Mission
Build this
Build a fixed PIR passage detector that turns one long motion signal into one event, with an optional indoor IR comparison.
Borrowed parts are labelled below and have a fallback. The registered device ID is fixed; sensing and behaviour decisions remain yours.
Bill of materials
Parts
| Source | Part | Fallback |
|---|---|---|
| ● kit | PIR sensor | — |
| ● kit | IR emitter, receiver, 220 Ω and 10 kΩ resistors | — |
| ● kit | SG90 servo | — |
Disconnect USB before rewiring. Motors, the relay, and the servo need appropriate power and a shared ground. Never drive an actuator from the ESP32 3V3 pin.
Your invitation
Build an invisible curtain from changing warmth
The Path Tripwire does not shine a beam across the path. It quietly watches the pattern of infrared warmth in several broad regions. When a warm body moves from one region to another, the pattern changes and the sensor wakes.
That makes it wonderfully simple and wonderfully imperfect. It can notice movement beyond the path, miss someone moving straight toward it, or react differently under sun and shade. Your job is to place it, test it, and turn one stretched signal into one fair event.
“The sensor saw the gardener’s warm arm, but ignored the cold cart rolling beside them.”
The central idea
PIR notices change, not presence
PIR means passive infrared. “Passive” matters: the sensor sends nothing into the path. A small lens divides its view into regions. When warm infrared energy moves across those regions, the output changes.
Warmth crosses several lens regions. Usually easy to notice.
Less sideways change across regions. Sometimes harder.
Warm body remains, but the pattern stops changing.
One person can hold the PIR output active for several seconds. Count the beginning of a debounced event, then wait through a refractory period before accepting another.
Why compare with an active infrared pair only indoors?
An emitter and receiver can form a beam that changes when something blocks it. That is a different clue from PIR and can make a useful controlled comparison.
Strong sunlight already contains abundant infrared and can overwhelm a simple receiver. Keep this comparison indoors or deeply shaded. The PIR remains the outdoor passage sensor.
Placement writes the question
The same sensor can watch a path, a tree, or the horizon
Legs cross the regions
Good motion contrast, but small animals and warm ground may join the story.
Bodies fill the view
Strong human signal, but vegetation and distant paths may remain visible.
Bound the background
Reduces distant motion, but changes the useful passage width.
A cardboard hood can narrow the sides without covering the white lens. Mark height, angle, and walking line before collecting data. If placement changes, the experiment begins again.
Wiring
Build the passive watcher before the optional beam
Let the PIR report raw HIGH and LOW transitions first. Add the servo after debouncing. Build the IR comparison only after the outdoor path detector is complete.
The power rule: The common PIR module uses 5 V and returns 3.3 V logic. The optional IR receiver pull-up uses 3V3. The servo uses a separate 5 V supply. Join all grounds.
Bench referenceOpen the exact wiring map
| ESP32 pin | Part | Part marking | Carries |
|---|---|---|---|
5V / VIN | PIR sensor | VCC | 5V power — common HC-SR501 supply |
GPIO 27 | PIR sensor | OUT | Digital in/out — 3.3 V logic output |
GND | PIR sensor | GND | Ground |
GPIO 25 | IR emitter | anode via 220 Ω | Digital in/out — optional indoor comparison |
GND | IR emitter | cathode | Ground |
GPIO 34 | IR receiver | collector + 10 kΩ pull-up | Analog voltage — pull up to 3V3; optional indoor comparison |
GND | IR receiver | emitter | Ground |
GPIO 18 | SG90 servo | signal (orange) | PWM to actuator — short startled gesture |
external 5 V | SG90 servo | power (red) | 5V power — separate supply |
GND | SG90 servo | ground (brown) | Ground — join servo and ESP32 grounds |
Confirm your PIR pin order before powering it; modules differ. Keep outdoor joints dry. Never allow a 5 V module output to reach an ESP32 GPIO.
- 5V power
- Digital in/out
- Ground
- Analog voltage
- PWM to actuator
The optional IR pair shown is for a bare emitter and phototransistor. If your kit uses a module, follow its printed pin labels and verify that OUT is 3.3 V safe.
Teach it to startle once
A long signal should produce one short event
PIR output LOW. Ready for a new event.
Candidate begins. Confirm the signal.
Count once and gesture once, however long HIGH lasts.
Wait for LOW and a quiet interval before rearming.
Your team decides:
- How long must HIGH persist before it is real?
- How long must the path be quiet before rearming?
- Does a very long HIGH state become “blocked,” “motion,” or “uncertain”?
- What startled gesture is clear without moving the sensor?
Your path trials
Walk the same line until the sensor’s blind spots appear
- Mark the route.
Fix the walking line, direction, speed range, sensor height, and angle.
- Run twenty crossings per condition.
Test sun, shade, across-view motion, toward-view motion, and at least one distant distraction.
- Count misses and doubles.
A detection rate without a double-count rate tells only half the story.
- Tune placement once.
Repeat the full set after one justified change, then keep the better fixed result.
| Condition | Crossings | Detected | Double counts | Other motion |
|---|---|---|---|---|
| shade, across view | 20 | ___ | ___ | none |
| sun, toward sensor | 20 | ___ | ___ | ___ |
| empty path, distant motion | 20 trials | — | ___ false | ___ |
When the curtain ripples
The path is larger than the line you drew
The PIR fires for a minute after startup
It is stabilising. Keep the scene still during warm-up and exclude that interval from results.
One walker creates two events
The signal briefly dropped or your refractory period ended too soon. Require a sustained quiet interval before rearming.
Someone walking toward the sensor is missed
Their warmth crosses fewer lens regions. Turn the sensor so normal traffic moves sideways across its view.
Leaves beyond the path cause events
The field of view includes the background. Aim downward or add a side hood, then repeat the empty-path trials.
The servo gesture creates another event
It shakes the sensor or moves a warm structure in view. Isolate the mount and keep the gesture outside the lens field.
Choose your path question
What kind of tripwire team will you become?
The placement scouts
Make height, angle, and hood shape the experiment. Map the useful and distracting field of view.
The timing designers
Make confirmation and refractory periods the experiment. Balance misses against double counts.
The clue comparers
Indoors, compare passive warmth changes with an active IR beam and explain where each fails.
A calm way through the build
Collect four small wins
pt-01says hello.Join the garden before watching the path.
- One crossing creates one raw pulse story.
Watch HIGH and LOW before counting.
- One long pulse becomes one event.
Add confirmation and a refractory state.
- The startled gesture leaves the sensor undisturbed.
Add separate servo power, then run the fixed route.
The garden handshake
Share what you found
These names are the rigid part of the project. They let another team find your work without knowing what you called the variables in your code.
Accepted path events
garden/outdoor-1/path-node/pt-01/countUnit: events
Motion state
garden/outdoor-1/path-node/pt-01/motionUnit: enum
Listen beyond your own device.
garden/entrance/counter/gk-01/countCompare aggregate path and entrance activity over shared periods. Never claim that one path event belongs to one particular entrance event or person.
Finish line
Ready to introduce to the garden
pt-01 stays online and publishes accepted count and motion state.
The reject feed stays clear after the final code starts.
The device reads the aggregate Gate Keeper count.
Each debounced passage produces one short gesture without moving the sensor or blocking messages.
The build log records fixed placement, twenty trials per condition, detection rate, double-count rate, distant-motion false alarms, and one blind spot.
Outdoor electronics are protected, the mount is fixed, the servo is safely powered, and the device label can be scanned.
The Path Tripwire does not see people. It notices changing warmth in a chosen field of view. The strength of the project is knowing exactly how different those statements are.