Working on a project for arduino which will use two switches to control two relays separately. There will be timers to control the on time of the relays. Here is the sketch code.
boolean button1_pressed = false; // This is a state flag for button1.
int relay1_onTime = 1000; // This is the time in milliseconds that relay1 will turn on.
unsigned long button1_previousTime = 0; // This is for saving the millis() time that the button was pressed.
unsigned long button1_currentTime = 0; // This is for saving a later time to compare to the above time.
boolean button2_pressed = false; // This is a state flag for button2.
int relay2_onTime = 5000; // This is the time in milliseconds that relay2 will turn on.
unsigned long button2_previousTime = 0;// This is for saving the millis() time that the button was pressed.
unsigned long button2_currentTime = 0;// This is for saving a later time to compare to the above time.
// This check is here to de-bounce the button input.
// Also it only tests for the button press if the relay is turned [off].
// check if the pushbutton is pressed. If it is, the buttonState is LOW.
//digitalWrite(relay1, HIGH); // add 5v to arduino pin 11 so relay in1 will be 5v and this will make the relay turn off.
digitalWrite(relay2, LOW); // and wait 5 seconds.
//digitalWrite(relay2, HIGH); // add 5v to arduino pin 12 so relay in2 will be 5v and this will make the relay turn off.
// and has been on for at least (relay1_onTime) milliseconds.
button1_pressed = false; // This turns off the state flag so you can press the button again.
digitalWrite(relay1, HIGH); // This turns off the relay.
// this is millis() rollover protection, not likely to happen but a good habit.
// and has been on for at least (relay2_onTime) milliseconds.
button2_pressed = false;// This turns off the state flag so you can press the button again.
digitalWrite(relay2, HIGH); // This turns off the relay.