// Button on pin 2 controlling an LED const int buttonPin = 2; // Button connected to pin 2 const int ledPin = 6; void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); } void loop() { int buttonState = digitalRead(buttonPin); // Button pressed = LOW // Button released = HIGH if (buttonState == HIGH) { digitalWrite(ledPin, HIGH); // Turn LED ON } else { digitalWrite(ledPin, LOW); // Turn LED OFF } }