Motion Detector with Arduino and PIR sensor

Introduction

In this tutorial, we are going to make a Motion Detector with Arduino and PIR sensor, we will understand the capabilities of the PIR sensor and its seamless integration with Arduino for detecting motion. From security systems to home automation, the PIR sensor opens up a realm of exciting applications. Let’s embark on the fascinating journey of motion detection with Arduino and the versatile PIR sensor.

Hardware Required

You will require the following Hardware Components for interfacing the PIR Motion Sensor with Arduino.

Components#Buy From Amazon
Arduino UNO1Buy Link
PIR Motion Sensor1Buy Link
9v DC Adapter (Optional)1Buy Link
Jumper Wires3Buy Link
Breadboard1Buy Link

What is a PIR Motion Sensor?

Passive Infrared (PIR) sensors are motion detection devices. They are cheap, small, low-powered, and easy to use. For this reason, they are frequently used in toys, home automation applications, or security systems.

PIR sensors are based on the measurement of infrared radiation. All bodies (living or not) emit a certain amount of infrared energy, the greater the higher its temperature. PIR devices have a pyroelectric sensor capable of capturing this radiation and converting it into an electrical signal.

Actually, each sensor is divided into two fields and there is an electrical circuit that compensates for both measurements. If both fields receive the same amount of infrared, the resulting electrical signal is zero. Conversely, if the two fields make a different measurement, an electrical signal is generated.

In this way, if an object crosses one of the fields, a differential electrical signal is generated, which is captured by the sensor, and a digital signal is emitted.

pir-motion-sensor-working

The other remaining element for everything to work is the optics of the sensor. It is basically a plastic dome formed by fresnel lenses, which divides the space into zones, and focuses the infrared radiation to each of the PIR fields.

In this way, each of the sensors captures an average of the infrared radiation from the environment. When an object enters the range of the sensor, one of the areas marked by the optics will receive a different amount of radiation, which will be captured by one of the PIR sensor fields, triggering the alarm.

working-of-pir-motion-sensor

Circuit Diagram

The following circuit shows you the connection of the Motion Detector with Arduino and PIR sensor Please make the connection carefully

Motion-detector-with-Arduino-and-PIR-sensor-circuit-diagram

Circuit Connections

ArduinoPIR Motion Sensor
+5VVCC Pin
GNDGND Pin
D2OUT

Installing Arduino IDE Software

First, you will require to Download the updated version of Arduino IDE Software and Install it on your PC or laptop. if you Learn How to install the Arduino step-by-step guide then click on how to install Arduino Button given Blow

Code Samples

The code needed to perform the reading is simple. We simply read the PIR output, and blink the LED while the signal is active.

//For more Projects: www.arduinocircuit.com

const int LEDPin= 13;
const int PIRPin= 2;

void setup()
{
  pinMode(LEDPin, OUTPUT);
  pinMode(PIRPin, INPUT);
}

void loop()
{
  int value= digitalRead(PIRPin);
 
  if (value == HIGH)
  {
    digitalWrite(LEDPin, HIGH);
    delay(50);
    digitalWrite(LEDPin, LOW);
    delay(50);
  }
  else
  {
    digitalWrite(LEDPin, LOW);
  }
}

If we wanted to execute an action only once when motion is detected, instead of the entire time the signal is active, we would use the following code.

//For more Projects: www.arduinocircuit.com


const int LEDPin = 13; // pin for the LED
const int PIRPin = 2; // input pin (for PIR sensor)

int pirState = LOW; // start no movement
int val = 0; // state of the pin

void setup()
{
pinMode(LEDPin, OUTPUT); 
  pinMode(PIRPin, INPUT);
  Serial.begin(9600);
}
void loop()
{
  val = digitalRead(PIRPin);
  if (val == HIGH)   //si está activado
  { 
    digitalWrite(LEDPin, HIGH);  //LED ON
    if (pirState == LOW)  //si previamente estaba apagado
    {
      Serial.println("Sensor activado");
      pirState = HIGH;
    }
  } 
  else   //si esta desactivado
  {
    digitalWrite(LEDPin, LOW); // LED OFF
    if (pirState == HIGH)  //si previamente estaba encendido
    {
      Serial.println("Sensor parado");
      pirState = LOW;
    }
  }
}

Applications

  1. Security Systems: The PIR sensor is widely used in security systems to detect intruders or unauthorized movements in homes, offices, or other premises. When integrated with Arduino.
  2. Automatic Lighting Control: In home automation projects, the PIR sensor is employed to control lighting automatically. When motion is detected, Arduino can activate lights.
  3. Occupancy Sensing: For energy conservation, the PIR sensor can be used in buildings and commercial spaces to detect occupancy. It helps in optimizing heating, ventilation, and air conditioning (HVAC) systems based on the number of occupants in a room.
  4. Wildlife Monitoring: In wildlife research and conservation, the PIR sensor is utilized to monitor animal movements and behavior. When combined with Arduino, it enables researchers to gather data on animal presence and activity in specific areas.

Leave a Comment


error: