I wrote this instructable because I made a similar project recently and thought it'd be nice to write down my work and share it with others.
What we want to reach with this instructable, is wireless controlling multiple devices (lights for example) on a timed schedule. Handy when you're not at home and still want to turn on / off some lights automatically to scare burglars etc.
Step 1: Materials
For this project, I'll be using:
- 2 cheap wireless wall sockets for 230V devices
- a remote that comes with those sockets (just for the setup)
- an Arduino Uno (or nano, mega, whatever you want)
- a super cheap DS3231 real time clock
- a 433MHz receiver / transmitter kit
Furthermore I'll be using some jumper wires (yes, it's not entirely wireless ;) ) and a breadboard.
Step 2: Finding the Right Signals
For this project, we make use of the RC-Switch library, which can be found on Github. Please download and install the library to the Arduino IDE via Sketch > Include Library > Add .zip library.
Now, before we can make the Arduino send a signal to the wall sockets in order to turn on or off, we need to know what to send. Therefore we will 'sniff' the communication between the remote and the wall sockets. To do so, make sure that your remote control and wall sockets work with each other. In my example, my wall sockets are connected to the channels A and B on the remote.
To sniff the signal, wire the receiver to the Arduino as shown in the picture. This is:
- VCC to 5V
- GND to GND
- The data pin next to the ground pin to Arduino Digital pin 2
Now hook up the Arduino to your computer and open the example sketch: File > Examples > RCSwitch > ReceiveDemo_Simple
Upload the sketch and open the serial monitor.
Now, when you press a button on the remote control, you see the signal appearing in your serial monitor! Note that every button (on A, off A, on B, off B etc.) has it's own signal. Write these signals down because we will use them later.
In the screenshot attached, you see that for me, for Button A-ON sends the 24bit code "16762196" as long as the button is pressed. When I release it, it sends the code "16768351". This last value you don't have to save.
Find all values for all the button that you're planning to use.
Step 3: Get the Time Right
Now, in order to make a time-control switch, we need to attach the clock module. If you're using a new clock, the time has to be programmed to it as well.
Remove the FM receiver from the Arduino and hook up the clock module, see the picture.
- VCC goes to the 5V on the Arduino
- GND goes to GND on the Arduino
- SDA goes to A4
- SCL goes to A5
These A4 and A5 ports cannot be changed, since those are the only ports on a Uno that support the SDA/SCL communication.
With this sketch, we can set the time of the clock. To set the time, uncomment line 19 and set the time. For example, Wednesday (3rd day of the week) December 16th 2015, 19:10:00 will be:
Save and upload the code to the Arduino. Now comment this line again an re-upload. Otherwise the time would be set to these values everytime you reboot your Arduino.
Ok, that was that. Time's set. Up to the next step!
Step 4: Transmitting
Ok, time to make the Arduino control the wall sockets! To do so, we keep the clock connected and attach the transmitter now as well:
- VCC to 5V on Arduino (See note below)
- GND tot GND on Arduino
- Data to D10 on Arduino
Note: Since an Uno has only 1 5V output pin, you can use a breadboard, or, like in the picture, use the 5V from the ICSP.
So now it's just a matter of uploading a code that checks the time and switches the lights on and off.
The code to use can -again- be found on my Github. It still includes some of the clock part, but it now also contains the part to control the wall sockets.
- In the void loop, you can set the times on which you want to have any action. I always mention the seconds in my if-statements, because otherwise the arduino will be performing the action for an entire minute.
- At the bottom part of the code in the 'turnOnA(), turnOffA(),etc.', you have to paste the codes that you saved before.
- To add additional buttons, copy/paste and rename!
Step 5: Go Out and Don't Worry!
Plug in your wall sockets, connect the lights and go out! No burglar that would expect you not to be home. :)
Thanks for reading this. If you enjoyed it and found it useful, please leave a comment.