Arduino Projects Ideas - Push Button LED

 Arduino Projects Ideas - Push Button LED

Components:
Push button
10kΩ resistor
LED + 220Ω resistor
Arduino UNO

Wiring:
Button between pin 2 and GND
10kΩ resistor from pin 2 to 5V (pull-up)
LED on pin 13 with resistor

Code:

void setup() {
  pinMode(2, INPUT_PULLUP);
  pinMode(13, OUTPUT);
}
void loop() {
  if(digitalRead(2) == LOW) {digitalWrite(13, HIGH);
  } else {digitalWrite(13, LOW);
  }
}