Hi. I hope this is the correct forum to ask about this kind of issues. I' ve been trying to set a relay to activate lights with arduino, but i can't make the lights turn on after sending a value. The relay is set so lights go on in the LOW position, and i already tested the circuit with this code
void setup()
{
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
Serial.begin(9600);
}
void loop()
{
digitalWrite(4, LOW);
delay(1000);
digitalWrite(4, HIGH);
delay(1000);
digitalWrite(5, LOW);
delay(1000);
digitalWrite(5, HIGH);
delay(1000);
digitalWrite(2, LOW);
delay(1000);
digitalWrite(2, HIGH);
delay(1000);
digitalWrite(3, LOW);
delay(1000);
digitalWrite(3, HIGH);
delay(1000);
*/
}
}
and everything worked out just fine, so i know i didn't make a bad installation.
Now, i tried to make a code based on different values of a variable called "senal" as conditions to turn on or off the lights. The only problem is that when i send the value, nothing happens.
Here is that code.
int senal;
void setup()
{
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
Serial.begin(9600);
}
void loop()
{
if (Serial.available()>0)
{senal = Serial.read();
if (senal == 1)
{digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);}}
else if (senal == 2)
{digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(2, HIGH);}
else if (senal == 3)
{digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);}
else if (senal == 4)
{digitalWrite(5, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);}
}
Any help with this is gratly appreciated. Oh, and sorry if my english is not that clear.