Motion detection using PIR sensor and Bharat Pi

PIR SENSOR - MOTION DETECTIO

Supplies:

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.

Story:

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 reverse polarity protection diode and could be used even for production and live customer deployments!

Circuitry:

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 main board Bharat Pi.
  • The 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 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:

int led = 32;                // the pin that the LED is atteched to
int sensor = 23;              // the pin that the sensor is atteched to
int state = HIGH;             // by default, no motion detected
int val = 0;                 // variable to store the sensor status (value)

void setup() {
  pinMode(led, OUTPUT);      // initalize 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
  if (val == HIGH) {           // check if the sensor is HIGH
    digitalWrite(led, HIGH);   // turn LED ON
    delay(100);                // delay 100 milliseconds 
    
    if (state == LOW) {
      Serial.println("Motion detected!"); 
      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
    }
  }
}

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.

Leave a Reply

Your email address will not be published. Required fields are marked *