MyRoboPathOpen Robotics Lab
Arduino Uno #2 of 35
Est. 0.5 Hours
Budget: $1 - $3
Beginner

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.

Arduino Uno R3Tactile SwitchINPUT_PULLUPDigital InputFloating Pin Elimination
Control LED with Tactile Push Button Switch Blueprint
Control LED with Tactile Push Button SwitchCAD Blueprint

Key Learning Objectives & Robotics Concepts

By building and programming this project, you will master the following core engineering skills:

1Understand why unconnected digital inputs "float" and trigger erratic false readings.
2Wire a 4-pin tactile push button across the breadboard center channel to avoid shorting paired pins.
3Use INPUT_PULLUP to simplify hardware wiring and interpret active-LOW switch logic.
4Map digital input reads directly to digital actuator outputs with Serial diagnostics.

Power Architecture & Voltage Staging

5V / 3.3V Regulated Power

The 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.

Control LED with Tactile Push Button Switch Power Architecture Schematic
Figure: Regulated Arduino Uno supply rails, current budget, and component protection.Power Schematic

Bill of Materials (BOM) & Hardware Components

Bill of Materials for Control LED with Tactile Push Button Switch
ComponentSpecifications & AlternativeQtyApprox Cost
Arduino Uno R3ATmega328P microcontroller board1$8.00
4-Pin Tactile Push Button (6×6mm)Momentary SPST normally-open breadboard switch1$0.15
5mm LED + 220Ω ResistorVisual status output stage1$0.15
10kΩ Resistor (Optional Pull-Down)1/4W resistor for external active-HIGH lab variant1$0.05
Breadboard & Jumper Wires400-point breadboard + 5 jumpers1$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.

Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for Control LED with Tactile Push Button Switch.
Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for Control LED with Tactile Push Button Switch.Wiring Schematic

Autonomous Behavior & Finite State Machine (FSM)

Deterministic Arduino loop handling 4-Pin Tactile Push Button + 5mm LED acquisition, filtering, and real-time output updates.

Figure: Firmware execution flow and state transitions for Control LED with Tactile Push Button Switch.
Figure: Firmware execution flow and state transitions for Control LED with Tactile Push Button Switch.Control Algorithm

Step-by-Step Physical Assembly & Wiring Tutorial

Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.

1

Identify Paired Pins on the 4-Pin Tactile Switch

Duration: 5 Mins

Confirm which pairs of switch legs are internally shorted and which close only when pressed.

Control LED with Tactile Push Button Switch hardware layout diagram
Stage 1: 4-Pin Tactile Push Button + 5mm LED hardware inspection & pinout overview.Stage 1 Diagram
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Wiring diagonal corners of a 4-pin tactile switch always guarantees switching action regardless of orientation.
2

Wire Switch to D2 & LED to D9

Duration: 10 Mins

Connect one switch corner to D2, the opposite corner to GND, and wire the LED + 220Ω resistor on D9.

Control LED with Tactile Push Button Switch breadboard wiring check diagram
Stage 2: Breadboard layout & Arduino Uno pin-to-pin wiring audit.Stage 2 Diagram
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Using INPUT_PULLUP removes the need for an external 10kΩ resistor while staying 100% immune to floating noise.
3

Inspect Ground Commonality

Duration: 5 Mins

Ensure Arduino GND connects securely to the shared breadboard ground rail.

Control LED with Tactile Push Button Switch power rail protection diagram
Stage 3: Supply rail check (USB 5.0V Regulated Rail (≈15mA active)) and circuit protection verification.Stage 3 Diagram
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Color-code ground wires black or blue so circuit tracing stays effortless.
4

Flash Momentary & Latch Control Sketch

Duration: 5 Mins

Upload the active-LOW switch controller sketch and inspect Serial Monitor output.

Control LED with Tactile Push Button Switch serial telemetry verification diagram
Stage 4: Firmware upload & 115200 baud Serial Monitor verification.Stage 4 Diagram
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Remember: with INPUT_PULLUP, digitalRead(BTN_PIN) == LOW means the button IS pressed!
5

Test Responsiveness & Active-HIGH Comparison

Duration: 10 Mins

Verify zero flicker when your hand approaches the wires, proving the input is firmly pulled HIGH.

Control LED with Tactile Push Button Switch live operational logic diagram
Stage 5: Live operational logic flow & calibration verification.Stage 5 Diagram
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: In Project 6 you will add software debouncing and multi-gesture detection on top of this circuit.

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 Diagnostic

Minimal standalone sketch to verify pin wiring and signal response for 4-Pin Tactile Push Button + 5mm LED before running the full project firmware.

Arduino IDE Diagnostic ScriptC++ / Arduino
// 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);
}
Expected Output: Prints RELEASED (HIGH) at rest and PRESSED (LOW) while held down.

Complete Production Firmware

Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.

arduino_uno_push_button_led_control.ino
arduino_uno_push_button_led_control.inoArduino C++
/**
 * 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

1Double-check all 3 Arduino Uno pin connections against the wiring schematic before plugging in USB.
2Upload the Bench Diagnostic sketch first and confirm Serial Monitor at 115200 baud matches: Prints RELEASED (HIGH) at rest and PRESSED (LOW) while held down.
3Upload the complete production sketch and verify every condition in the operational truth table below.

Input Signal vs. System Output Truth Table:

Operational truth table for Control LED with Tactile Push Button Switch
Input / StatePin / SignalDetected ConditionExpected Output
Open (Not Pressed)D2 = HIGH (5V)Internal pull-up activeD9 = LOW (LED OFF)
Closed (Pressed)D2 = LOW (0V)Pulled to GNDD9 = HIGH (LED ON)

Engineering Troubleshooting Matrix

Engineering troubleshooting matrix for Control LED with Tactile Push Button Switch
ProblemLikely CauseDiagnostic CheckEngineering Solution
LED stays permanently ON even without pressingButton rotated 90° so permanently shorted legs were wiredUnplug one switch jumper—if LED turns off, button pins were shortedWire diagonal corners of the 4-pin tactile switch.
LED flickers randomly when finger nears wirepinMode set to INPUT instead of INPUT_PULLUP without external resistorCheck pinMode(BTN_PIN, INPUT_PULLUP) in setup()Enable INPUT_PULLUP or add an external 10kΩ pull-down resistor.
LED turns OFF when button is pressedActive-LOW logic not inverted in codeCheck digitalRead(BTN_PIN) == LOW conditionInvert the boolean expression when using INPUT_PULLUP.

Engineering Challenges & Upgrades

Take your build to the next level with these progressive engineering upgrades:

Level 1Inverted Logic Safety Lamp

Make the LED stay ON normally and switch OFF only while the button is held down.

Level 2Dual-Button AND Gate

Wire a second push button on D3 so the LED lights only when both buttons are pressed simultaneously.

Level 3Press Counter Telemetry

Count total button presses and blink a second green LED every 5th click.