Push button relay control

Hi every one yet another newbie here, I will try to not be to much of a pain in the but. So what I'm trying to do is simple except I can't figure out the best way to do it. Im working on an art project and I need to sequentially turn a relay on, delay, and then turn of. The next time the button is pressed relay #2 turns on,delays,and turns off.followed by relay #3 and so on. I need help withthe programming,how the heck do I accomplish this. Thanks and sorry to be that guy.

The example StateChangeDetection would be a good place to start. That sketch should give you an idea how it's done.

Hello I am writing a program which will do the cause hopefully its a simple code:
it should work perfectly incase it doesn't work do not hesitate to message.

int relay1=5; //relay pins
int relay2=6;
int relay3=7;
int button= 12; //button must be connected to 5v pin to digital pin 12
int count=0 ; //to store values how many times it has been pressed.
void setup() {

pinMode(relay1, OUTPUT);
pinMode(relay1, OUTPUT);
pinMode(relay1, OUTPUT);
Serial.begin(9600);
}
void loop() {
int swtch = digitalRead(button);
delay(1000);
int count = swtch+1;
if(count=1)
{
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);

}
if(count=2)
{
digitalWrite(relay1, HIGH);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
delay(2000);
}
if(count=3)
{
digitalWrite(relay1, LOW);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, LOW);
delay(2000);
}
if(count=4)
{
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, HIGH);
delay(2000);
count==0;
}

}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

You could use

switch case

instead of a line of if statements

https://www.arduino.cc/en/Reference/SwitchCase

Thanks.. Tom.. :slight_smile:

@kjp_Durgesh: please stop doing this.
It is polite (or at least customary) to qualify code that even if it compiles, clearly does not perform as a reasonable person would expect as "uncompiled and untested".

Your stream-of-conciousness programming helps no-one.

The lack of code tags is secondary.

@kjp_Durgesh you need to re-read the man pages on = vs == for a start.

Your varable count will never go higher as 2.

A digitalRead will give you high or low (0 or 1).

int count = swtch+1; // results in 1 or 2

Please also read the comment from ardy_guy