// Define the pin for the relay
const int relayPin1 = 3;
const int relayPin2 = 4;
const int relayPin3 = 5;
int buttonstate;
// Define the pin for the button
const int buttonPin = 2;
void setup() {
// put your setup code here, to run once:
pinMode(relayPin1, OUTPUT);
pinMode(relayPin2, OUTPUT);
pinMode(relayPin3, OUTPUT);
// Set the button pin as input
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
buttonstate=digitalRead(buttonPin);
}
void loop() {
// put your main code here, to run repeatedly:
buttonstate=digitalRead(buttonPin);
Serial.println(buttonstate);
if(buttonstate==LOW){
buttonstate=digitalRead(buttonPin);
Serial.println("button in on");
digitalWrite(relayPin3, LOW);
digitalWrite(relayPin2, LOW);
digitalWrite(relayPin1, HIGH);
delay(6000);
digitalWrite(relayPin1, LOW);
digitalWrite(relayPin2, HIGH);
delay(4000);
digitalWrite(relayPin2, LOW);
digitalWrite(relayPin3, HIGH);
delay(4000);
}
else
{
buttonstate=digitalRead(buttonPin);
Serial.println("button is off");
digitalWrite(relayPin3, LOW);
digitalWrite(relayPin2, LOW);
digitalWrite(relayPin1, LOW);
}
}