New to the wonderful world of Arduino here, and I have a few (probably stupid) questions.
The first problem is that when my Arduino boots up, it turns both Pump1 and Pump2 outputs on and keeps them on (I need them to be off); when I actuate button1, it runs the code correctly but proceeds to turn the relays back on until the button is actuated again.
Secondly, after reading through the forums for a bit, I've come to the conclusion that you guys aren't huge fans of the delay() function. What I need to do is have Pump1 run for a set time (2 seconds) and then have Pump2 run for a different amount of time (4 seconds). This portion of the code seems to be working just fine, but I was wondering if there was any way to do the same thing without using the delay() function. I looked at the blink without delay example, but I couldn't see how that could work for me.
Thanks in advance for any help.
const int Pump1 = 8; // the number of pump 1 pin
const int Pump2 = 9; // the number of pump 2 pin
const int button1 = 3; // the number of button 1 pin
int button1State = 0; // variable for reading the button status
void setup() {
// initialize the pump pins as outputs:
pinMode(Pump1, OUTPUT);
pinMode(Pump2, OUTPUT);
// initialize the button pin as an input:
pinMode(button1, INPUT_PULLUP);
}
void loop() {
// read the state of the button value:
button1State = digitalRead(button1);
// check if the button is pressed. If so, run both pumps
if (button1State == LOW) {
digitalWrite(Pump1, HIGH); // turn on pump 1
delay(2000); // wait 2 seconds
digitalWrite(Pump1, LOW); // turn off pump 1
delay(50); // wait .05 seconds
digitalWrite(Pump2, HIGH); // turn on pump 2
delay(4000); // wait 4 seconds
digitalWrite(Pump2, LOW); // turn off pump 2
}
else{
digitalWrite(Pump1, LOW);
digitalWrite(Pump2, LOW);
}
}