I am very new to the whole Arduino experience and have very little knowledge on the code. I have been testing different codes and I have finally created a sketch that allows me to turn on and off two relays using two different switches. However I also need a timer that will run in the background and turn the relays on for around 45 seconds and off for roughly 10 minutes. I have tried using delays but I still need the switches to work and delays will not let this happen. I have also had a look at the BlinkWithoutDelay example, but the time that the relays are on for seem to be the same as they are off for and I don't know what to do change this. Is the BlinkWithoutDelay the best method for me or is there another method that I can use. I really hope someone can help me :(.
What criteria do you want to use to decide when the relays turn on?
Is it a daily thing, an hourly thing or a one off when you push the button or immediately you power up?
This is quite easy stuff but you have to define exactly what you want to achieve.
I'm looking for a timer to turn on my relays every half an hour for 45 seconds at a time.
You will also have to think about whether you want the switches to over-ride the timer or whether the timer should take precedence.
The switches will over-ride the timer. I was thinking about putting a timer on an if. The if would be for the switch off state but I didnt know what timers would work under the if as delays over-ride the switches.
The demo several things at a time is an extended example of the BWoD technique. Hopefully it will make things clearer.
...R
This would work
const int relayPin=9;//just picked this at random
void setup()
{
pinMode(9,OUTPUT);
}
void loop()
{
unsigned long t=micros()%1800000ul;
digitalWrite(relayPin,(t<45000));
}
Thanks every so much guys for the help and quick responses. Much appreciated. I think I have all I need now to finish my project. Thanks again.