Mobile-controlled Home Automation

6 months, 2 weeks ago

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

home-automation.jpg

.

Background

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.

.

Parts

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.


untitled-2.png

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.

picservo2small.jpg

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

dsc03654.jpg
dsc03657.jpg

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.

phone.jpg

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.

image3.jpg

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.

.

Conclusion

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.

19 Responses to “Mobile-controlled Home Automation”

  1. WAP controlled home automation - Hack a Day Says:

    […] [Josh] sent in a home automation project he did a little while ago. It has a total of eight switched outlets. The main focus of the project was WAP access for remote control from any cellphone. The control box is based on a design by [Ashley Roll] for controlling eight servos using a PIC microcontroller. A listener app written in Java monitors the control web page and sends signals to the board via serial port. He used opto-isolated 240V solid state relays for each of the outlets. All the pieces are available on the site and he might even do a custom control board design if there is enough interest. […]

  2. technology guerilla » Blog Archive » Mobile-controlled Home Automation with PIC16F84 Says:

    […] http://blog.neonascent.net/archives/292 […]

  3. Robert S Says:

    Hi Dude;

    Nice clean aproach for something I’ve been trying to do for a while. I’m well into pic programming etc.. as an electronics engineer, and I have a lot of programming experience, but have newer had the time to dive deep into PHP and internett protocols yet.

    It seems to me that when the java listener app updates the ip file on the server, it appends to the adress, instead of overwriting it. I had to manually edit the file to write in the correct IP adress. But after that it worked like a charm.

    If you posted a new set of files, with controlling maybe two or tre things instead of one, you would spare me of some wondering, and I could concentrate on the hardware side of things.

    Good work, Greatings from Norway.
    Robert

  4. Will Says:

    Careful with sealing those solid state relays in a small enclosure, they often put out a bit of heat with not much of a load. They require a bit of heat sink to operate at full capacity.

  5. Josh Says:

    Robert; thanks for pointing that out - have fixed it in the PHP files zip.

    I’ll whip up something for handling 8 ports now.

    Will; Thanks - a bit disappointing that the datasheet didn’t suggest similar!

  6. Josh Says:

    The updated 8-port server control code is now online.

  7. Robert S Says:

    I’ll probably design some circuit boards for this during the christmas holiday. If you want to bend your mind around something Josh, it would be a cool idea if the PIC could send something back on the serial bus, that the java applet could send to the website, and display.

    In my own project, this would be an indoors and outdoors tmp sensor, as I plan to implement that in the circuit for thermostatic control of heating in my living room.

    If you could read the temp on the website that would be nice. And then one could perhaps set the wanted temp from the website. maybe something like “@16:00 T=21C”

    If you want to think a little bit around how that can be done on the software side, I would be glad to send you one of my finished cards with temp sensor interface free of charge.

    I plan to use those cheap 433mhz remote thingies for switching lights on and off for the controll, so I will make a circuit board with a PIC Micro, internal and external temp sensor, and a 433mhz TX. The I can just add on as many comercial RX 220V 16A switches as i like.

    Here in Norway, those switches would be like 20€ for 3 of them, and then you get a hand remote in the package.

    Sounding interesting? Or is this an old and abandoned project on your side?

    Happy Holidays
    Robert S

  8. Robert S Says:

    Wow, 9:01 am..

    It’s 11:44 pm 23.12.08 here wher I sit. Going to bed now.
    Curious what willcome ofthis durng the holidays.

    Robert S

  9. Robert S Says:

    Josh: Do youhae a tip onaice, len applet/solution for posig a webcam picture on the webpage? Had something like this in the late 90’s, but if you have checked out what’s available lately, you just save me the trouble.

    R

  10. Robert S Says:

    i’ll stop this ranting now.. tried to write “do you have a tip on a nice clean applet solution for posting a…” but seems that I need to change the batteries in the wireless keyboard. And no editing posibilities. Should read what I have written before pressing “Submit”. Instead I fill your blog with garbage. Your free to delete my two last posts.. ;)

    *going to bed - grin*

    Robert S

  11. Josh Says:

    Robert; Sending information back to the server shouldn’t be too much of a chore. I’m certainly happy to tweak the listener to do that. :) Once you’ve got an idea of data format, let me know via the contact form, and I’ll put something together.

    josh

  12. SCADA, Telematics & GPS Technologies » Blog Archive » WAP controlled home automation Says:

    […] [Josh] sent in a home automation project he did a little while ago. It has a total of eight switched outlets. The main focus of the project was WAP access for remote control from any cellphone. The control box is based on a design by [Ashley Roll] for controlling eight servos using a PIC microcontroller. A listener app written in Java monitors the control web page and sends signals to the board via serial port. He used opto-isolated 240V solid state relays for each of the outlets. All the pieces are available on the site and he might even do a custom control board design if there is enough interest. […]

  13. lifekludger - disability : technology : life » Blog Archive » Mobile-controlled Home Automation DIY Says:

    […] Control 8×240v outputs via mobile/web. sydney guy. Even without wap, offers great step-by-step DIY environmental control idea. [Link] […]

  14. Siftah Says:

    Robert S:

    I like your idea of using a 433mhz TX unit on the board to be able to control the commercially available relay units - they’re quite common here in the UK too and make a great/cheap way of doing HA.

    They’re quite often had for around 10ukp for 3 or 4, making them ideal!

    I’d previously toyed with using the bundled remote control unit and then interfacing it with a parrallell port or similar to trigger the buttons, but your solution seems cleaner - I know nothing of the 433mhz wireless protocol they use, is it something you can point us to documentation of?

    Regards,
    John

  15. Robert S Says:

    Hi Siftah;

    The protocol for the 433 MHz systems are mostely proprietary, meaning that every vendor makes their own system. So little or no documentation is available online.

    That being said, the protocol is in most cases very simple, and easy to decode and replicate with simple equipment. One way to go if one dont have access to a scope, couold be to find the signal line on the TX board, and send it to the soundcard trough a resistor. Then, use one of the online available “scope” programs to look at the waveform.

    Normally, the TX part in the remote is quite weak, and has a poor range and stability. I bought some simple AM On /Off keying TX cards with 100mW output and 50R antenna attachment for about 10€ / stk. They give a great range, and are nice to controll with a micro or the LPT or Serial port.

    Have not had any time to make any boards for this project yet, but it’s on my to-do list..

    Robert S

  16. Binu Says:

    Nice project, Do we need any dedicated IP address.

  17. Josh Says:

    Thanks Binu.
    A dedicated IP is not needed; when you start your the Listener program on your home computer, it updates its IP address on the server.

  18. Dan Says:

    I really like this project and I’ve developed my own, but I’m having a problem. I can’t seem to find a free online web host that allows sockets. Are you using a free webhost? If so what is it?

  19. Josh Says:

    Hi Dan,
    If you set up a mini webserver (or at least a HTTP request processor) on your home computer, you can communicate with it using AJAX requests direct from your browser. So:

    1) Home computer starts up and uses HTTP to send new IP to server code,

    2) Server code embeds new IP into an Javascript AJAX command on the control panel page,

    3) Browser communicates directly with home box.

    Would require a little more work on the Home Computer Java code.

    Another alternative is to write a Java Applet that connects and sends UDP signals straight from the client computer. No change needed to Home computer code, and you can make your Applet look nice and pretty. You could also write this browser app in Flash (and possibly Silverlight).

Leave a Reply