const int buttonPin = 2; // Pin where the button is connected
const int ledPin = 13; // Pin where the LED is connected
int buttonState = 0;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
//Connect the longer leg (anode) of the LED to digital pin 13 on the Arduino.
//Connect the shorter leg (cathode) of the LED to one end of the 220-ohm resistor.
//Connect the other end of the resistor to GND on the Arduino.
//Connect one end of the push button to digital pin 2 on the Arduino.
//Connect the other end of the push button to 5V on the Arduino.
//Connect one end of the 10k-ohm resistor to GND on the Arduino.
//Connect the other end of the 10k-ohm resistor to the junction
//between the push button and digital pin 2.