MOTION DETECTION USING PIR SENSOR AND BHARAT PI

by bharatpi in Circuits > Electronics

395 Views, 0 Favorites, 0 Comments

MOTION DETECTION USING PIR SENSOR AND BHARAT PI

WhatsApp Image 2023-06-22 at 20.30.51.jpg
61VoC1mAJfL._SL1500_.jpg
aaaaaaaa.jpg

·      This project uses the PIR motion sensor and Bharat Pi to detect moving living objects.

·      It allows us to detect the presence of people, and animals when they are within the range of the sensor.


Supplies

247488209-2de0aa2c-7df7-481e-a941-b4c3681b5366.png
Untitled Diagram.jpg

Hardware components

Below is the given list of all the hardware components that are required for this project:

·      Bharat Pi Board (You can buy Bharat Pi board from Amazon)

·      PIR Sensor

·      Jumper Wire

·      LED   

Software apps and online services

We are going to use Arduino IDE for programming the Bharat Pi. The Bharat Pi can be connected using a USB Type-C connector. Serial drivers are required to be installed for the detection of Bharat Pi. You can download the serial drivers from this depending on the operating system.

·      Arduino IDE

·      CH341 serial drivers for Bharat Pi

Story

images.jpeg
71nD-O7XWUL._SL1500_.jpg

·    PIR Sensor

  PIR is a short form for Passive Infrared sensor – an electronic sensor which can detect levels of infrared radiation from objects in its field of view.

·      When a warm body like a human or animal passes by, it first intercepts one-half of the PIR sensor, which causes a positive differential change between the two halves.

·      When the warm body leaves the sensing area, the reverse happens, whereby the sensor generates a negative differential change. These change pulses are what is detected.

·      PIR sensors are more complicated than many other sensors explained because multiple variables affect the sensor's input and output.

·      The PIR sensor has two slots in it, each slot is made of a special material that is sensitive to IR.

·      When the sensor is idle, both slots detect the same amount of IR.

BHARAT PI

·      In this project, we are using Bharat Pi which has both an ESP32 microcontroller and a SimCom A7672S 4G/LTE module.

·      Bharat Pi is an IoT prototyping board for students, innovators, startups, and developers. A simplified board with an all-in-one compute, network and storage on a single board to build rapid prototypes.

·      Bharat Pi bundles the power of ESP32, 4G/LTE module in an Arduino form factor. This makes Bharat Pi compatible with all Arduino and ESP32 programs and shields.

·      Wireless monitoring can be done using Wi-Fi or with a Sim based 4G/LTE connectivity.

·      Bharat Pi is a rugged board with good quality and could be used even for production and live customer deployments!



Circuitry

2023-06-28 (1).png

·      The circuit for this project is really simple and you only need to assemble it on a board using some jumper wires to test it.

·      It mainly consists of a PIR sensor connected to our main processor, the ESP32-WROOM -32F.

·      The PIR sensor consists of a pyroelectric element which generates a signal when exposed to heat or temperature variation.

·      It contains a special lens called Fresnel lens which sets the range and sensitivity of the sensor. It helps in converging the detected infrared signals to the pyroelectric element. To make the signal usable by the appliances, it must be amplified to a dc level of at least 5v which is done using a 2-stage amplifier and a comparator circuit.


Code Snippet

2023-06-28 (2).png
int led = 32;                // the pin that the LED is attached to
int sensor = 23;             // the pin that the sensor is attached to
int state = HIGH;            // by default, no motion detected
int val = 0;                 // variable to store the sensor status (value)
int motionCounter = 0;       // variable to count the number of motions detected


void setup() {
  pinMode(led, OUTPUT);      // initialize LED as an output
  pinMode(sensor, INPUT);    // initialize sensor as an input
  Serial.begin(115200);      // initialize serial
}


void loop() {
  val = digitalRead(sensor);   // read sensor value
  Serial.print("Sensor value: ");
  Serial.println(val);         // print sensor value for debugging
 
  if (val == HIGH) {           // check if the sensor is HIGH
    digitalWrite(led, HIGH);   // turn LED ON
    delay(100);                // delay 100 milliseconds


    if (state == LOW) {
      motionCounter++;         // increment motion counter
      Serial.print("Motion detected! Count: ");
      Serial.println(motionCounter);
      state = HIGH;            // update variable state to HIGH
    }
  }
  else {
    digitalWrite(led, LOW);    // turn LED OFF
    delay(200);                // delay 200 milliseconds


    if (state == HIGH) {
      Serial.println("Motion stopped!");
      state = LOW;             // update variable state to LOW
    }
  }
}


Downloads

Application

PIR sensor can be used for a wide range of real-life applications. Some of the examples are as listed below:

·      Security use case: Alert or raise an alarm based on a human moment.

·      Automatic door opening upon human arrival.

·      Automatic lighting controls to help reduce power consumption.

·      Vending machines for automated dispensing based on a gesture.

·      Lift lobbies, count people entering malls, events, public place etc.

·      Wireless remotely monitoring for secured assets.