The Phantom in the Shadows
The abandoned facility stretches before you, its corridors shrouded in perpetual twilight. Your footsteps echo against cracked concrete walls as you navigate deeper into the complex, following the faint traces of electromagnetic signatures that suggest valuable salvage ahead. But you're not alone out here.
In the post-apocalyptic wasteland, rival scavenger crews move like ghosts through the ruins, always hunting for the same precious electronics that could mean the difference between survival and starvation. They've learned to move silently, to avoid the automated defense systems that still guard some facilities. But silence isn't enough when motion itself betrays presence.
You pause at a junction, pressing your back against a steel support beam. Something moved in the shadows ahead, just beyond the reach of your headlamp. Your hand instinctively moves to the motion detection device clipped to your gear. The HC-SR501 PIR sensor has been your silent guardian for weeks now, its invisible infrared eyes watching for the heat signatures of approaching threats.
The device works by detecting changes in infrared radiation, the heat that all living things emit. When a warm body moves through its field of view, it triggers an alert that could save your life. Today, you'll learn to build and program this essential survival tool, turning your HERO Board into a motion-sensing sentinel that watches your back while you focus on the salvage ahead.
The stakes are real in this wasteland. Miss a threat, and you might not make it back to base. But with proper motion detection, you'll have the advantage of knowing when something moves in your vicinity, even when your attention is elsewhere. Time to wire up your electronic watchdog.
What You'll Learn
When you finish this lesson, you'll be able to:
- Wire an HC-SR501 PIR motion sensor to your HERO Board and understand why each connection is essential
- Program your microcontroller to detect when motion starts and stops, not just when motion is present
- Create a state-tracking system that prevents spam alerts and only reports actual changes
- Debug motion detection issues and optimize sensor placement for maximum coverage
- Apply motion sensing principles to security systems, automated lighting, and energy conservation
Understanding Motion Detection
Motion detection might sound like science fiction, but it's surprisingly straightforward once you understand the physics. Every warm object, including humans and animals, emits infrared radiation. Think of it as an invisible heat signature that radiates outward from your body at all times.
The HC-SR501 PIR (Passive Infrared) sensor works like an electronic guard dog with superhuman senses. It continuously monitors the infrared radiation in its field of view, building a baseline of what "normal" looks like. When something warm moves through that space, it creates a sudden change in the infrared pattern, triggering the sensor.
The "passive" part is crucial. Unlike active sensors that emit signals and wait for reflections, PIR sensors simply observe. They're like thermal cameras that can only see temperature changes, not steady heat sources. This makes them perfect for detecting movement while ignoring stationary warm objects like radiators or computers that have been running for hours.
The sensor has a detection range of about 7 meters and a 110-degree field of view, creating a cone of surveillance that can monitor a room's entrance or a hallway intersection. When motion is detected, it outputs a HIGH signal for a predetermined time, then returns to LOW when the area is clear.
Real-world applications are everywhere. Security systems use PIR sensors to detect intruders. Automatic lighting systems turn on when you enter a room. Smart thermostats know when rooms are occupied. Even wildlife cameras use motion detection to capture animal behavior without human intervention.
Wiring Your Motion Detector

- VCC to 5V: The HC-SR501 needs 5 volts to power its infrared detection circuitry. This provides the energy for the sensor's amplification stages and signal processing.
- GND to Ground: Completes the electrical circuit and provides a reference point for voltage measurements. Without this, the sensor can't function properly.
- OUT to Digital Pin 2: This is where the sensor communicates with your HERO Board. When motion is detected, this pin goes HIGH (5V). When no motion is present, it stays LOW (0V).