Skip to content

StarkAg/PIR-Home

Repository files navigation

PIR Motion Sensor with Stadium Wave LED Effect

Arduino C++ License

A home automation project that detects motion using a PIR sensor and creates a mesmerizing stadium wave effect with LEDs

Features β€’ Hardware β€’ Setup β€’ Usage β€’ Demo


πŸ“– About

This project combines a PIR (Passive Infrared) motion sensor with an Arduino Uno to create an interactive lighting system. When motion is detected, three LEDs perform a stadium-style wave effect, turning on sequentially and then turning off with a visible delayβ€”perfect for home security, room lighting, or just a cool visual display!

🎯 Use Cases

  • Home Security: Visual alert when motion is detected
  • Room Lighting: Automatic light activation
  • Educational Project: Learn about sensors, state machines, and Arduino programming
  • Visual Display: Create an eye-catching LED animation

✨ Features

  • 🎯 Motion Detection: Reliable PIR sensor (HC-SR501) with 3-7 meter range
  • 🌊 Stadium Wave Effect: Sequential LED activation with customizable timing
  • βš™οΈ Configurable: Easy to adjust timing, pins, and number of LEDs
  • πŸ“Š Serial Debugging: Real-time status messages via serial monitor
  • πŸ—οΈ State Machine Architecture: Clean, maintainable code structure
  • πŸ”§ Arduino CLI Support: No IDE required, compile and upload from terminal

🏠 Home Setup Visualization

Physical Setup

    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚         Home Setup View                 β”‚
    β”‚                                         β”‚
    β”‚    [PIR Sensor]                         β”‚
    β”‚      (Wall)                             β”‚
    β”‚       β”‚                                 β”‚
    β”‚       β”‚ Detects Motion                  β”‚
    β”‚       β–Ό                                 β”‚
    β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                      β”‚
    β”‚    β”‚  Arduino    β”‚                      β”‚
    β”‚    β”‚    Uno      β”‚                      β”‚
    β”‚    β”‚             β”‚                      β”‚
    β”‚    β”‚  Pin 8  ────┼───► [LED 1] πŸ”΄      β”‚
    β”‚    β”‚  Pin 9  ────┼───► [LED 2] 🟑      β”‚
    β”‚    β”‚  Pin 10 ────┼───► [LED 3] 🟒      β”‚
    β”‚    β”‚  Pin 2  ◄───┼─── [PIR OUT]        β”‚
    β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                      β”‚
    β”‚                                         β”‚
    β”‚    When motion detected:                β”‚
    β”‚    πŸ”΄ β†’ 🟑 β†’ 🟒 (Wave ON)              β”‚
    β”‚    πŸ”΄πŸŸ‘πŸŸ’ (All ON - 3 sec)            β”‚
    β”‚    πŸ”΄ β†’ 🟑 β†’ 🟒 (Wave OFF)             β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Stadium Wave Effect Animation

Motion Detected! πŸŽ‰

STEP 1: Wave ON (200ms intervals)
    πŸ”΄          🟑          🟒
    ON  ────►  OFF ────►  OFF
    ON  ────►  ON  ────►  OFF
    ON  ────►  ON  ────►  ON

STEP 2: All ON (3 seconds)
    πŸ”΄πŸŸ‘πŸŸ’
    ALL ON!

STEP 3: Wave OFF (300ms intervals)
    πŸ”΄          🟑          🟒
    OFF ────►  ON  ────►  ON
    OFF ────►  OFF ────►  ON
    OFF ────►  OFF ────►  OFF

Ready for next motion detection...

πŸ› οΈ Hardware Requirements

Component Quantity Notes
Arduino Uno 1Γ— Or compatible board
PIR Sensor (HC-SR501) 1Γ— Motion detection sensor
LED (any color) 3Γ— For stadium wave effect
220Ξ© Resistor 3Γ— One for each LED
Jumper Wires ~10Γ— For connections
Breadboard 1Γ— Optional, but recommended
USB Cable 1Γ— For Arduino programming

Estimated Cost: ~$15-25 USD


πŸ“ Wiring Diagram

Circuit Diagram (ASCII Art)

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Arduino Uno   β”‚
                    β”‚                 β”‚
     PIR Sensor     β”‚  5V ────────────┼───► VCC
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚                 β”‚
    β”‚ HC-SR501 β”‚    β”‚  GND ───────────┼───► GND
    β”‚          β”‚    β”‚                 β”‚
    β”‚  VCC ────┼────┼──► 5V           β”‚
    β”‚  GND ────┼────┼──► GND          β”‚
    β”‚  OUT ────┼────┼──► Pin 2        β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚                 β”‚
                    β”‚  Pin 8 ────[220Ξ©]───► LED 1 (+)
                    β”‚                 β”‚      β”‚
                    β”‚  Pin 9 ────[220Ξ©]───► LED 2 (+)
                    β”‚                 β”‚      β”‚
                    β”‚  Pin 10 ───[220Ξ©]───► LED 3 (+)
                    β”‚                 β”‚      β”‚
                    β”‚  GND ───────────┼──────┼──────┼──► LED (-)
                    β”‚                 β”‚      β”‚      β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚      β”‚
                                             β”‚      β”‚
                                           [220Ξ©] [220Ξ©]
                                             β”‚      β”‚
                                            GND    GND

Connection Table

Component Pin/Port Arduino Connection
PIR Sensor VCC 5V
PIR Sensor GND GND
PIR Sensor OUT Digital Pin 2
LED 1 Anode (+) Digital Pin 8 (via 220Ξ© resistor)
LED 1 Cathode (-) GND
LED 2 Anode (+) Digital Pin 9 (via 220Ξ© resistor)
LED 2 Cathode (-) GND
LED 3 Anode (+) Digital Pin 10 (via 220Ξ© resistor)
LED 3 Cathode (-) GND

⚠️ Important:

  • Always use resistors (220Ξ©) with LEDs to prevent damage
  • Check LED polarity (longer leg = anode/+)
  • Ensure PIR sensor has 30-60 seconds to calibrate after power-on

πŸš€ Setup

Prerequisites

  1. Install Arduino CLI

    # macOS (using Homebrew)
    brew install arduino-cli
    
    # Linux
    curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
    
    # Windows (using Chocolatey)
    choco install arduino-cli
  2. Initialize Arduino CLI

    arduino-cli config init
    arduino-cli core update-index
    arduino-cli core install arduino:avr
  3. Clone this repository

    git clone https://github.com/yourusername/pir-motion-sensor.git
    cd pir-motion-sensor

Upload to Arduino

  1. Find your Arduino port

    arduino-cli board list
    # Look for something like: /dev/cu.usbmodemXXXX or COM3
  2. Compile and upload

    # Create sketch directory (Arduino CLI requirement)
    mkdir -p pir_motion_sensor
    cp pir_motion_sensor.ino pir_motion_sensor/pir_motion_sensor.ino
    
    # Compile
    arduino-cli compile --fqbn arduino:avr:uno pir_motion_sensor
    
    # Upload (replace PORT with your actual port)
    arduino-cli upload -p /dev/cu.usbmodemXXXX --fqbn arduino:avr:uno pir_motion_sensor
  3. Or use the provided scripts

    # Make scripts executable
    chmod +x upload.sh monitor.sh
    
    # Upload
    ./upload.sh /dev/cu.usbmodemXXXX
    
    # Monitor serial output
    ./monitor.sh

πŸ“Š Usage

Serial Monitor

Open the serial monitor to see real-time status:

arduino-cli monitor -p /dev/cu.usbmodemXXXX -c baudrate=9600

Expected Output

PIR Motion Sensor with Stadium Wave - Initialized
Calibrating PIR sensor... Please wait 30-60 seconds.
Calibration complete. Ready to detect motion!
Wave effect: LEDs will turn on in sequence (8->9->10)
Then turn off in sequence with visible delay.

Motion detected! Starting stadium wave...
LED 8 ON
LED 9 ON
LED 10 ON
All LEDs ON - Stadium wave complete!
LED 8 OFF - Starting wave off
LED 9 OFF
LED 10 OFF
All LEDs OFF - Ready for next motion detection

Configuration

Edit pir_motion_sensor.ino to customize:

// Pin configuration
const int PIR_PIN = 2;              // PIR sensor pin
const int LED_PINS[] = {8, 9, 10};  // LED pins
const int NUM_LEDS = 3;             // Number of LEDs

// Timing configuration
const unsigned long WAVE_ON_DELAY = 200;    // Delay between LEDs turning on (ms)
const unsigned long ALL_ON_DURATION = 3000; // All LEDs on duration (ms)
const unsigned long WAVE_OFF_DELAY = 300;   // Delay between LEDs turning off (ms)

🎬 Demo

How It Works

  1. Initialization: Arduino waits 30 seconds for PIR calibration
  2. Motion Detection: PIR sensor detects movement (rising edge trigger)
  3. Wave ON: LEDs turn on sequentially (200ms delay)
  4. All ON: All LEDs stay on for 3 seconds
  5. Wave OFF: LEDs turn off sequentially (300ms delay)
  6. Idle: System waits for next motion detection

State Machine

    IDLE
      β”‚
      β”‚ Motion Detected
      β–Ό
   WAVE_ON (8β†’9β†’10)
      β”‚
      β”‚ All LEDs ON
      β–Ό
    ALL_ON (3 seconds)
      β”‚
      β”‚ Duration Expired
      β–Ό
   WAVE_OFF (8β†’9β†’10)
      β”‚
      β”‚ All LEDs OFF
      β–Ό
    IDLE (waiting...)

πŸ› Troubleshooting

LEDs Don't Turn On

  • βœ… Check LED polarity (longer leg = anode)
  • βœ… Verify 220Ξ© resistors are connected
  • βœ… Test LEDs individually (connect to 5V via resistor)
  • βœ… Verify pins 8, 9, 10 are correctly wired
  • βœ… Check if wave effect is working (should see sequential lighting)

PIR Sensor Not Detecting Motion

  • βœ… Wait 30-60 seconds after power-on for calibration
  • βœ… Adjust sensitivity potentiometer on HC-SR501
  • βœ… Check connections (VCC, GND, OUT)
  • βœ… Move within detection range (3-7 meters)
  • βœ… Ensure sensor has clear line of sight

Upload Errors

  • βœ… Check USB cable connection
  • βœ… Verify correct port in upload command
  • βœ… Close other programs using the serial port
  • βœ… Try unplugging and replugging Arduino
  • βœ… Install correct board drivers

Serial Monitor Not Showing Output

  • βœ… Verify baud rate is 9600
  • βœ… Check correct port is selected
  • βœ… Ensure Arduino is powered and connected
  • βœ… Wait for calibration period to complete

πŸ”§ Expanding the Project

Possible Enhancements

  • More LEDs: Add more LEDs to the wave (increase NUM_LEDS)
  • Reverse Wave: Change direction (10β†’9β†’8)
  • RGB LEDs: Use RGB LEDs for colorful effects
  • Multiple Waves: Trigger multiple wave cycles
  • Audio Feedback: Add buzzer synchronized with wave
  • OLED Display: Show motion status and statistics
  • WiFi Integration: ESP32 for remote monitoring
  • Relay Module: Control larger devices (lights, fans)
  • Motion Counter: Log and display motion count
  • Different Patterns: Circular, back-and-forth waves
  • Web Interface: Control via web dashboard
  • Mobile App: Smartphone notifications

Code Structure

pir_motion_sensor.ino
β”œβ”€β”€ Pin Definitions
β”œβ”€β”€ Timing Configuration
β”œβ”€β”€ State Machine Enum
β”œβ”€β”€ State Variables
β”œβ”€β”€ setup()
β”‚   β”œβ”€β”€ Serial initialization
β”‚   β”œβ”€β”€ Pin configuration
β”‚   └── Calibration delay
└── loop()
    β”œβ”€β”€ Motion detection
    └── State machine
        β”œβ”€β”€ IDLE
        β”œβ”€β”€ WAVE_ON
        β”œβ”€β”€ ALL_ON
        └── WAVE_OFF

πŸ“ Project Structure

pir-motion-sensor/
β”œβ”€β”€ pir_motion_sensor.ino    # Main Arduino sketch
β”œβ”€β”€ README.md                 # This file
β”œβ”€β”€ upload.sh                 # Upload script
β”œβ”€β”€ monitor.sh                # Serial monitor script
└── .gitignore               # Git ignore file

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments

  • Arduino community for excellent documentation
  • HC-SR501 PIR sensor manufacturers
  • All contributors and testers

πŸ“§ Contact

For questions or suggestions, please open an issue on GitHub.


Made with ❀️ and Arduino

⭐ Star this repo if you found it helpful!

About

🏠 PIR Motion Sensor with Stadium Wave LED Effect - Arduino project for home automation with sequential LED lighting

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors