#define pirPin 2
      int calibrationTime = 30;
      long unsigned int lowIn;
      long unsigned int pause = 5000;
      boolean lockLow = true;
      boolean takeLowTime;
      int PIRValue = 0;
      void setup() {
         Serial.begin(9600);
         pinMode(pirPin, INPUT);
      }
      void loop() {
         PIRSensor();
      }
      void PIRSensor() {
         if(digitalRead(pirPin) == HIGH) {
            if(lockLow) {
               PIRValue = 1;
               lockLow = false;
               Serial.println("Motion detected.");
               delay(50);
            }
            takeLowTime = true;
         }
         if(digitalRead(pirPin) == LOW) {
            if(takeLowTime){
               lowIn = millis();takeLowTime = false;
            }
            if(!lockLow && millis() - lowIn > pause) {
               PIRValue = 0;
               lockLow = true;
               Serial.println("Motion ended.");
               delay(50);
            }
         }
      }
      
      Cpp language logo

      Arduino - PIR Sensor

      0

      0

      avatar
      Sohail Gulam
      uno
      arduino

      PIR sensors allow you to sense motion. They are used to detect whether a human has moved in or out of the sensor’s range. They are commonly found in appliances and gadgets used at home or for businesses. They are often referred to as PIR, "Passive Infrared", "Pyroelectric", or "IR motion" sensors.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.