Chapter 02: Base Security 101

Motion Sensor Security System

The Perimeter is Breached

The compound's emergency klaxon cuts through the night like a rusty blade. You jolt awake on your makeshift cot, the synthetic fabric still damp with condensation from the cooling unit that barely functions. Outside your reinforced shelter, the wasteland stretches endlessly under a moonless sky, dotted with the skeletal remains of civilization.

"Movement on the south perimeter," crackles the voice through your salvaged radio. "Unknown entities. Could be scavengers. Could be worse." The transmission cuts to static. In this new world, three months after the AI uprising turned every connected device into a potential weapon, paranoia isn't madness—it's survival.

You grab your electronics kit from the reinforced case beneath your bed. The HERO Board gleams under the harsh LED strip lighting, its circuits a reminder of humanity's ingenuity before the machines turned against us. Tonight, you're not just building a motion detector. You're creating the difference between waking up tomorrow and becoming another casualty in humanity's war for survival.

The PIR sensor in your hands weighs almost nothing, but its importance is immense. Every successful detection could mean early warning of raiders. Every false alarm could mean wasted energy from your precious battery reserves. The flood lights you'll control aren't just illumination—they're psychological warfare, turning the advantage of surprise back to the defenders.

Time to wire up your first line of defense. In the post-apocalyptic world, the best security system isn't the fanciest—it's the one you can build, maintain, and trust with your life.

What You'll Learn

When you finish this lesson, you'll be able to:

  • Connect a PIR motion sensor to detect movement in your area
  • Wire flood lights that activate automatically when motion is detected
  • Write code that reads sensor data and controls output devices
  • Implement timing logic to keep lights on for a set period after motion stops
  • Use the Serial Monitor to track and debug your security system
  • Understand how digital inputs and outputs work on the HERO Board

Understanding Motion Detection

Motion sensors work like the security guard's eyes, but they detect something your eyes can't see: infrared heat. Every living thing—humans, animals, even the undead if rumors are true—gives off body heat. A PIR (Passive Infrared) sensor watches for changes in heat patterns across its field of view.

Think of it like this: imagine you're staring at a wall that's painted with heat-sensitive paint. When someone walks past, their body heat creates a moving hot spot on that wall. The PIR sensor sees these temperature changes and says "Hey, something moved!"

The brilliant part is the timing system we'll build. Real security systems don't just turn on lights—they keep them on long enough to be useful, then turn them off to save power. Our system will detect motion, turn on the flood lights immediately, wait for motion to stop, then start a countdown timer before switching the lights back off.

This creates what security experts call "intelligent automation": the system responds instantly to threats but doesn't waste resources staying active when the area is clear. In the wasteland, every watt of power could mean the difference between having working defenses tomorrow or sitting in the dark.

Wiring Your Security System

Motion sensor security system wiring diagram

This wiring creates two separate circuits: one for detecting motion, one for controlling power to your lights.

  1. PIR Sensor Power: Connect VCC to 5V and GND to ground. The sensor needs clean, stable power to detect heat signatures accurately.
  2. PIR Signal Wire: Connect the OUT pin to digital pin 23. This carries the HIGH or LOW signal that tells us when motion is detected.
  3. LED Flood Lights: Connect the positive leg (longer) to digital pin 22, negative leg to ground through a 220-ohm resistor. The resistor prevents the LED from drawing too much current and burning out.
  4. Ground Connections: Both components share the HERO Board's ground. This creates a common reference point for all electrical signals.
Tip

PIR sensors can be sensitive to air currents and temperature changes. Mount yours away from heating vents or windows where it might get false triggers.

Complete Code

Here's the complete motion sensor security system code. Copy this into your HERO Board's programming environment: