fbpx

Interface PIR With Arduino Uno

Passive Infrared Sensor which uses the IR to detect the motion.

  • PIR are basically made of a pyroelectric sensor.
  • It detect an object has moved in or out of the sensor range.
  • The round metal with a rectangular crystal in the centre , which can detect level of infrared radiation.
  • The sensor in a motion detector is actually split in two halves.
  • When sensor is idle, both slots detect the same amount of IR.
  • When motion detected it first intercepts one half of the PIR sensor.
  • When the warm body leaves the sensing area, the reverse happens, whereby the sensor generates a negative differential change.
  • The PIR detects motion, the output pin will go “high” to 3.3V.

Application

  • SmartPhone.

Hardware Required

  • Pir Sensor.
  • Arduino.

Pinout

  • Vcc: +5v.
  • OutPut: 3.3v.
  • Gnd: Gnd.

Circuit

Code

 int calibrationTime = 30;
 long unsigned int lowIn;
 long unsigned int pause = 5000;
 boolean lockLow = true;
 boolean takeLowTime;
 int pirPin = 2;
 void setup()
 {
 Serial.begin(9600);
 pinMode(pirPin, INPUT);
 pinMode(13,OUTPUT);
 delay(1000);
 digitalWrite(pirPin, LOW);
 Serial.print("calibrating sensor ");
 for(int i = 0; i < calibrationTime; i++)
 {
 Serial.print(".");
 delay(1000);
 }
 Serial.println(" done");
 Serial.println("SENSOR ACTIVE");
 delay(50);
 }
 void loop()
 {
 if(digitalRead(pirPin) == HIGH)
 {
 if(lockLow)
 {
 lockLow = false;
 Serial.println("---");
 Serial.print("motion detected at ");
 Serial.print(millis()/1000);
 Serial.println(" sec");
 digitalWrite(13,HIGH);
 delay(50);
 }
 takeLowTime = true;
 }
 if(digitalRead(pirPin) == LOW)
 {
 if(takeLowTime)
 {
 lowIn = millis();
 takeLowTime = false;
 }
 if(!lockLow && millis() - lowIn > pause)
 {
 lockLow = true;
 Serial.print("motion ended at ");
 Serial.print((millis() - pause)/1000);
 Serial.println(" sec");
 digitalWrite(13,LOW);
 delay(50);
 }
 }
 } 

Leave a Reply

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