This project demonstrates the use of a push button to operate a LED.
Objective:
- To Set LED ON when Button is pressed.
- To Set LED OFF when Button is pressed (the opposite effect).
Working with a Push Button
Interaction Basics: LED and Button
Every great invention starts with a single interaction. Controlling an LED with a push button is the "Hello World" of physical computing. This project introduces the core concepts of digital reads and digital writes.
The Logic Flow
The Arduino acts as a mediator in this circuit:
- Input: The Arduino reads the state of a GPIO pin connected to the button.
- Analysis: If the button is pressed, the pin reads
HIGH(orLOWdepending on your circuit). - Output: Based on that state, the Arduino sends a signal to another pin to turn the LED
ONorOFF.
Hardware Setup: The Pull-Down Resistor
A common mistake for beginners is connecting a button directly between power and an input pin. This leaves the pin "floating" when the button isn't pressed, leading to erratic behavior.
- Solution: We use a 10k-ohm resistor connected to Ground (a pull-down resistor). This ensures the pin sees a stable
LOWsignal until the button is pressed.
Components List
- Arduino (any model): To process the signals.
- LED (any color): Your visual output.
- Push Button/Tactile Switch: Your physical input.
- 220-ohm Resistor: For the LED.
- 10k-ohm Resistor: For the button pull-down.
This simple setup is the basis for almost every user interface in the world, from microwave buttons to industrial control panels.