🔥 Project: Motion-Activated Light System Using Arduino + PIR Sensor bonkers image 🔥 project motion activated

1. Introduction

In this project, we’ll build a motion-activated light system using an Arduino and a PIR (Passive Infrared) sensor. When motion is detected in the sensor’s range, an LED light (or relay-controlled bulb) will turn on automatically and stay on for a set time before turning off. This concept is commonly applied in security lighting, automatic hallway lights, and energy-saving systems.


2. Learning Objectives

  • Understand how a PIR sensor detects motion using infrared radiation.
  • Learn to handle digital inputs from sensors.
  • Control an LED or a relay module to operate lights.
  • Implement timing functions in code for delay-based control.
  • Understand practical applications in home automation and energy efficiency.

3. Components and Tools Needed

You will need:

  • Arduino Uno or Nano
  • PIR Sensor (e.g., HC-SR501)
  • LED (or a 5V relay module for real bulbs)
  • Resistor (220Ω for LED)
  • Jumper wires and breadboard
  • Optional: External power supply if using relay and high-power light

4. Key Definitions and Concepts

PIR Sensor:

  • Stands for Passive Infrared Sensor.
  • Detects infrared radiation emitted by moving objects (like humans or animals).
  • Outputs a digital HIGH signal when motion is detected.

Digital Input:

  • Arduino reads a HIGH (1) or LOW (0) from digital pins.
  • Used to respond to real-world events (motion, switches, etc.).

Delay Function:

  • The delay(milliseconds) function pauses program execution, used to keep the light on for a set time.

5. Wiring Instructions (Circuit Description)

  • PIR Sensor VCC connects to Arduino 5V.
  • PIR Sensor GND connects to Arduino GND.
  • PIR Sensor OUT connects to Arduino Digital Pin 2.
  • LED long leg (anode) connects to Arduino Digital Pin 13 through a 220Ω resistor.
  • LED short leg connects to GND.
  • If using a relay module, connect its IN pin to Pin 13, VCC to 5V, and GND to GND.

6. Complete Arduino Code with Explanations

// Define pins
int pirPin = 2; // PIR sensor output
int lightPin = 13; // LED or relay control

void setup() {
pinMode(pirPin, INPUT); // Set PIR sensor as input
pinMode(lightPin, OUTPUT); // Set light as output
Serial.begin(9600); // For debugging
}

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

if (motionDetected == HIGH) {
Serial.println("Motion detected! Turning light ON.");
digitalWrite(lightPin, HIGH); // Turn on light
delay(5000); // Keep light on for 5 seconds
digitalWrite(lightPin, LOW); // Turn off light
Serial.println("Light OFF.");
} else {
// No motion detected, keep light off
digitalWrite(lightPin, LOW);
}

delay(100); // Small delay to reduce sensor polling noise
}

7. Testing and Debugging Tips

  • If the LED doesn’t light up:
    • Check PIR sensor orientation and connections.
    • Use Serial Monitor to verify PIR output status.
  • Adjust the PIR sensor’s onboard potentiometers:
    • Sensitivity (distance detection).
    • Time delay (how long output stays HIGH).
  • If using a relay, ensure the light bulb’s voltage and current are within the relay’s specs.

8. Project Extensions and Enhancements

  • Replace LED with a relay module to control real 220V AC lights.
  • Add a light-dependent resistor (LDR) to activate lights only at night.
  • Log motion events to an SD card or send via Wi-Fi (ESP8266) for IoT-based home security.
  • Add a buzzer for an audible alarm when motion is detected.
  • Install in real-world environments like doorways, gardens, or staircases.