some advise please. multiple timed outputs

hi there,
absolute beginner to arduino systems so the question is probably a no-brainer/dumb one for most of you.
But im needing to build a device that will turn 4 to 5 relays on and off over a 1 minute cycle and loop/repeat.
so for example relay 1 may need to come on for 5 seconds, off for 15, on to 2 sec off for 10sec etc etc … but at the same time relays 2,3,4 need to be able to turn on and off at different sequences and timing over that same 1 minute window.

so i’ve done a little timeline drawing to hopefully clarify the type of thing i want to achieve.

i wasnt sure on the limitation of arduino or whether i had to go down the more complex raspberry pi road :frowning:

Possibly a problem with your secret code. :) Please see topic #7 here: http://arduino.cc/forum/index.php/topic,148850.0.html

This can easily be accomplished using an Arduino. I would not recommend using a Raspberry Pi for this particular application.

There are many ways to use a clock.

Most of use use the one that re-sets to zero twice a day. Some use a stop-watch to count up in time other use a kitchen timer to count down in time

millis() is the system clock Blink-Without-Delay or BWD is the basic way of counting with time by using millis()

one variation of BWD is :

loop { if (then >= 60000) { //this will allow the clock to count up to one minute , then reset then – millis() }

duration = then – millis() ; // this is run every loop

if (duration > 1000 ) { relay1_status=1 ; } // sets the flag if over 1 second if (duration > 3000 ) { relay1_status=0 ; } // sets the flay if over 3 seconds

if (duration > 1500 ) { relay2_status=1 ; } if (duration > 5000 ) { relay2_status=1 ; }

// other stuff goes here

digitalWrite(relay1, relay1_status) ; digitalWrite(relay2, relay2_status) ; } // end of loop

As you can see, this is not complete code. And you can add as many conditions as you like and none affect the time. the first part sets the total elapsed time of the cycle. ifyou want to do 20 things in 1 minutes, set for 1 minute if you want to do 10 things in 5 minutes, just change things around.

There are more elegant ways, but this works and is easy for a beginner to understand.

it uses the 3-part rule for loop

part 1 inputs - read everything part 2 calculations - do the calculations part 3 output - do the outputs.

p { margin-bottom: 0.1in; line-height: 120%; }

Thanks for the help so far. i'll start experimenting and no doubt may need to yell for some help and tips until i learn a little more :-)

phil91: Thanks for the help so far. i'll start experimenting and no doubt may need to yell for some help and tips until i learn a little more :-)

blink without delay is a simple concept lock in the time. check how long, is it time out yet ? if it is timed out , then do that thing you want to do and lock in the new time. that is like a kitchen timer, but the basis of BWD the above variation locks in the time creates a counter of how long it has been after 1 minute, start that after 3 minutes, stop .. multiple things can get turned off or on then at the end of the cycle, lock in the time, again, repeat. try it, and see what results you can get. take a minute to read How To Use This Forum especially #7 about posting code using code tags.

then post your code and tell us what is going on.