What you will need
Part 1 (The Protocol):
1x Arduino (any version, mine is a Duemilanove)
1x RF Link 2400bps Receiver - 315MHz
1x RF Link 2400bps Receiver - 434MHz
1x RF Link Transmitter - 315MHz
1x RF Link Transmitter - 434MHz
1x Breakout Board for FT232RL USB to Serial
Part 2 (The Application):
1x Three-Way Switch
1x 5V Relay
1x 2N2222 Transistor
1x 1N4007 Diode (1N4004 also works)
1x 1K Resistor
Part 1 (The Protocol):
This solution is based on two parts, a transmitter, connected to a PC running Java code, and a receiver, connected to the Arduino board. Important to say that this name schema can get confused once both the transmitter and the receiver can transmit and receive messages, so let's establish that the transmitter is the one connect to the PC, always, and the receiver is the one on the Arduino board.
To build the transmitter we're going to use the Breakout Board for FT232RL USB to Serial, the RF Link Transmitter - 315MHz and the RF Link 2400bps Receiver - 434MHz. One thing to pay attention here is that the receiver and the transmitter need to have different frequencies, otherwise the communication will not happen.
First thing to do is to wire the VCCIO pin on the breakout board to 5V and to help you on this, check this mini-tutorial on the SparkFun Forum.
Once this first step is done we need to add the transmitter/receiver pair to our transmitter (remember? transmitter means PC, receiver, Arduino). So, there's also a thread on the SparkFun forum to help you on this task.
As you may have noticed on the thread it only refers to the transmitter, to add the receiver is easy and the labels on the pins are self-explanatory. One thing that can get you confused is that the receiver has two data pins, we're going to use only one, the first one from left to right, and it goes on the RXD pin on the breakout board.
Antennas are optional, i used them.
|Transmitter - Left View|
|Transmitter - Right View|
|Transmitter - Top View|
To build the receiver we just need to take a look at this post and instead of wiring to different Arduinos you will wire both the transmitter and the receiver in only one board. One more thing that need to be done is that instead of using pins 0 and 1 for the transmitter and the receiver respectively we're are going to use pins 2 and 3.
|Receiver - Front View|
|Receiver - Back View|
|Receiver - Other Angle View|
This is the best part, so let's begin from the beginning. To get it done i started using this and this codes available here. This code already implements error catching so i just had to do a little modification to add reliable messaging and it's available for download in two parts here and here.
After that comes the Java code wich is a version of the Arduino code implemented in Java, of course, and it's also available in two parts here and here. This is a improved version of the Java code available here and it uses the RXTX library for serial communication.
In a few words what this code does is: The transmitter (Java code) keeps the id (a random number) of the last message sent and keeps sending this very same message until it gets a reply from the receiver (Arduino). The receiver, once a message is received, verifies if it has the same id of the last message it received. If the id is the same it means the transmitter didn't receive the reply and just send a reply again if it's not it handles the message and send a reply for the first time. When a reply gets to the transmitter it verifies if it's a reply for the last message sent and, if it's ok, it stops sending messages. All this is done with some error catching that was already available and you can check the console (both Arduino and Java) for the outputs.
|Java code running|
I think an implementation like that can be used in many situations, and it can also be improved to add more capabilities. One situation where it can be used is to build a home automation system, which was already something i would like to work on. On my case i just added the capability of switching my room light wirelessly and in order to do that i added a little circuit and a relay to the Arduino part of the solution, walkthrough found here. Thing is, i wanted the wirelessly controlling to be a plus, i still wanted to be able to turn my light on and off using the switch. So, i added a three-way switch to the solution and connected it to the relay, help found here. Doing this i'm now able to turn my light on using the switch and turn it off wirelessly and vice versa or use just one to accomplish both tasks. Here are some pictures to help in the understanding:
|Three-way switch connected to the 5V relay and the AC|
|The whole thing connected|
So, i think that's it. Let me know if you guys used it to something else, or even if you think something can be modified or, i don't know, if you have doubts in some part that was not very well explained (easy to happen). Comments will be very appreciated. And remember to follow Arduitter on Twitter to get to know about all the news here.