Skip to content

Confirm sustained PIR motion

Distinguish a sustained digital PIR pulse from a pulse too short to pass a 500 ms confirmation rule.

Physics Phoebe: I want you to connect interface type to observable pin behavior and test the duration rule before trusting a motion alert., your practice guide

Physics Phoebe: I want you to connect interface type to observable pin behavior and test the duration rule before trusting a motion alert.
Predict the reading, then compare it with the measurement.

Wokwi ESP32

Third party Tool

Tier 1 · Web · No account

Version tested: Compiled and run in the public Wokwi ESP32 web editor on 2026-10-09; post-warm-up PIR behavior captured from real simulations. Date: 2026-10-09.

Open the ESP32 editor, paste diagram.json, then paste sketch.ino.

Open Wokwi to paste in the files (new tab)

Get the files

Use both prepared files. This is a paste-in setup; saving a project requires a Wokwi account.

diagram.json

721 bytes · Circuit connections

Download

sketch.ino

1,095 bytes · ESP32 program

Download

  1. Use the launch button above to open the ESP32 editor in Wokwi.
  2. Select the editor’s diagram.json tab and replace all its text with the supplied diagram.json.
  3. Select the sketch.ino tab, replace all its text with the supplied sketch.ino, then click Start Simulation.

Steps

Screens captured against Wokwi ESP32 Compiled and run in the public Wokwi ESP32 web editor on 2026-10-09; post-warm-up PIR behavior captured from real simulations on 2026-10-09; the tool may have moved on — the text steps are the contract.

  1. 1 Step 1

    Do
    In the Wokwi simulation panel, paste the prepared diagram and sketch into Wokwi ESP32. Inspect the PIR connections.
    You will see
    Input: the corrected sketch and supplied PIR diagram were loaded in the public Wokwi editor. Observed: the editor built the sketch and entered a running ESP32 simulation at 00:00.133. Observed: PIR OUT is wired to GPIO 13; its supply and ground reach VIN and GND. Observed: STATUS_LED_PIN is set to GPIO 2 in the visible sketch.
    Why it matters
    The running Stop control and boot text establish that this exact sketch compiled. The PIR is a digital input on GPIO 13, as shown by the wire and PIR_PIN declaration. The GPIO 2 output is named STATUS_LED_PIN so it does not collide with the core macro. The boot screen alone does not establish motion confirmation; later steps test that state.
    Step 1: running public Wokwi editor with STATUS_LED_PIN on GPIO 2 and PIR wiring; the ring marks the PIR terminals.
    Step 1 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  2. 2 Step 2

    Do
    In the Simulation toolbar, start Wokwi and read the warm-up message in Serial Monitor at 115200 baud.
    You will see
    Input: start the corrected sketch with the PIR idle. Observed: the simulation clock reached 01:00.314. Observed Serial Monitor: "PIR warm-up: wait 60 seconds". Observed: no "CONFIRMED MOTION" line appeared before the first deliberate pulse.
    Why it matters
    The startup line is emitted before the 60-second delay. The 01:00.314 clock confirms this run passed the delay. The absence of "CONFIRMED MOTION" at this point is the idle baseline. The next step applies a PIR pulse after warm-up to test the duration rule.
    Step 2: after warm-up, the running simulation clock reads 01:00.314; the ring marks the PIR warm-up line in Serial Monitor.
    Step 2 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  3. 3 Step 3

    Do
    In the Wokwi simulation panel, after warm-up, select the PIR sensor and press Simulate Motion.
    You will see
    Input: click Simulate motion after the 60-second warm-up. Observed: at 01:01.431, Serial Monitor shows "CONFIRMED MOTION". Observed: the ESP32 GPIO 2 status LED is blue. Observed: the sketch still displays MIN_TRIGGER_DURATION = 500.
    Why it matters
    The printed confirmation is a direct result of the sustained simulated PIR HIGH. The output appears after the 500 ms threshold, rather than on the first HIGH sample. The blue status LED matches digitalWrite(STATUS_LED_PIN, HIGH). The live clock and Stop control place this output in the active simulation.
    Step 3: the ring marks CONFIRMED MOTION at 01:01.431, with the GPIO 2 blue status LED lit.
    Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  4. 4 Step 4

    Do
    In the Wokwi simulation panel, leave the sensor alone after triggering it.
    You will see
    Input: leave the PIR alone after the first confirmation. Observed: at 01:07.014, the GPIO 2 blue status LED is dark. Observed Serial Monitor: one earlier "CONFIRMED MOTION" remains visible. Observed: no separate reset line is printed by this sketch.
    Why it matters
    The default simulated pulse ended before this capture. On LOW, the visible sketch clears triggerStartTime and confirmedMotion. The status LED is also written LOW, matching the dark GPIO 2 indicator. The retained serial line is history; it does not mean the output remains HIGH.
    Step 4: after the pulse, the ring marks the dark GPIO 2 status LED; the earlier confirmation remains in Serial Monitor.
    Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  5. 5 Step 5

    Do
    In the Wokwi simulation panel, trigger motion again, and trigger once more while the pulse remains HIGH.
    You will see
    Input: click Simulate motion again after reset, then click during that HIGH pulse. Observed: at 01:09.231, Serial Monitor contains two "CONFIRMED MOTION" lines in total. Observed: the GPIO 2 blue status LED is lit during this pulse. Observed: the second click did not create a third confirmation line.
    Why it matters
    The first line belongs to the earlier completed pulse. The second line proves a LOW interval reset the confirmation state. While HIGH continues, confirmedMotion remains true. That flag suppresses another print until a later LOW resets it.
    Step 5: the ring marks the second CONFIRMED MOTION after a later pulse; the click during HIGH added no third line.
    Step 5 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  6. 6 Step 6

    Do
    In the Wokwi simulation panel, stop the simulation, change MIN_TRIGGER_DURATION from 500 to 6000, restart, wait through warm-up, and trigger once.
    You will see
    Input: change MIN_TRIGGER_DURATION from 500 to 6000, restart, wait through warm-up, and click Simulate motion once. Observed: at 01:06.314, the editor shows MIN_TRIGGER_DURATION = 6000. Observed Serial Monitor: only "PIR warm-up: wait 60 seconds" follows the boot text. Observed: no "CONFIRMED MOTION" line and the GPIO 2 blue status LED is dark.
    Why it matters
    The default simulated PIR pulse ended before the 6000 ms threshold elapsed. With no qualifying HIGH interval, the confirmation branch did not print. The status LED remained LOW, matching the missing confirmation. The comparison changes only the threshold; the PIR wiring and sketch logic are otherwise the same.
    Step 6: at 01:06.314, the running editor shows the 6000 ms threshold and only the warm-up line in Serial Monitor; the ring marks the changed value.
    Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  7. 7 Step 7

    Do
    In the Wokwi simulation panel, restore MIN_TRIGGER_DURATION to 500, restart, wait through warm-up, and trigger once again.
    You will see
    Input: restore MIN_TRIGGER_DURATION to 500, restart, wait through warm-up, and click Simulate motion once. Observed: the running editor shows MIN_TRIGGER_DURATION = 500. Observed: at 01:01.797, Serial Monitor again shows "CONFIRMED MOTION". Observed: the GPIO 2 blue status LED is lit.
    Why it matters
    Restoring the 500 ms rule makes the same simulated pulse long enough to qualify. The warm-up line precedes the new confirmation in this restarted run. The blue status LED matches the confirmed branch of the visible sketch. The restored source is the committed lab sketch, so learners begin with the demonstrated baseline.
    Step 7: after restoring the 500 ms threshold, the ring marks CONFIRMED MOTION at 01:01.797 and the GPIO 2 status LED is lit.
    Step 7 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)

Chapter checks

These questions refer to the chapter’s examples. Use the return links to review their answers.

  1. An ESP32 has three I2C sensors: BMP280 (0x76), BH1750 (0x23), and SHT31 (0x44). After adding a second BMP280 for redundancy, both pressure readings return identical values. What is the most likely cause?

    Return to the chapter’s knowledge check
  2. An SD card must transfer at 2 MB/s. A BME280 also needs a connection, and GPIO pins are limited. Which protocol combination meets the throughput while keeping the sensor connection pin-efficient?

    Return to the chapter’s knowledge check

Caution

Wait 60 simulated seconds before testing motion. The browser run demonstrated the original 500 ms pulse confirmation, reset, and retrigger; change the threshold only for the comparison step, then restore it. This digital PIR example does not identify people, measure distance, or validate real sensor warm-up and false-alarm performance. The status output is GPIO 2 and is named STATUS_LED_PIN to avoid the ESP32 core LED_BUILTIN macro.

Return to Protocol Diagnostics and Bus Design · Browse Labs