Quick question about relay programming

Hello!

New to this and had an question.

Im trying to turn on one relay from my four relay boad.

This does not work:

#define RELAY1 8

void setup(){

pinMode(RELAY1, OUTPUT);

}

void loop(){

digitalWrite(RELAY1,LOW); // Turns ON Relays 1
delay(2000); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off

}

But this works..'

#define RELAY1 6
#define RELAY2 7
#define RELAY3 8
#define RELAY4 9

void setup()

{

pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);

}
void loop()

{
digitalWrite(RELAY1,LOW);
delay(2000);
digitalWrite(RELAY1,HIGH);

digitalWrite(RELAY2,LOW);
delay(2000);
digitalWrite(RELAY2,HIGH);

digitalWrite(RELAY3,LOW);
delay(2000);
digitalWrite(RELAY3,HIGH);

digitalWrite(RELAY4,LOW);
delay(2000);
digitalWrite(RELAY4,HIGH);

}

What am i doing wrong?

Thanks in advance!

Which pin is relay 1 connected to ?

This does not work:

Sure it does. The relay is turned on for two seconds, off for a few nanoseconds, and then back on. (Or it might be off for most of the time and on for a few nanoseconds).

Isn't that what you want? If not, why did you write the code that way?

(Perhaps you wanted to delay() for longer at the end of loop()).

haha alrighty, thats the issue PailS. on for nanosec then off for 2 hehe thanks!

Realy awsome forum since there seem to be so many active members.

Thanks for your answer bob but its solved now! :slight_smile: