Hello,
Pretty new to Arduino. I'm trying to control relays and LEDs with a button. I am able to turn the relays on/off with a button using this code:
/*
*/
const int buttonPin = 3;
const int relay = 13;
const int relayMist = 12;
const int Greenled = 1;
const int Blueled = 2;
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(Greenled, OUTPUT);
pinMode(Blueled, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(relayMist, OUTPUT);
Serial.begin(9600);
}
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
else {
Serial.println("off");
}
}
lastButtonState = buttonState;
if (buttonPushCounter % 2 == 0) {
digitalWrite(Greenled, LOW);
digitalWrite(relay, HIGH);
digitalWrite(relayMist, HIGH);
digitalWrite(Blueled, HIGH);
} else {
digitalWrite(Greenled, HIGH);
digitalWrite(relay, LOW);
digitalWrite(relayMist, LOW);
digitalWrite(Blueled, LOW);
}
What I want to do is have the relays turn on after the button is pressed then turn off after 15 seconds. Anyone know how I can do this? Any help would be great!