Pir Motion Sensor (Im-21066)
Pir Motion Sensor (Im-21066)
Pir Motion Sensor (Im-21066)
Detect Motion
Introduction
This report details the process of connecting a Passive Infrared (PIR) Motion Sensor with an
Arduino UNO to detect motion in a room or area surrounding the sensor. PIR sensors are
commonly used in security systems and automatic lighting because they can detect infrared
radiation from moving objects, particularly humans. This project will guide you through the setup
and programming necessary to create a basic motion detection system.
1. Arduino UNO: A popular microcontroller board used for building digital devices and
interactive objects. (Cost: PKR 800)
2. PIR Motion Sensor: A sensor that detects infrared radiation from moving objects. (Cost:
PKR 200)
3. Jumper Wires: Used to make electrical connections between the Arduino and other
components. (Cost: PKR 30 for 5 pcs)
4. LED Light: An indicator that lights up when motion is detected. (Cost: PKR 10) Total
Component Details
1. Arduino UNO
3. Jumper Wires
4. LED Light
Circuit Diagram
Project Snap
LED Light
--------
Anode --------- Pin 13 Cathode
-------- GND
Arduino Code
The following Arduino code is used to detect motion and control the LED light accordingly. This
code also allows the sensor to recalibrate every 5 seconds to detect new motion.
//the time we give the sensor to calibrate (10-60 secs according to the
datasheet) int calibrationTime = 5;
//the time when the sensor outputs a low impulse
long unsigned int lowIn;
int pirPin = 3; //the digital pin connected to the PIR sensor's output
int ledPin = 13;
/////////////////////////////
//SETUP
void setup(){ Serial.b
egin(9600); pinMode(pirPin,
INPUT); pinMode(ledPin,
OUTPUT);
digitalWrite(pirPin, LOW);
lockLow = false;
Serial.println("---");
Serial.print("motion detected at ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(50); }
takeLowTime = true;
}
• The code begins by defining the pins connected to the PIR sensor and the onboard LED.
• A calibration time of 5 seconds is set for the sensor to stabilize before it starts detecting
motion.
• In the setup function, the serial communication is initialized for debugging purposes, and
the PIR sensor pin is set as an input while the LED pin is set as an output. The PIR sensor
is also given time to calibrate.
• The loop function continuously reads the state of the PIR sensor. If motion is detected (the
sensor output is HIGH), a message is printed to the serial monitor, and the LED is turned
on. If no motion is detected (the sensor output is LOW), the LED is turned off. The code
also ensures that it waits for 5 seconds of no motion before assuming that motion has ended.
Conclusion
This project demonstrates how to interface a PIR Motion Sensor with an Arduino UNO to detect
motion. The Arduino reads the sensor's output and responds by turning an LED on or off, making
it a useful setup for various applications such as security systems and automated lighting.
By following the steps outlined above, you can create a basic motion detection system and modify
the code or hardware setup to suit more complex requirements. This project serves as a
foundational example of using sensors with microcontrollers to create interactive and responsive
systems.