This project page provides a guide to adding both USB and a Web based User Interface (UI) to remote control socket set. Through the process we will unlock even more capabilities than are available when you use the socket set as they were originally intended. Part 1 deals with the hardware, Part 2 (this post) deals with programming the chip and Web UI.
The main components are:
- Arduino (or other AVR-MK2 programmer)
- Web-server (I used a Raspberry pi, but any computer will work if it’s running Apache and PHP)
- Lego (if you want to make a Raspberry pi case)
Okay, first step is to program the AT Mega 8 chip.
I don’t have a AVR-MK2 programmer like [befinitiv], but I do have a number of Arduino boards. There are a number of ways to program an AT Mega 8 with an Arduino, but the most successful method I have found is to use mega-isp code for Arduino. A very good tutorial can be found at [blog.ntsd.net]. Upload mega-isp onto your Arduino.
mega-isp: programming an atmega8 with arduino from [web archive – blog.ntsd.net]
If you would like to program the chip before you have soldered it all together, follow the instructions above. If you have the hardware already assembled use the programming cable (purple, grey, white, black) that sticks out the of the remote control at the end of the first tutorial (see image below).
In this case the purple is reset (Arduino pin 10), grey (Arduino pin 13), white (Arduino pin 12), black (Arduino pin 11).
Using a Linux machine with avrdude installed run the following command in the terminal
$ avrdude -p atmega8 -c avrisp -P /dev/ttyUSB0 -b 19200 -U lfuse:w:0xe4:m -U hfuse:w:0xda:m
This is a combination of the standard setup for mega-isp and setting the fuses as done by [befinitiv]. The ttyUSB0 in the code above is the Arduino, so this may need to be changed, but if you unplug all USB peripherals and plug in the Arduino first it should be ttyUSB0.
- Plug in the remote control and hook up to the Arduino as mentioned above.
- Now download the code from my gitHub repository.
- Navigate to the folder “remote_controlled_socket” in the terminal.
- Run make.
- Now run make program
The code above largely builds on the code provided by [befinitiv], but adds extra support for up to 15 devices and adds channel selection to the mix.
Okay, now we have the remote all set up it’s time to set up the web based control. Essentially what we need here is a basic web server running PHP. Place the files from the “SerialPowerControl-web” folder on the server. As I’m running a Linux server so I have to alter the dialout group settings to allow the PHP script to communicate over the USB.
$ sudo pico /etc/group
-> add “,www-data” to end of dialout:x:*** (without quotes)
Now I’m using a Raspberry Pi as my server (as it’s a really cheap, low power and tiny computer) and I encountered a slight problem as the Apache server isn’t configured properly, to resolve the issue you need to do the following:
$ sudo groupadd www-data
$ sudo usermod -a -G www-data www-data
$ apt-get install php5-common libapache2-mod-php5 php5-cli
after installation, then restart Apache:
$ sudo service apache2 restart
If eveything is successful you should end up with the interface as shown below (point the browser to the server location of the power scripts) and once the remote is plugged into the servers USB port (make sure it’s the first USB device plugged in, so that it becomes ttyUSB0). This was easily thrown together using PHP and the jQtouch library meaning it will work in any Webkit Browser (Chrome, Safari, iOS and Android), it still works in Firefox, but loses it’s visual appeal.
Feel free to edit the scripts on the server so that the text reflects your own set up. You can add more devices (up to 15 per channel), events or change the default channel (the check boxes at the bottom of the image above, there are 32 possible channels). Check out the README file that comes with the scripts for the mapping of device numbers and the settings on the sockets (4-bit code). Let me know in the comments how you get along, the changes you make, or the issues you encounter.
I think one of the next steps is to try and add manual control to the sockets, there is no switch on the socket itself. You can of course use the wall socket switch if available, but this completely disables the remote feature. I also have one socket circuit embedded in the light switch for the main room lights, again the actual switch will turn off the lights but also disables the remote feature. So the new feature will have to allow for manual control without disabling the remote feature.
You can use the power.php and the GET method to use direct links to activate devices or profiles. Say for example I wanted to turn on device 1 on channel 4 (dip switch 4 down)
similarly for events
Making a case for your Raspberry Pi out of Lego. I got the inspiration from a bunch of scouts that have a post on the Raspberry Pi blog. I spent an evening going through my old Lego collection in my attic, collecting the necessary pieces.
Notice the clear blocks to let the power and Ethernet indicator LEDs light through.
To make your own I’ve included images of all sides, but essentially the Raspberry Pi is 7 x 11 in Lego dimensions, making the case 9 x 13.
Video and Audio Outputs
USB and LAN ports
Power and SD ports
[…] This project page provides a guide to adding both USB and aWeb based User Interface (UI) to remote control socket set. Through the process we will unlock even more capabilities than are available when you use the socket set as they were originally intended. Part 1 (this post) deals with the hardware, Part 2 deals with programming the chip and Web UI. […]
[…] [Jake] took some cheap hardware and figured out a way to use it as a huge home automation network. He’s chose a Raspberry Pi board to connect the radio controlled power outlets to his network. He wrote about his project in two parts, the first is hacking the RC outlet controller and the second is using the Raspberry Pi to manipulate it. […]
Great Job !!!
your design is very safe and does not depend on the computer used for the webserver, letting the microcontroller talk to the real world. Since the raspberryPi is equipped with GPIOs I guess you could have done without the FTDI cable and the arduino