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 ads by
Signing UpStep 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.










































Visit Our Store »
Go Pro Today »




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
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!
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.
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
Are you able to ping the IP address? What output does executing ARP -a provide?
Doug
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"???
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
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
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
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
I'm Using a 220V-AC to 12V-DC ADAPTER 1000mA
..
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
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...
The 78L33 should not be hot.
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??
Do you have a multimeter? If so, you could verify the voltage out ofthe 3.3v regulator.
Doug'
can the problem be in the soldering or components ? . or the problem is in the ip configuration only??
The activity light flashes when it receives a packet. Are you able to just connect it - with a crossover cable to your pc?
Doug
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??
When you ping, do you see the activity light on the board flashing with each ping?
Doug
can the problem be in the soldering or components ? . or the problem is in the ip configuration only??
====================================
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."
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
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...
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
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??
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.
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 :)
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