Control LED with Tactile Push Button Switch
Interface a standalone 4-pin tactile switch with pull-down/pull-up stabilization to command an external LED reliably.
Learn how digital inputs read physical switches without floating-pin noise. You will wire a 4-pin tactile push button using the Arduino Uno's internal pull-up resistor (or external 10kΩ pull-down), read clean logic transitions, and control an LED indicator.
Key Learning Objectives & Robotics Concepts
By building and programming this project, you will master the following core engineering skills:
Power Architecture & Voltage Staging
5V / 3.3V Regulated PowerThe Arduino Uno 5V logic rail powers the LED via a 220Ω resistor on D9, while D2 engages its internal ~30kΩ pull-up resistor so closing the tactile switch safely sinks micro-amps to GND. Internal 20kΩ–50kΩ pull-up resistor guarantees deterministic HIGH idle state and eliminates floating-pin EMI.
Bill of Materials (BOM) & Hardware Components
| Component | Specifications & Alternative | Qty | Approx Cost |
|---|---|---|---|
| Arduino Uno R3 | ATmega328P microcontroller board | 1 | $8.00 |
| 4-Pin Tactile Push Button (6×6mm) | Momentary SPST normally-open breadboard switch | 1 | $0.15 |
| 5mm LED + 220Ω Resistor | Visual status output stage | 1 | $0.15 |
| 10kΩ Resistor (Optional Pull-Down) | 1/4W resistor for external active-HIGH lab variant | 1 | $0.05 |
| Breadboard & Jumper Wires | 400-point breadboard + 5 jumpers | 1 | $2.50 |
Electrical & System Architecture
Tactile switch bridges Arduino D2 (configured as INPUT_PULLUP) to GND across the breadboard center trench; D9 drives an indicator LED through a 220Ω resistor to GND.
Autonomous Behavior & Finite State Machine (FSM)
Deterministic Arduino loop handling 4-Pin Tactile Push Button + 5mm LED acquisition, filtering, and real-time output updates.
Step-by-Step Physical Assembly & Wiring Tutorial
Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.
Identify Paired Pins on the 4-Pin Tactile Switch
Confirm which pairs of switch legs are internally shorted and which close only when pressed.
- Straddle the tactile push button across the center divider groove of the breadboard.
- Note that legs on the same side of the switch body are typically linked; opposing sides bridge when clicked.
- Optionally verify continuity diagonally with a multimeter while pressing the cap.
Wire Switch to D2 & LED to D9
Connect one switch corner to D2, the opposite corner to GND, and wire the LED + 220Ω resistor on D9.
- Connect a jumper from Arduino D2 to one terminal of the tactile switch.
- Connect the opposite diagonal switch terminal to the breadboard GND rail.
- Wire D9 → 220Ω resistor → LED anode, and LED cathode → GND rail.
Inspect Ground Commonality
Ensure Arduino GND connects securely to the shared breadboard ground rail.
- Check that both the button return wire and the LED cathode sit in the same GND bus.
- Verify no jumper accidentally touches the 5V pin directly to GND.
- Connect USB power to the Arduino Uno.
Flash Momentary & Latch Control Sketch
Upload the active-LOW switch controller sketch and inspect Serial Monitor output.
- Upload the sketch below via Arduino IDE.
- Open Serial Monitor at 115200 baud.
- Press and hold the push button; verify Serial reports PRESSED and the LED lights immediately.
Test Responsiveness & Active-HIGH Comparison
Verify zero flicker when your hand approaches the wires, proving the input is firmly pulled HIGH.
- Wave your hand near the D2 wire—LED must stay completely off (no floating noise).
- Tap the button rapidly 10 times and verify crisp LED response.
- Record how active-LOW inversion works in firmware.
Subsystem Benchtop Verification Scripts
Test each hardware subsystem independently before deploying the full autonomous firmware.
1Bench Diagnostic: 4-Pin Tactile Push Button + 5mm LED Hardware Check
Subsystem DiagnosticMinimal standalone sketch to verify pin wiring and signal response for 4-Pin Tactile Push Button + 5mm LED before running the full project firmware.
// Diagnostic: Raw Tactile Switch Logic Readout
const uint8_t BTN_PIN = 2;
void setup() {
pinMode(BTN_PIN, INPUT_PULLUP);
Serial.begin(115200);
}
void loop() {
Serial.println(digitalRead(BTN_PIN) == LOW ? "PRESSED (LOW)" : "RELEASED (HIGH)");
delay(150);
}Complete Production Firmware
Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.
/**
* Project 2: Tactile Push Button LED Controller (Active-LOW Pull-Up)
* Board: Arduino Uno R3 | Pins: D2 (Button), D9 (LED)
*/
const uint8_t BTN_PIN = 2;
const uint8_t LED_PIN = 9;
bool lastPressed = false;
void setup() {
pinMode(BTN_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
Serial.println(F("Push Button LED Controller Initialized"));
}
void loop() {
bool isPressed = (digitalRead(BTN_PIN) == LOW);
digitalWrite(LED_PIN, isPressed ? HIGH : LOW);
if (isPressed != lastPressed) {
lastPressed = isPressed;
Serial.print(F("Switch State: "));
Serial.println(isPressed ? F("PRESSED -> LED ON") : F("RELEASED -> LED OFF"));
}
delay(10); // Brief settle interval
}Firmware Architecture Explanation:
- Enables the ATmega328P internal pull-up resistor via INPUT_PULLUP to keep D2 firmly at 5V when open.
- Converts active-LOW hardware logic into a clean boolean (isPressed) for readable control code.
- Logs edge transitions only when state changes, keeping Serial Monitor clean and readable.
Operational Verification & Pin State Matrix
Input Signal vs. System Output Truth Table:
| Input / State | Pin / Signal | Detected Condition | Expected Output |
|---|---|---|---|
| Open (Not Pressed) | D2 = HIGH (5V) | Internal pull-up active | D9 = LOW (LED OFF) |
| Closed (Pressed) | D2 = LOW (0V) | Pulled to GND | D9 = HIGH (LED ON) |
Engineering Troubleshooting Matrix
| Problem | Likely Cause | Diagnostic Check | Engineering Solution |
|---|---|---|---|
| LED stays permanently ON even without pressing | Button rotated 90° so permanently shorted legs were wired | Unplug one switch jumper—if LED turns off, button pins were shorted | Wire diagonal corners of the 4-pin tactile switch. |
| LED flickers randomly when finger nears wire | pinMode set to INPUT instead of INPUT_PULLUP without external resistor | Check pinMode(BTN_PIN, INPUT_PULLUP) in setup() | Enable INPUT_PULLUP or add an external 10kΩ pull-down resistor. |
| LED turns OFF when button is pressed | Active-LOW logic not inverted in code | Check digitalRead(BTN_PIN) == LOW condition | Invert the boolean expression when using INPUT_PULLUP. |
Engineering Challenges & Upgrades
Take your build to the next level with these progressive engineering upgrades:
Make the LED stay ON normally and switch OFF only while the button is held down.
Wire a second push button on D3 so the LED lights only when both buttons are pressed simultaneously.
Count total button presses and blink a second green LED every 5th click.