Two Push-Buttons Turn LEDs ON/OFF

Description: Two push-buttons are used to turn two LEDs On and Off with an Arduino Nano.

Supplies:

1 - Breadboard 830 Points
1 - Arduino Nano
2 - Push-Buttons
2 - LEDs
2 - 220 Ohm Resistors

Arduino Code:

int button1 = 4;
int button2 = 3;
int led1 = 13;
int led2 = 14;

void setup() {

   pinMode(button1, INPUT_PULLUP);
   pinMode(button2, INPUT_PULLUP);
   pinMode(led1, OUTPUT);
   pinMode(led2, OUTPUT);
 
}

void loop() {

if(digitalRead(button1) == LOW) {
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   delay(10);
}

if(digitalRead(button2) == LOW) {
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   delay(10);
}

}

Comments

Leave a Comment

5 + 3 =