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.
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.