Interfacing Push Button and Led with Arduino:
ARDUINO CODE
/* --------------------------------------------------------- Objective: Control an LED using a push button. When the button is pressed, the LED turns ON; otherwise, it stays OFF. Components: - LED + 220Ω resistor (current limiting) - Push Button - 10kΩ pull-down resistor - Arduino Uno Board Working: Digital pin 2 reads the button state. If it becomes HIGH (button pressed), Arduino sets LED pin HIGH to turn it ON. --------------------------------------------------------- */ int buttonState = 0; // Variable to store button input state const int buttonPin = 2; // Push button connected to pin 2 const int ledPin = LED_BUILTIN; // Built-in LED on pin 13 void setup() { pinMode(buttonPin, INPUT); // Set button pin as input pinMode(ledPin, OUTPUT); // Set LED pin as output } void loop() { buttonState = digitalRead(buttonPin); // Read button state if (buttonState == HIGH) { digitalWrite(ledPin, HIGH); // Turn LED ON } else { digitalWrite(ledPin, LOW); // Turn LED OFF } delay(10); // Small delay for stable simulation }
Start Simulation
Click the pushbutton!