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

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

Tier 1 · Web · No account

Version tested: Compiled and booted by the Wokwi gate (ESP32 Arduino core 3.3.11); captured in the Wokwi web editor on 2026-09-09. Date: 2026-09-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,093 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 booted by the Wokwi gate (ESP32 Arduino core 3.3.11); captured in the Wokwi web editor on 2026-09-09 on 2026-09-09; the tool may have moved on — the text steps are the contract.

  1. 1 Step 1

    Do
    Paste the prepared diagram and sketch into Wokwi ESP32. Inspect the PIR connections.
    You will see
    PIR OUT connects to GPIO 13, supply to VIN, and ground to GND. The status output uses GPIO 2.
    Why it matters
    This exercise uses a digital level, unlike the host’s addressed I2C sensors and chip-selected SPI devices.
    Step 1: PIR OUT, supply, and ground connect to the ESP32. The ring marks the PIR sensor terminals.
    Step 1 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  2. 2 Step 2

    Do
    Start the simulation at 115200 baud and let it run for at least 60 simulated seconds.
    You will see
    PIR warm-up: wait 60 seconds appears immediately. Motion evaluation starts after the original 60-second delay.
    Why it matters
    The boot marker proves startup only. It does not prove motion detection during the warm-up period.
    Step 2: PIR warm-up: wait 60 seconds appears while the original warm-up delay runs. The ring marks the warm-up message.
    Step 2 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  3. 3 Step 3

    Do
    After warm-up, select the PIR sensor and press Simulate Motion.
    You will see
    A sustained HIGH produces CONFIRMED MOTION after more than 500 ms and switches the GPIO 2 status output HIGH.
    Why it matters
    The sketch requires a duration, rather than accepting the first HIGH sample.
    Step 3: CONFIRMED MOTION appears after the PIR stays HIGH for more than 500 ms. The ring marks the confirmation.
    Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  4. 4 Step 4

    Do
    Leave the sensor alone after triggering it.
    You will see
    The default simulated pulse lasts about five seconds; when OUT returns LOW the status output clears without printing a separate reset message.
    Why it matters
    Confirmation state resets on LOW, allowing a later pulse to be evaluated independently.
    Step 4: The PIR is shown after its five-second pulse has ended; no separate reset message is printed. The ring marks the sensor after the pulse.
    Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  5. 5 Step 5

    Do
    Trigger motion again, and trigger once more while the pulse remains HIGH.
    You will see
    The continuous HIGH interval produces one confirmation; retriggering extends the interval rather than producing a second confirmation immediately.
    Why it matters
    The confirmedMotion flag suppresses repeated announcements until a LOW resets it.
    Step 5: The retriggered HIGH pulse produces one confirmation rather than an immediate second one. The ring marks that pulse confirmation.
    Step 5 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  6. 6 Step 6

    Do
    Stop the simulation, change MIN_TRIGGER_DURATION from 500 to 6000, restart, wait through warm-up, and trigger once.
    You will see
    A single default five-second pulse does not print CONFIRMED MOTION.
    Why it matters
    A duration threshold longer than the input pulse rejects that pulse; the setting must match the intended behavior.
    Step 6: After warm-up and one five-second pulse, no CONFIRMED MOTION line appears with the 6000 ms threshold. The ring marks the unchanged serial output.
    Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  7. 7 Step 7

    Do
    Restore MIN_TRIGGER_DURATION to 500, restart, wait through warm-up, and trigger once again.
    You will see
    CONFIRMED MOTION returns after a sustained pulse, establishing the original baseline.
    Why it matters
    Repeatable input and explicit thresholds help separate interface wiring failures from application filtering rules.
    Step 7: CONFIRMED MOTION returns after restoring the 500 ms threshold and completing warm-up. The ring marks the restored baseline confirmation.
    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. You need to read data from an SD card at 2 MB/s and also connect a BME280 environmental sensor. Which protocol combination is most appropriate?

    Return to the chapter’s knowledge check

Caution

The headless gate verifies compilation and the early warm-up marker within its 20-second window; it does not cover the later motion action. Wait 60 simulated seconds before testing motion. This digital PIR example does not identify people, measure distance, or validate real sensor warm-up and false-alarm performance. The generic ESP32 build explicitly defines the source’s LED_BUILTIN as GPIO 2.

Return to Protocol Diagnostics and Bus Design · Browse Labs