I am trying to turn ON a LED when either of two push buttons are pressed. But the problem is, button states of both push buttons show to be '1' even when I did not press anything. Please help!
This is my circuit : https://drive.google.com/file/d/18fsPnaaDxo9asE-DUh2sPlcEWGCRdqs-/view?usp=sharing
This is my code.
int button_state_1 = 0;
int button_state_2 = 0;
const int button_1 = 2;
const int button_2 = 3;
const int led = 4;
void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(button_1, INPUT);
pinMode(button_2, INPUT);
}
void loop()
{
delay(500);
button_state_1 = digitalRead(button_1);
button_state_2 = digitalRead(button_2);
Serial.print("Button states for 1 and 2 are : ");
Serial.print(button_state_1);
Serial.println(button_state_2);
if ((button_state_1 == HIGH) || (button_state_2 == HIGH))
{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led, LOW);
}
delay(1000);
}