Description: Two push-buttons with 10k Resistors are used to turn an LED ON/OFF with an Arduino Nano.
Notes: When the left push-button (buttonPin1) is pressed down, the LED turns ON and in the Serial Monitor the value changes from 0 to 1. And when the right push-button (buttonPin2) is pressed, the LED turns OFF and in the Serial Monitor the value changes from 1 to 0.
Supplies:
1 – Arduino Nano
2 – Push-Buttons
2 – 10k Ohm Resistors
1 – LED
1 – 220 Ohm Resistor
Arduino Code:
int buttonPin1 = 4; int buttonPin2 = 5; int ledPin = 8; int ledStatus = 0; int buttonStatus1 = 0; int buttonStatus2 = 0; void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); pinMode(buttonPin1, INPUT); pinMode(buttonPin2, INPUT); } void loop() { buttonStatus1 = digitalRead(buttonPin1); buttonStatus2 = digitalRead(buttonPin2); ledStatus = digitalRead(ledPin); Serial.println(ledStatus); if (buttonStatus1 == HIGH && buttonStatus2 == LOW) { digitalWrite(ledPin, HIGH); } if (buttonStatus1 == LOW && buttonStatus2 == HIGH) { digitalWrite (ledPin, LOW); } }