I have design a circuit with 2 led (red and UV) and 2 button.So, the circuit supposed to work like this: If i press the button for red led, the red led lights up and the uv led turn off, and if i press the button for uv led the uv led lights up and the red led turn off.
But the circuit is not work like that, when i upload the code, the uv led suddenly turn on without touching the button.The red led had no issue.The red led turn on when the button is push.And turn off when the button is unpress.But when i push the red button, the uv led does not turn off.It stay glow.The uv led turn on whatever i push the button or not.
Here is the code :
int red = 8;
int uv = 9;
int redbutton = 2;
int uvbutton = 3;
int redbutcondition = 0;
int uvbutcondition = 0;
void setup()
{
pinMode (red, OUTPUT);
pinMode (uv, OUTPUT);
pinMode (redbutton, INPUT);
pinMode (uvbutton, INPUT);
}
void loop()
{
redbutcondition = digitalRead(redbutton);
uvbutcondition = digitalRead(uvbutton);
if (redbutcondition == HIGH)
{
digitalWrite(red, HIGH);
digitalWrite(uv, LOW);
}
else if(uvbutcondition == HIGH);
{
digitalWrite(uv, HIGH);
digitalWrite(red, LOW);
}
}