Skip to content

Button Event Logger

Log button transitions with timestamps and a short non-blocking debounce interval.

Button Event Logger: the matching Arduino Uno circuit rendered in Circuitera’s simulator
Matching Circuitera simulator circuit. Real firmware capture; modeled components are idealized.

Wire it up

Disconnect power before changing connections. Follow terminal names rather than wire colors.

FromToWhy it matters
Pushbutton (button1) · 1.lUno · 2Match this terminal to the sketch
Pushbutton (button1) · 2.lUno · GND.2Ground reference

The complete sketch

button-event-logger.ino
int lastReading = HIGH, stable = HIGH;
unsigned long changedAt = 0;
void setup() { Serial.begin(9600); pinMode(2, INPUT_PULLUP); }
void loop() {
  int reading = digitalRead(2);
  if (reading != lastReading) changedAt = millis();
  if (millis() - changedAt >= 30 && reading != stable) {
    stable = reading;
    Serial.print(millis()); Serial.println(stable == LOW ? " pressed" : " released");
  }
  lastReading = reading;
}

The launch buttons use this same code and a matching saved circuit.

Build it step by step

  1. Open a complete project

    Launch in Simulator creates a separate Uno sketch and its matching wired circuit. Existing sketches are preserved. Press Run to compile and execute.

  2. Explore the live circuit

    Press and hold the button, then release. There should be one pressed event and one released event, not thousands of repeated lines.

  3. Try it on hardware

    Disconnect power while wiring. Match terminal names in the table, select the exact board, Verify, then connect and upload. Check component ratings and power requirements first.

Understand the sketch

Edges instead of repeated levels

The sketch prints only when the stable state changes. millis subtraction allows other work to continue and handles unsigned wraparound.

If something is different

Very short taps are ignored

A new reading must remain stable for 30 ms. That is the debounce interval, not a serial failure.

Expected output and tested scope

A press/release generates one timestamped event after debounce, rather than repeated events while held.

Version 1 · Last source- and build-matched test: 2026-10-25. Actual shipped AVR-GCC WASM compilation and Uno AVR engine execution; no physical hardware test.

Supported tutorial target: Arduino Uno R3 / ATmega328P. Compile: PASS · Modeled execution: PASS. Other boards require a separate review of pins, voltage, libraries and the exact build profile.

Keep exploring.