A home automation project that detects motion using a PIR sensor and creates a mesmerizing stadium wave effect with LEDs
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!
- 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
- π― 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 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) β
βββββββββββββββββββββββββββββββββββββββββββ
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...
| 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
βββββββββββββββββββ
β 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
| 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 |
- 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
-
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
-
Initialize Arduino CLI
arduino-cli config init arduino-cli core update-index arduino-cli core install arduino:avr
-
Clone this repository
git clone https://github.com/yourusername/pir-motion-sensor.git cd pir-motion-sensor
-
Find your Arduino port
arduino-cli board list # Look for something like: /dev/cu.usbmodemXXXX or COM3 -
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
-
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
Open the serial monitor to see real-time status:
arduino-cli monitor -p /dev/cu.usbmodemXXXX -c baudrate=9600PIR 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
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)- Initialization: Arduino waits 30 seconds for PIR calibration
- Motion Detection: PIR sensor detects movement (rising edge trigger)
- Wave ON: LEDs turn on sequentially (200ms delay)
- All ON: All LEDs stay on for 3 seconds
- Wave OFF: LEDs turn off sequentially (300ms delay)
- Idle: System waits for next motion detection
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...)
- β 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)
- β 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
- β 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
- β Verify baud rate is 9600
- β Check correct port is selected
- β Ensure Arduino is powered and connected
- β Wait for calibration period to complete
- 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
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
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
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Arduino community for excellent documentation
- HC-SR501 PIR sensor manufacturers
- All contributors and testers
For questions or suggestions, please open an issue on GitHub.
Made with β€οΈ and Arduino
β Star this repo if you found it helpful!