A while back I built a mobile-controllable home automation system, and promised to blog it. It’s taken a while, but here it it…

DIY Home Automation via WAP and the Web – How-to




This how-to will provide a detailed guide to implementing your own Web/WAP enabled home automation system. The home automation system allows you to control the on/off state of up to eight 3A appliances via either a web browser or a mobile phone. The system provided is fairly cheap and effective, but has a few prerequisites:

  • An always-on internet connection (or at least on while you want to control things)
  • An always-on computer (see above)
  • PHP enabled Web space, or your own web server. (Of course if you are serving from home you already have the first two!)
  • WAP/web enabled phone if you’d like to use the mobile control features of the system. All modern mobile phones are capable of controlling the system.
  • Some beginner-level soldering skill. This project uses a PIC16F84, a cheap programmable chip.

Assuming the above, the total cost of building this system should be no more than about AU$50, plus AU$15 for each 240v switch. You can also extend the usefulness of the system by setting up an internet-viewable webcam, using a usb webcam and any freely publishing programs, providing some visual feedback.



The system is split into three functional sections. These are

  1. PHP files on the internet server – These handle the front-end interface to browsers (HTML) and WAP phones (WML), and send commands to your home computer.
  2. Java application on your home computer – Receives messages from Internet server, and passes them via the serial port to the automation hardware.
  3. The control box – Receives signals via serial port, and actuates the eight 240vac switches.
  4. Switches – 240vac relay switches.


I’ll go through the three components out of logical order, as the control box is the most involved part, and I don’t want to spring surprises on you! 🙂


The Control Box

The control box hardware for this system is an appropriation of Ashley Roll’s PIC-based 8-servo controller, as it is very closely suited to what we want to do, and saved me designing anything else. However, I’ve modified the control code to fit the needs of this project. The control box’s function is to sit listening to serial port input, and switch it’s outputs high or low depending on control codes set from the computer – not a difficult task, and easily implemented in hardware and software using other chips.


Ashley’s design features a 9v power supply and regulator circuit. However, you are likely to be wanting to use a USB->RS232 connector, and so can wire the USBs 5v supply directly into this circuit.

For the Hardware: Visit Ashley’s page for information on building the control box, and to download the schematic diagram’s for etching. I am happy to design a stripped-down circuit that can be set up on a breadboard (without etching) if there is a demand for this.

For programming the chip: In place of Ashley’s servo code, please use the modified code provided in automation_pic_code.zip. This archive contains the 8portonoff.HEX file for programming the PIC16F84, and 8portonoff.ASM code listing. All modifications have been marked with “Josh”.


The Switches


Warning! 240vac can kill! Don’t use the relays while their enclosure is open.

Switches are simply 240vac relays, insulated in a plastic project box. I used the SY-4080 solid state relay (datasheet .pdf), which is optically-isolated from the control signal. The relay is put between the Live wire of the mains supply. The control lines connect up to pins 4 and 3 on the relay, and an LED is wired across these to indicate the state of the relay. The control lines are taken from the ground, and logic line on the control board, which are the two outer pins (the centre pin is a 5v supply intended for server power). Remember to connect the correct polarity for LED and relay – ground on the control box out to negative. Note :It’s good practice to wire the earth wire longer than everything else, so that it is the last to be pulled out if there is tension on the connection.

I cut the mains cable holes just slightly out from lid, so that screwing the top on clamped the cables in place. Ragnar also suggests putting cable straps tightly around the mains-cables inside, to reduce the risk of them being pulled out.


The Server

Files needed on your server are available in php-files.zip.
Edit (24/12/08): I’ve just completed a nicer 8-port control system available in php-stuff-8port.zip – merry Christmas!

Once you’ve uploaded them to your server, make sure the “state” and “relayIPaddress” files are given write permissions (eg. 777). Also, if you want to use a WAP interface, you must configure Apache to serve WML pages through the PHP interpreter; Add

AddType application/x-httpd-php .wml

into your httpd.conf file.


The control panel pages for HTML and WML are control.php and control.wml respectively, in your upload directory. At the moment the control panel only controls device 1 connected to your control box, but it is very easy to modify the PHP to control them all (simply changing the control string from “1” to “3” for example). Give me a yell in the comments if you want a more fully featured control page.


Home Computer

The listener application does two things; it connects to the server to update it’s IP address, and then listens for commands from the server sent via UDP. To install the listener application, download and unextract java-relaycontrol-listener.zip.* Open up listener.bat in your favourite text editor, and change the address to your server address, and the number to the comm port you have attached the control box to.

java relaylisten <full address of updaterelayip.php including http://> <comm port number>

The serial port communication code is base on Ben Resner’s SimpleSerial. If you’d like to customize the java listener, the source code is available for download in java-relaycontrol-listener-source.zip.

Before you can receive commands from the server, you must configure your firewall. This process will vary depending on your router. You will want to forward UDP port 11000 to the computer running the listener.


At this stage, you may want to also set up webcam software on your home PC.


Now test…

  1. Run the listener and see that it connects to the server correctly.
  2. Connect to the web server control page, and send some commands. You should see the commands echoed in the listener window of your home computer.
  3. If your control box is connected on the correct port, the relays should be actuating.



Play and enjoy – share your applications, and feel free to request any improvements in the design. One possible improvement is to build a web server into the listener application, so you can run everything from home. What modifications would you find useful? What are your thoughts?

*The listener is Java-based, but uses a native DLL for connecting to your serial port, so will only run on Windows. A cross-platform version is in development.