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.
Predict the reading, then compare it with the measurement.
Wokwi ESP32
Third party ToolDistinguish a sustained digital PIR pulse from a pulse too short to pass a 500 ms confirmation rule.
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.
sketch.ino
- Use the launch button above to open the ESP32 editor in Wokwi.
- Select the editor’s diagram.json tab and replace all its text with the supplied diagram.json.
- Select the sketch.ino tab, replace all its text with the supplied sketch.ino, then click Start Simulation.
Steps
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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · 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.
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 checkYou 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