// 🛠 Fourth Arduino Program: Turn ON LED when Button is Pressed
// 👉 Concepts introduced: pinMode(INPUT), digitalRead(), button press detection
int ledPin = 13; // LED connected to pin 13
int buttonPin = 7; // Button connected to pin 7
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT); // 1️⃣ Set button pin as INPUT
}
void loop() {
int buttonState = digitalRead(buttonPin); // 2️⃣ Read button state
if (buttonState == HIGH) { // 3️⃣ If button is pressed
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}