Instructables

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

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
1-40 of 147Next »
xp_sm4 months ago

Please help me

I have this error like below when compiling the code:

Error: D:\cvavr2\inc\pgmspace.h(90), included from: ip_arp_udp_tcp.h: incomplete type is not allowed ---<ypedef void prog_void PROGMEM;>

avr.png
evilcomputer10 months ago
Hello sir, i'm having problem making the pcb, can i ask you to upload the kicad pcb project files please.
rmartin191 year ago
Sorry for the noob-ish question, but how would one add a clock module (e.g. ds1302) to this board?
drj113 (author)  rmartin191 year ago
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
Do you need a clock if you can access an NTP server?
http://arduino.cc/en/Tutorial/UdpNTPClient

drj113 (author)  farticus1 year ago
That's a definite thought - but you should also cater for the possibility that the network is isolated.
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..?
You have to go into your wireless router settings and port forward to the local address.
Example: your IP address is 50.145.78.99 and the arduino is 192.168.1.2.
You set the router to forward port 8081 to -> 192.168.1.2.
Now when you are anywhere in the world you would use the address: 50.145.78.99:8081 and you would see the arduino control page just like you would at home!
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!
ynos1 year ago
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.
mantux1003 years ago
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)  mantux1003 years ago
The parts list is definitive. The Micro is definitely an AtMega328, and the gate is a HC part.
can i use mega168 instead of mega328?
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)  mahmoudmorsy2 years ago
That can be really frustrating.

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

Doug
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?
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...
jajen2 years ago
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.
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
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)  mahmoudmorsy2 years ago
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
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
So Could be the problem in the input current
I'm Using a 220V-AC to 12V-DC ADAPTER 1000mA
..
drj113 (author)  mahmoudmorsy2 years ago
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
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)  mahmoudmorsy2 years ago
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.
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)  mahmoudmorsy2 years ago
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'
Sorry for my poor English , but i can't understand what is the crossover cable connection to my pc??
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)  mahmoudmorsy2 years ago
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
Sorry for my poor English , but i can't understand what is the crossover cable connection to my pc??
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)  mahmoudmorsy2 years ago
Hmm - Thats really weird.

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

Doug
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??
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
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)  mahmoudmorsy2 years ago
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
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...
1-40 of 147Next »