Try It: PIR Detection Zone Simulator
Try Keep Detection range (m) at 5 and Mounting height (m) at 2.3; change Hold time (s) from 8 and compare the zone drawing.
Observe At the starting height, effective range stays at 5.0 m; changing Hold time (s) updates its card without resizing the zone.
Explain Mounting height (m) selects either the full requested range or a reduced range; coverage uses a circular area with radius equal to effective range times the tangent of half the fixed angle.
Calculate detection zone
Reset
Technical boundaries. The drawing assumes a 110-degree angle and applies a 30% range reduction outside mounting heights of 2.0–2.5 m. Warm-up is fixed at 60 seconds; trigger-mode text describes timing without simulating motion, false triggers or an output timeline.
Change the range and mounting height to see how this model draws a detection zone. Hold time affects how long the output remains high, not the size of the zone; the mode text describes how retriggering changes that interval. The fixed angle, height rule and coverage area are illustrative assumptions, not measured HC-SR501 performance. The model does not simulate false triggers or actual motion. Verify coverage and timing with walk tests on the installed module.
viewof pir_range = Inputs. range ([1 , 10 ], {value : 5 , step : 0.5 , label : "Detection range (m)" })
viewof pir_height = Inputs. range ([0.5 , 4 ], {value : 2.3 , step : 0.1 , label : "Mounting height (m)" })
viewof pir_hold = Inputs. range ([2.5 , 200 ], {value : 8 , step : 0.5 , label : "Hold time (s)" })
viewof pir_mode = Inputs. radio (["Single Trigger" , "Repeatable Trigger" ], {value : "Repeatable Trigger" , label : "Trigger mode" })
{
const angle = 110 ;
const halfAngle = angle / 2 ;
const heightOptimal = (pir_height >= 2.0 && pir_height <= 2.5 );
const effectiveRange = pir_range * (heightOptimal ? 1.0 : 0.7 );
const groundRadius = effectiveRange * Math . tan (halfAngle * Math . PI / 180 );
const coverageArea = Math . PI * groundRadius * groundRadius;
const warmupTime = 60 ;
const modeDesc = pir_mode === "Single Trigger"
? "Output goes HIGH once, then LOW after hold time. Ignores motion during hold period."
: "Output stays HIGH as long as motion continues. Hold timer resets with each new detection." ;
const svgW = 360 ;
const svgH = 200 ;
const sensorX = svgW / 2 ;
const sensorY = 30 ;
const maxVisRange = 160 ;
const scale = maxVisRange / 10 ;
const visRange = effectiveRange * scale;
const leftX = sensorX - visRange * Math . sin (halfAngle * Math . PI / 180 );
const rightX = sensorX + visRange * Math . sin (halfAngle * Math . PI / 180 );
const bottomY = sensorY + visRange * Math . cos (halfAngle * Math . PI / 180 );
return html `<div style="font-family: system-ui, sans-serif; background: #f8f9fa; border-radius: 8px; padding: 1.2rem; margin-top: 0.5rem;">
<div style="text-align: center; margin-bottom: 1rem;">
<svg width=" ${ svgW} " height=" ${ svgH} " viewBox="0 0 ${ svgW} ${ svgH} " style="width: 100%; max-width: ${ svgW} px; height: auto; background: white; border-radius: 6px; border: 1px solid #ddd;">
<defs>
<radialGradient id="pirZone" cx="50%" cy="0%" r="100%">
<stop offset="0%" style="stop-color:#16A085;stop-opacity:0.4"/>
<stop offset="100%" style="stop-color:#16A085;stop-opacity:0.05"/>
</radialGradient>
</defs>
<polygon points=" ${ sensorX} , ${ sensorY} ${ leftX} , ${ bottomY} ${ rightX} , ${ bottomY} "
fill="url(#pirZone)" stroke="#16A085" stroke-width="1.5" stroke-dasharray="4,2"/>
<circle cx=" ${ sensorX} " cy=" ${ sensorY} " r="8" fill="#2C3E50"/>
<text x=" ${ sensorX} " y=" ${ sensorY + 4 } " text-anchor="middle" fill="white" font-size="8" font-weight="bold">PIR</text>
<text x=" ${ sensorX} " y=" ${ bottomY + 15 } " text-anchor="middle" fill="#555" font-size="11"> ${ effectiveRange. toFixed (1 )} m effective range</text>
<text x=" ${ leftX + 5 } " y=" ${ (sensorY + bottomY) / 2 } " fill="#7F8C8D" font-size="10">110deg</text>
</svg>
</div>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: 0.8rem; margin-bottom: 1rem;">
<div style="background: #2C3E50; color: white; padding: 0.8rem; border-radius: 6px; text-align: center;">
<div style="font-size: 0.8rem; opacity: 0.8;">Coverage Area</div>
<div style="font-size: 1.3rem; font-weight: bold;"> ${ coverageArea. toFixed (1 )} m2</div>
</div>
<div style="background: ${ heightOptimal ? '#16A085' : '#E67E22' } ; color: white; padding: 0.8rem; border-radius: 6px; text-align: center;">
<div style="font-size: 0.8rem; opacity: 0.8;">Mount Height</div>
<div style="font-size: 1.3rem; font-weight: bold;"> ${ pir_height. toFixed (1 )} m</div>
<div style="font-size: 0.75rem; opacity: 0.7;"> ${ heightOptimal ? "Optimal" : "Suboptimal (-30% range)" } </div>
</div>
<div style="background: #3498DB; color: white; padding: 0.8rem; border-radius: 6px; text-align: center;">
<div style="font-size: 0.8rem; opacity: 0.8;">Hold Time</div>
<div style="font-size: 1.3rem; font-weight: bold;"> ${ pir_hold} s</div>
<div style="font-size: 0.75rem; opacity: 0.7;">Warm-up: ${ warmupTime} s</div>
</div>
</div>
<div style="font-size: 0.85rem; color: #555; background: white; padding: 0.6rem; border-radius: 4px;">
<strong> ${ pir_mode} :</strong> ${ modeDesc} <br>
<strong>Tip:</strong> ${ heightOptimal
? "Mounting at 2.0-2.5m provides optimal detection for head-height humans while reducing pet triggers."
: html `<span style="color: #E67E22;">Mount between 2.0-2.5m for best results. Current height reduces effective range by ~30%.</span>` }
</div>
</div>` ;
}
Back to the chapter