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

 by drj113
Featured

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 1: How 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.




1-40 of 144Next »
rmartin19 says: May 13, 2013. 12:07 PM
Sorry for the noob-ish question, but how would one add a clock module (e.g. ds1302) to this board?
drj113 (author) in reply to rmartin19May 14, 2013. 6:18 PM
Hi,

There is no such thing as a Noob-ish question - Everybody learnt at some stage :-)

You could simply add a DS1302 to the board by looking at something like my later clock designs - they use a DS1302. Essentially there are three wires that get connected from the clock module to the AtMega chip. You also need to include the DS1302 library and write some software, but thats not impossible.

I am a little flat out with the clock business at the moment to spend the time to modify the project - but I would encourage you having a play - You can even find space on the board by removing the 4 way dip switch that is not used, and using that space to place the DS1302.chip.

Let me know how you get on.

Doug
francisroan says: May 8, 2013. 12:26 PM
Hi how can i connect this to the "internet" and not the local home network ..What if i want to access this from anywhere in the world..?
CrazySolutions says: Mar 25, 2013. 12:54 PM
Hi There! This is exactly what i have been looking for!! Thankyou.

however...

having built the board successfully, i am having problems with the programming.

firstly i simply tried using my current version (0020) of the arduino software to burn the file however it quickly came up with errors, so after reading through previous posts i see that you were using the 0017 version, so i went and downloaded it, tried it and found that it apparently dosnt support the UNO board? so... i tried with my origonal version (0020) and tried changing the file names of the library in the code, it got a few steps further but then came up with these errors:

sketch_mar25a:89: error: 'Ethernet' does not name a type
sketch_mar25a.cpp: In function 'void setup()':
sketch_mar25a:119: error: 'es' was not declared in this scope
sketch_mar25a:127: error: 'PHLCON' was not declared in this scope
sketch_mar25a.cpp: In function 'void loop()':
sketch_mar25a:227: error: 'es' was not declared in this scope
sketch_mar25a:283: error: 'IP_PROTO_P' was not declared in this scope
sketch_mar25a:283: error: 'IP_PROTO_ICMP_V' was not declared in this scope
sketch_mar25a:283: error: 'ICMP_TYPE_P' was not declared in this scope
sketch_mar25a:283: error: 'ICMP_TYPE_ECHOREQUEST_V' was not declared in this scope
sketch_mar25a:289: error: 'IP_PROTO_P' was not declared in this scope
sketch_mar25a:289: error: 'IP_PROTO_TCP_V' was not declared in this scope
sketch_mar25a:289: error: 'TCP_DST_PORT_H_P' was not declared in this scope
sketch_mar25a:289: error: 'TCP_DST_PORT_L_P' was not declared in this scope
sketch_mar25a:290: error: 'TCP_FLAGS_P' was not declared in this scope
sketch_mar25a:290: error: 'TCP_FLAGS_SYN_V' was not declared in this scope
sketch_mar25a:294: error: 'TCP_FLAGS_P' was not declared in this scope
sketch_mar25a:294: error: 'TCP_FLAGS_ACK_V' was not declared in this scope
sketch_mar25a:298: error: 'TCP_FLAGS_FIN_V' was not declared in this scope
sketch_mar25a.cpp: In function 'uint16_t print_program_page(uint8_t*, uint8_t)':
sketch_mar25a:445: error: 'TCP_CHECKSUM_L_P' was not declared in this scope
sketch_mar25a:448: error: 'es' was not declared in this scope
sketch_mar25a:452: error: 'TCP_CHECKSUM_L_P' was not declared in this scope
sketch_mar25a:476: error: 'TCP_CHECKSUM_L_P' was not declared in this scope
sketch_mar25a:492: error: 'TCP_CHECKSUM_L_P' was not declared in this scope
sketch_mar25a.cpp: In function 'uint16_t print_manual_page(uint8_t*)':
sketch_mar25a:514: error: 'TCP_CHECKSUM_L_P' was not declared in this scope
sketch_mar25a:517: error: 'es' was not declared in this scope
sketch_mar25a:521: error: 'TCP_CHECKSUM_L_P' was not declared in this scope
sketch_mar25a:540: error: 'TCP_CHECKSUM_L_P' was not declared in this scope
sketch_mar25a:554: error: 'TCP_CHECKSUM_L_P' was not declared in this scope
sketch_mar25a.cpp: In function 'uint16_t edit_program_page(uint8_t*, uint8_t)':
sketch_mar25a:578: error: 'TCP_CHECKSUM_L_P' was not declared in this scope
sketch_mar25a:582: error: 'es' was not declared in this scope
sketch_mar25a:586: error: 'TCP_CHECKSUM_L_P' was not declared in this scope
sketch_mar25a:604: error: 'TCP_CHECKSUM_L_P' was not declared in this scope
sketch_mar25a:616: error: 'TCP_CHECKSUM_L_P' was not declared in this scope
sketch_mar25a:627: error: 'TCP_CHECKSUM_L_P' was not declared in this scope


i am afraid im one of these "hardware blokes" and have little knowledge of programming.

any help with this would be much appreciated!
ynos says: Dec 6, 2012. 1:34 AM
Thanks for a nice instructable. I am trying to build the same project and my concern is the power supply. In my understanding the relays require 12V and the arduino/enc28j60 requires 5v and 3.3v respectively. How should I go about building/purchasing the power supply if I want to have one power supply to power this project. I suppose the voltage is 12V but how about the ampere or wattage rating.

Also I am planning to use this (HFJ11-2450E-L12RL) - http://docs-asia.electrocomponents.com/webdocs/106e/0900766b8106e81d.pdf, will this work?

Thanks in advance.
mantux100 says: Dec 22, 2010. 8:11 AM
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????
drj113 (author) in reply to mantux100Dec 22, 2010. 12:18 PM
The parts list is definitive. The Micro is definitely an AtMega328, and the gate is a HC part.
shaadmahmud in reply to drj113Nov 21, 2012. 1:20 AM
can i use mega168 instead of mega328?
mahmoudmorsy says: Sep 11, 2012. 11:14 PM
Hey, I solved the problem of the ferrite bead by taking one out of an old dial up modem board.
and finally the board worked completely
i programmed the atmega and it runs the relays on and off as you said here .
and when i connect the power
the yellow led in the RJ-45 lights on . and when i connect the Ethernet cable the green one flashes many times and when i press the reset switch . both yellow and green flashes 2 or 3 times then start working again.
My BIGGEST PROBLEM HERE !! >> is that i can't open the webpage of the board
with the ip"192.168.1.2" . i tried many times with different cables. i tried to connect it directly to the laptop and another time to the router.
but at both times the webpage cannot be opened . !!!
i tried to re-program the chip with changing the ip address in the sketch .
and also i can't open it .
I"M SO HOPELESS after all that working and the board works fine . i can't control it :SSS
PLEASE HELP ME
drj113 (author) in reply to mahmoudmorsySep 12, 2012. 11:24 PM
That can be really frustrating.

Are you able to ping the IP address? What output does executing ARP -a provide?

Doug
shaadmahmud in reply to drj113Nov 21, 2012. 1:07 AM
I have the same problem...but I can ping the IP address but cant open the webpage. can you tell me what is the problem?
mahmoudmorsy in reply to drj113Sep 12, 2012. 11:59 PM
I tried to ping the ip from cmd . and it doesn't give me "reply from ..."
and when i connect it directly to the computer . it gives me a message "local area connection doesn't have a valid ip 'configuration' or 'address' i can;t remember exactly.
by the way . I can't understand what is the "ARP-a"???
mahmoudmorsy in reply to mahmoudmorsySep 13, 2012. 12:02 AM
i can send you a video of the board while it is working . but without controlling it from my computer . just leds, relays , and every thing on the board is working fine but still my problem isn't solved...
jajen says: Oct 13, 2012. 4:17 AM
Can you specify type of rj45 MagJack use this project? Thera are a lot of rj45 MagJack and I dont know which one should I use.
mahmoudmorsy in reply to jajenOct 14, 2012. 12:18 PM
It's this one
it should have magnetics
I have made this project and one of my faults was that i get the wrong RJ45
so this one should works as it is wriiten in the parts list as Mr. Doug said :)
http://www.sparkfun.com/commerce/product_info.php?products_id=8534

Mahmoud Morsy
mahmoudmorsy says: Oct 2, 2012. 3:03 PM
Today the electronic components shop received an Ethernet MagJack it's not exactly like yours but the same idea of magnetics and its using is for ethernet interfaces.
I bought it and soldered it instead of the old one
but i got the ENC28j60 hot and the board also can't ping
i revised all connections and solders for any shortage between wires or any thing wrong but i didn't find any thing wrong . so i don't know what to do now :S
drj113 (author) in reply to mahmoudmorsyOct 2, 2012. 4:54 PM
That is bad news.

The ENC chip getting hot could mean that it has been damaged.

The project does *need* the magjack. Without it, it probably won't work.

If you like, you can post your project to me here in Australia and I will see if I can make it work for you.

Doug
mahmoudmorsy says: Sep 30, 2012. 1:18 AM
I Can adjust it to 9V bec. it is variable adapter.

Also I don't know if this is a problem or not . I didn't find your RJ45 in the component list in my country . But I found this
http://ram-e-shop.com/oscmax/catalog/product_info.php?products_id=1415
and i connected two 3mm leds instead of the RJ45 leds
{The engineer in the shop said that they are the same your RJ45 and this one}

I hope I Could do this :( .. But I'm here in EGYPT . so it is too hard to send it to you
But i Can easily Send You Pictures and Videos for the project. and I appreciate you a lot for helping me

M.Morsy
mahmoudmorsy says: Sep 28, 2012. 4:59 AM
So Could be the problem in the input current
I'm Using a 220V-AC to 12V-DC ADAPTER 1000mA
..
drj113 (author) in reply to mahmoudmorsySep 28, 2012. 8:39 PM
That will work ok although it is a bit high voltage - ideally you should use about 9V.

Would you like to send your project to me here in Australia so I can see if I can find out what the problem is?

Doug
mahmoudmorsy says: Sep 28, 2012. 2:12 AM
I found that the input is 5V with the output 3.3V on the component "78l33"
and input 10V with output 5V on the component "78l05"

and when i remove the ATMEGA chip and the enc28j60 from the board . the component doesn't get hot . but while i'm connecting the 2 chips on board . it gets hot...
drj113 (author) in reply to mahmoudmorsySep 28, 2012. 4:49 AM
The 78l05 will be getting hot, as it will be converting the 10V to 5v, producing between 1/2 and 3/4 W of heat.

The 78L33 should not be hot.
mahmoudmorsy says: Sep 27, 2012. 4:55 AM
HeY !!
I noticed something . that the component U4 : 78L33 is getting hot while the board is powered on. Is that normal or there is something wrong in the board??
drj113 (author) in reply to mahmoudmorsySep 27, 2012. 4:31 PM
That component should not be hot at all - it is only supplying about 50mA with 2V across it - so it would seem that there is some excessive load.

Do you have a multimeter? If so, you could verify the voltage out ofthe 3.3v regulator.

Doug'
mahmoudmorsy says: Sep 18, 2012. 9:55 PM
Sorry for my poor English , but i can't understand what is the crossover cable connection to my pc??
mahmoudmorsy says: Sep 17, 2012. 9:04 PM
it's always flashing while i'm connecting the plug into it , even i'm not connecting it to the router or computer. and connecting one side only !.


can the problem be in the soldering or components ? . or the problem is in the ip configuration only??
drj113 (author) in reply to mahmoudmorsySep 17, 2012. 9:16 PM
It could be the soldering - it may also be the IP configuration.

The activity light flashes when it receives a packet. Are you able to just connect it - with a crossover cable to your pc?

Doug
mahmoudmorsy in reply to drj113Sep 18, 2012. 7:11 AM
Sorry for my poor English , but i can't understand what is the crossover cable connection to my pc??
mahmoudmorsy says: Sep 16, 2012. 7:08 PM
Here it is
I do what you have said . i turned off the wi-fi
and connected the computer and the circuit directly to the switch
and this is the ip configured from cmd
=================================================
Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\Users\MOORSY>ipconfig

Windows IP Configuration


Wireless LAN adapter Local Area Connection* 12:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Ethernet adapter Ethernet:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::3004:1e43:d042:d64f%13
IPv4 Address. . . . . . . . . . . : 192.168.1.2
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1

Wireless LAN adapter Wi-Fi:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Tunnel adapter isatap.{BCE244F2-A4FF-4815-8FB4-D22D5FA36027}:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Tunnel adapter Teredo Tunneling Pseudo-Interface:

Connection-specific DNS Suffix . :
IPv6 Address. . . . . . . . . . . : 2001:0:9d38:6ab8:3c78:16ee:3f57:fefd
Link-local IPv6 Address . . . . . : fe80::3c78:16ee:3f57:fefd%17
Default Gateway . . . . . . . . . : ::

C:\Users\MOORSY>
===================================================
and when i ping the circuit board which i changed its ip address in the sketch to "192.168.1.5"

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

C:\Users\MOORSY>ping 192.168.1.5

Pinging 192.168.1.5 with 32 bytes of data:
Reply from 192.168.1.2: Destination host unreachable.
Reply from 192.168.1.2: Destination host unreachable.
Reply from 192.168.1.2: Destination host unreachable.
Reply from 192.168.1.2: Destination host unreachable.

Ping statistics for 192.168.1.5:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

C:\Users\MOORSY>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

So what i have to do now??
drj113 (author) in reply to mahmoudmorsySep 16, 2012. 8:18 PM
Hmm - Thats really weird.

When you ping, do you see the activity light on the board flashing with each ping?

Doug
mahmoudmorsy in reply to drj113Sep 17, 2012. 6:07 AM
it's always flashing while i'm connecting the plug into it , even i'm not connecting it to the router or computer. and connecting one side only !.


can the problem be in the soldering or components ? . or the problem is in the ip configuration only??
mahmoudmorsy in reply to mahmoudmorsySep 16, 2012. 7:10 PM
Ahh and btw this screenshot when i typed the ip in IE and didn't work the i pressed the fix problem button . it gives me this screen
ip.png
mahmoudmorsy says: Sep 16, 2012. 4:15 PM
OKay . Here is a copy of my ipconfig from cmd

====================================
Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\Users\MOORSY>ipconfig

Windows IP Configuration


Wireless LAN adapter Local Area Connection* 12:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Ethernet adapter Bluetooth Network Connection:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Ethernet adapter Ethernet:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Wireless LAN adapter Wi-Fi:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::a093:7370:5a4e:a777%12
IPv4 Address. . . . . . . . . . . : 192.168.1.2
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1

Tunnel adapter isatap.{BC39A4FF-1F08-43E4-9D0D-02CC91628AF0}:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Tunnel adapter Teredo Tunneling Pseudo-Interface:

Connection-specific DNS Suffix . :
IPv6 Address. . . . . . . . . . . : 2001:0:4137:9e76:49d:481:d67d:80d0
Link-local IPv6 Address . . . . . : fe80::49d:481:d67d:80d0%17
Default Gateway . . . . . . . . . : ::

Tunnel adapter isatap.{97F50E96-CF33-4F76-B691-FAF7A543FDCC}:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

C:\Users\MOORSY>
=================================================


BTW . i'm using windows 8
and i tried to open it from my android phone through wireless and also didn't work.\

when i ping board ip . it gives me this
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\Users\MOORSY>ping 192.168.1.8

Pinging 192.168.1.8 with 32 bytes of data:
Reply from 192.168.1.2: Destination host unreachable.
Reply from 192.168.1.2: Destination host unreachable.
Reply from 192.168.1.2: Destination host unreachable.
Reply from 192.168.1.2: Destination host unreachable.

Ping statistics for 192.168.1.8:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

C:\Users\MOORSY>

>>>>>>
and sometimes it gives me "Destination net unreachable."
drj113 (author) in reply to mahmoudmorsySep 16, 2012. 5:16 PM
It looks like you are not actually connected to the PHYSICAL network.

Ethernet adapter Ethernet:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :


You have a wireless connection.

Wireless LAN adapter Wi-Fi:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::a093:7370:5a4e:a777%12
IPv4 Address. . . . . . . . . . . : 192.168.1.2
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1

How do you have the board connected to your network?

I would hard code your PC to have a 192.168.1.2 address, connect the laptop to a switch, connect the board to the same switch and see how that went.

Disable your wireless in the meantime to make sure that it is not conflicting.

Doug
mahmoudmorsy says: Sep 15, 2012. 8:37 AM
I tried to ping the ip from cmd . and it doesn't give me "reply from ..."
and when i connect it directly to the computer . it gives me a message "local area connection doesn't have a valid ip 'configuration' or 'address' i can;t remember exactly.
by the way . I can't understand what is the "ARP-a"???

i can send you a video of the board while it is working . but without controlling it from my computer . just leds, relays , and every thing on the board is working fine but still my problem isn't solved...
drj113 (author) in reply to mahmoudmorsySep 16, 2012. 5:11 AM
Ok - it seems as though you may not have your local network configured correctly.

Can you let me know the IP of your computer and your router?

It is best if you hard code your IP for your network and computer, as opposed to using a DHCP address from your router.

You also need to make sure that your computer is on the 192.168.0.x network

Doug
mahmoudmorsy says: Sep 7, 2012. 7:32 AM
Hey,
I have programmed the IC and i treated the error of the ethershield by downloading the ethershield library and attached it to the project . and it compiles successfully .
My problem now that i don't have the "ferrite bead" and i can't find it here in my country and i don't know what it is also !!?? . So could you help me with this issue please??
drj113 (author) in reply to mahmoudmorsySep 9, 2012. 7:17 PM
The ferrite bead is simply a piece of wire with a ferrite core on it to reduce interference.

http://au.mouser.com/ProductDetail/Murata/FSRH044C00RNB00B/?qs=sGAEpiMZZMvgExXaNlWje%2fYJEy227vp0b74WvV4jJ3M%3d

If you can't find one - just a piece of wire should work fine.

mahmoudmorsy says: Aug 31, 2012. 5:36 AM
Hey, Thanks for your reply
I have just bought the pcb components totally.
and a new ARDUINO UNO .
now i want to know how can i install the .pde sketch on the ATMEGA328
and where i can place the connectors between the arduino and the pcb .
there are many things i can't understand . but please could you help me to build this project and how can i connect the arduino with the project pcb. and how can i install the pde code to the microcontroller .
If u can help me please with some step by step pictures.
Thanks for your attention :)
drj113 (author) in reply to mahmoudmorsyAug 31, 2012. 3:50 PM
Hi,

Sorry I don't have any pictures for you - I am a bit confused as to what you are trying to do.

This project uses its own circuit board. All I was using the Arduino for, was to put the Atmega CPU chip into it, and programming it, then transfering the chip into the projects board and using that.

Doug
1-40 of 144Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!