A Remotely Programable Relay Controller (Christmas Lights or Home Automation Controller)

A Remotely Programable Relay Controller (Christmas Lights or Home Automation Controller)

What was that?  A Whats-a-Maja-Thimagig?

Yep - One of those!  This Instructable extends my Arduino Ethernet controller to control a set of up to 6 relays, but that's not the neat bit.  The neat bit is that there is a web based state machine in the AtMega chip so that the relays will operate in whatever sequence with whatever timing you want - all by themselves.

This allows you to have a set of relays connected to the end of a piece of Ethernet cable that can be accessed from a web browser anywhere from your house.

I needed a system to sequence a set of relays to control some Christmas lights around my house this Christmas, as well as to turn on and off a water fountain, so I thought that a simple controller for it would be an AtMega328 chip.  Then I thought about how cool it would be to allow these things to be controlled from a web interface.  A little bit of tinkering later, and this project was born.  I really only needed 4 relays, but as I was doing the layout, I decided that here was enough space for 6!

This project is an autonomous controller, operating a set of 6 relays according to a pre-programmed pattern, over and over again.  If you are impatient, jump to the section on programing the board to see how it is programmed.

In my case, I wanted to control a fountain and some Christmas lights, so my pre-programmed pattern is as follows:

Relay 1 - Front fairy lights
Relay 2 - Fountain Blue Light
Relay 3 - Fountain Green Light
Relay 4 - Fountain Pump

On startup, do the following forever until it is switched off:

Turn on the Fairy lights, the Blue light and run the pump.  After 3 minutes, turn off the blue light, and turn on the Green light.  After 3 more minutes, turn off the fountain and the fountain lights.

This would be defined in the controller as:-

State0;  Relay 1, Relay 2, Relay 4 - time 3 minutes - jump to state 1
State1;  Relay 1, Relay 3, Relay 4 - time 3 minutes - jump to state 2
State2;  Relay 1 - time 3 minutes - jump to state 0

Relay 1 would be connected to the Fairy lights. 
Relay 2 would be connected to the Blue light
Relay 3 would be connected to the Green light
Relay 4 would be connected to the pump.

You can have a completely different program, say for running a gardening facility, where the relays drive various pumps and lights for watering and heating.  Whatever you like!  The uses are limitless!  And the hacking potential is limited only by your imagination.
 
Remove these adsRemove these ads by Signing Up
 

Step 1How does the programming work - or What is a state machine?


I am glad that you asked that!

The controller implements a wonderful tool called a state machine.  A state machine is one of the simplest controllers that just knows two things; What the current state is, and what will the next state be?

State machines are driven by a table called a state table.  Essentially what the controller does, is cycle through the state table one state at a time.  Our state table documents the current output settings, and what the next state will be.  In our case, it also specifies the amount of time we wait in the current state.  Here is an example of a state table that toggles the first 4 relay outputs in sequence, waiting for 3 minutes between cycles;

State 0: 1 on, 2 off, 3 off, 4 off, 5 off, 6 off, Wait 3 minutes - goto State 1
State 1: 1 off, 2 on, 3 off, 4 off, 5 off, 6 off, Wait 3 minutes - goto State 2
State 2: 1 off, 2 off, 3 on, 4 off, 5 off, 6 off, Wait 3 minutes - goto State 3
State 3: 1 off, 2 off, 3 off, 4 on, 5 off, 6 off, Wait 3 minutes - goto State 0

The controller runs in an infinite loop, where it knows what the current state is, waits the required time, and then jumps to the next state as dictated by the table. 

You will find state machines in things ranging from traffic lights, through washing machines, through to Industrial controllers.




« Previous StepDownload PDFView All StepsNext Step »
86 comments
1-40 of 86next »
Jan 20, 2012. 3:03 AMsv1elf says:
Hi
I have a New Arduino Uno - R3 board .
Can i program with this board the atmega IC?
Is it possible to add a port like ' 7000 ' in case i want forward the ip- port to router?
Thanks
George
Nov 18, 2011. 8:53 AMtuanman says:
I'm trying to figure out a way to use either christmas lights or leds to attach to a table and be able to select a part number (via computer)and have only certain lights light up to show multiple locations on the table that the part on the table needs marked at. Can this be easily done?
Aug 9, 2011. 2:39 PMabishur says:
So do I have to have an Arduino to program the main chip or is there another method for programming it? I know they're not too expensive, but I'd prefer a bit of a cheaper option
Jun 15, 2011. 5:07 AMgandu1 says:
HI,

i am new to ethernet, i want to control devices in lan. please can you help me.please send me your project details.

my mail ID: hardships_143@yahoo.co.in


Thanks & Regards.
Jan 13, 2011. 5:07 AMcrorat says:
realy good project, i have prroblem finding atmega in my countri could you please tell me is anyone of this useble, thanks

http://www.chipoteka.hr/?module=moduli%2Fshop&moduleS=index&moduleLinkID=22&search=atmega&traziField=atmega
May 17, 2011. 9:06 AMchax says:
I'm from croatia too. A/D Electronic shop has Atmega168 microcontroler. I'm planing to buy one to build arduino myself. http://ad-electronic.hr/vmchk/mikrokontroleri/atmega168-20puisp-mc-27-55v-16k-flash-20mhz.html
It's Arduino compatible microcontroler, unfortunately, they don't have Atmega328 which has double amount of flash memory.
Or you can always buy Atmega328 from ebay.
Apr 8, 2011. 12:25 AMTeknopuppy says:
Hi,

can you send me the pcb board artwork for top and bottom . i did print out the pcb layout but the size it too big. Please send me the actual size in pdf or bmp format.



Thanks,

Jimmy
May 19, 2011. 1:29 AMiasonas says:
can you please also send me the pcb board artwork in real size?

jason.bouroutis@gmail.com

Kind regards
May 19, 2011. 2:19 AMiasonas says:
If possible please send it with the format of the pcb designer programm because I'm going to give it to a company for printing it and they want the actual file.
Apr 9, 2011. 6:07 AMTeknopuppy says:
Hi,
drj113,

my email address is jimmy_wong2001@yahoo.com


thanks and Best Regards,

Jimmy
May 3, 2011. 6:17 PMcrorat says:
What did you select as board in arduino aplication? whicone i can use for this chip, thanks
May 3, 2011. 3:17 PMcrorat says:
(removed by author or community request)
May 3, 2011. 7:34 AMTeknopuppy says:
hi,

Mantux100,

The actual size of the board is 10mm x 11mm. i use the Foxit reader software to print out the pcb artwork and the scale set it to 100%.


drj113,

Thanks for everything, i finaly get the print pcb right size.


Thanks,

Jimmy
Apr 21, 2011. 10:25 AMmantux100 says:
what size is this board?
Mar 26, 2011. 3:44 AMâÖÙàÙ says:
hi drj
can i use 51ohm resistor insted i cant find 50ohm resistor?
thanks Ami
Mar 26, 2011. 6:05 AMâÖÙàÙ says:
thank for your super fast replay
can i ask about the ferrite bid is the fx18 the packing? i have dificults to find
can i use this :http://cgi.ebay.com/50-Ni-Zn-Ferrite-Bead-Core-Lead-3-5x6-0mm-Taiwan-/140329107881?pt=LH_DefaultDomain_0&hash=item20ac4441a9#ht_1504wt_905
Mar 17, 2011. 7:41 PMpcapelo says:
Hi,

i have to say again that I loved our instructable.

I would like to ask you, since I know very little about programing the arduino, how could I make it possible to have distinct ON/OFF commands, instead of just toggle.

I ask your help because I would like to be able to control better the relays.
I email last year asking you about your board and I let that idea go, now I decide to start again, got my relays, arduino and ethernet board running, teste your code and everything looks awesome. I am still trying to figureout how to remove the programs without damage the rest of the code but I got stuck with toggle issue.

could you help me out with this matter???

thank you in advance
PC
Jan 30, 2011. 9:44 PMgg23 says:
hi,
This is what I have been looking for :)

I am intending on using these for a community art project, where 1 will be installed in up to 50 apartments of a single block of apartments. Through the internet/local wan I will control a single light source in the apartment and in the evening create a giant pixel display using the building. How can I keep the cost down? I am not sure I can get static ip addresses for the ports in each apartment, will this matter? Any help greatly appreciated. As an arts project dealing with very limited funding.
Thanks
greg
Dec 30, 2010. 5:50 AMmantux100 says:
What P3 does?
Dec 22, 2010. 8:11 AMmantux100 says:
on schematic you wrote that the controler is Atmega8 and on parts list you write that it's AtMega 328 and that gate ic is 74ls08 but on pats list you write 74HC08 . WTF????
Dec 9, 2010. 8:24 PMhightekrednek2396 says:
where can i get ki cad
Dec 11, 2010. 6:19 PMhightekrednek2396 says:
do you have the gerber file
Dec 12, 2010. 3:49 PMhightekrednek2396 says:
no i couldnt figure out where to download from
Dec 12, 2010. 5:13 PMhightekrednek2396 says:
ive been there how do is save the file to run it
1-40 of 86next »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
338
Followers
11
Author:drj113
I have a background in digital electronics, and am very interested in computers. I love things that blink, and am in awe of the physics associated with making blue LEDs.