Using a 9 Volt Battery with an LED, Push-Button, Arduino Nano

Description: A Push-Button is used to turn an LED ON/OFF with a 9 Volt Battery and an Arduino Nano.

Supplies:

1 – Breadboard 400 Points
1 – Arduino Nano
1 – 9 Volt Battery
1 – LED
1 – Push-Button
1 – 220 Ohm Resistor

Arduino Code:

int button = 3;
int led = 2;
int status = false;

void setup() {
  
  pinMode(led, OUTPUT);
  pinMode(button, INPUT_PULLUP); // set the internal pull up resistor, unpressed button is HIGH

}

void loop() {

  if (digitalRead(button) == true) {
  status = !status;
  digitalWrite(led, status);

} 

while(digitalRead(button) == true);
delay(50); // keeps a small delay

}

Leave a Comment

52 − = 45