DIY Motion Sensor Light with Arduino

Motion sensor lights are practical DIY projects that combine electronics fundamentals with real-world applications. This tutorial will guide you through building your own automatic light system using an Arduino and a PIR (Passive Infrared) sensor. This project is perfect for beginners looking to understand how sensors, microcontrollers, and actuators work together.

Understanding PIR Motion Sensors

A PIR (Passive Infrared) sensor detects changes in infrared radiation emitted by warm objects, including humans and animals. Unlike active sensors that emit and receive signals, PIR sensors are passive – they only detect infrared energy. When a warm body moves within the sensor’s field of view, it triggers a signal that can be read by your Arduino.

Key specifications of typical PIR sensors:

  • Detection range: 3-7 meters (adjustable on most modules)
  • Detection angle: 110-120 degrees
  • Operating voltage: 4.5V to 20V DC
  • Output: Digital HIGH (3.3V) when motion detected, LOW otherwise

Materials Needed

Before starting this project, gather these components:

  • Arduino UNO R3 – The microcontroller brain of the project (approx. PHP 350-500)
  • HC-SR501 PIR Motion Sensor – Detects human movement (approx. PHP 50-80)
  • LED (5mm, any color) – Visual output indicator (approx. PHP 5-10)
  • 220-ohm resistor – Current limiting for LED protection (approx. PHP 1-2)
  • Breadboard – Prototyping board for connections (approx. PHP 50-100)
  • Jumper wires – Male-to-male connections (approx. PHP 30-50)
  • USB cable – For programming and power

Total estimated cost: PHP 500-750

Circuit Connections

Follow these step-by-step wiring instructions:

PIR Sensor Connections

  1. Connect PIR VCC pin to Arduino 5V
  2. Connect PIR GND pin to Arduino GND
  3. Connect PIR OUT pin to Arduino Digital Pin 2

LED Connections

  1. Connect LED positive leg (longer leg/anode) to Arduino Digital Pin 13 through a 220-ohm resistor
  2. Connect LED negative leg (shorter leg/cathode) to Arduino GND

Arduino Code

Upload this code to your Arduino using the Arduino IDE:

// Motion Sensor Light - Arduino Project
// Hamnus.com Computer Engineering Tutorial

const int pirPin = 2;    // PIR sensor output pin
const int ledPin = 13;   // LED output pin
int pirState = LOW;      // Current state of PIR
int val = 0;             // Variable to store PIR reading

void setup() {
  pinMode(ledPin, OUTPUT);     // Set LED as output
  pinMode(pirPin, INPUT);      // Set PIR as input
  Serial.begin(9600);          // Initialize serial communication
}

void loop() {
  val = digitalRead(pirPin);   // Read PIR sensor

  if (val == HIGH) {           // Motion detected
    digitalWrite(ledPin, HIGH); // Turn LED ON
    if (pirState == LOW) {
      Serial.println("Motion detected!");
      pirState = HIGH;
    }
  } else {                     // No motion
    digitalWrite(ledPin, LOW);  // Turn LED OFF
    if (pirState == HIGH) {
      Serial.println("Motion ended.");
      pirState = LOW;
    }
  }

  delay(100);  // Small delay for stability
}

How It Works

The program continuously monitors the PIR sensor’s output pin. When infrared radiation changes (motion detected), the sensor outputs HIGH, triggering the LED to turn on. The serial monitor displays status messages for debugging. When motion stops, the sensor returns to LOW state after a brief delay (adjustable via potentiometer on the PIR module).

Adjusting PIR Sensitivity

Most HC-SR501 PIR modules have two potentiometers:

  • Sensitivity (Sx): Adjust detection range from 3m to 7m – turn clockwise to increase
  • Time delay (Tx): Adjust how long output stays HIGH after motion – ranges from 3 seconds to 5 minutes

Troubleshooting Common Issues

LED doesn’t light up:

  • Check LED polarity (long leg to positive)
  • Verify resistor connections
  • Test LED separately with 3V battery

False triggers (LED turns on randomly):

  • Allow 30-60 seconds warm-up time for PIR sensor
  • Keep away from heat sources and direct sunlight
  • Reduce sensitivity using Sx potentiometer

No detection at all:

  • Check all wire connections
  • Verify PIR sensor receives 5V power
  • Use Serial Monitor to debug sensor output

Real-World Applications

This basic project can be expanded for practical uses:

  • Bathroom/closet automatic lights – Replace LED with relay module to control AC lights
  • Security alarm system – Add buzzer for intrusion alerts
  • Energy-saving office lighting – Lights turn off when room is empty
  • Pet monitoring – Track pet movement and activity

Safety Considerations

  • Never connect AC mains voltage directly to Arduino
  • Use relay modules with proper isolation for AC applications
  • Always use appropriate current-limiting resistors for LEDs
  • Disconnect power before modifying circuits

This project demonstrates fundamental concepts in embedded systems: digital input/output, sensor integration, and basic programming logic. Once mastered, you can combine multiple sensors and actuators for more complex automation projects.

Previous Article
Next Article