// Define variables
int buttonPin = 5; // Digital pin where the button is connected.
int ledPin = 7; // Digital pin where the LED is connected.
int buttonState;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // LED pin as an output.
pinMode(buttonPin, INPUT); // Button pin as an input.
}
void loop() {
// Read the state of the button
buttonState = digitalRead(buttonPin);
// Check if the button is pressed
if (buttonState == 1){
digitalWrite(ledPin, HIGH);
Serial.println("LED ON ");// Turn LED on.
} else {
digitalWrite(ledPin, LOW);
Serial.println("LED Off ");
}
}