ejshea
Published © GPL3+

PIR Sensor Integration

Detect movement up to 30' away which is useful in motion-activated projects such as a security system or automatic lighting in a classroom.

BeginnerFull instructions provided13,345
PIR Sensor Integration

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Final Circuit Schematic

Code

PIR Sensor Integration

Arduino
//Interface a PIR sensor to detect motion and display "Motion detected" or
//"No motion" depending on the output from the sensor

#include <LiquidCrystal.h>

//variable declarations
uint8_t readPIR = 0;
uint8_t nomotionflag = 0;
const int RS = 2, EN = 3, D4 = 4, D5 = 5, D6 = 6, D7 = 7;

LiquidCrystal lcd(RS,EN,D4,D5,D6,D7);   //set Uno pins that are connected to LCD, 4-bit mode

void setup() {
  lcd.begin(16,2);          //set 16 columns and 2 rows of 16x2 LCD
  pinMode(8, INPUT);        //output of PIR sensor (input to Uno)
  pinMode(9, OUTPUT);       //input to PIR sensor to enable (output of Uno)
  digitalWrite(9, HIGH);    //enable PIR sensor

}

void loop() {
  readPIR = digitalRead(8);   //check if motion detected
  
  if (readPIR == 1){          //motion detected
    nomotionflag = 0;         //reset flag
    lcd.home();
    lcd.print("Motion Detected");
    delay(500);
  }

  else{                         //no motion detected
    if (nomotionflag == 0){       
      lcd.clear();
      lcd.print("No motion");
      nomotionflag = 1;
    }
    
  }
  
}

Credits

ejshea

ejshea

16 projects • 30 followers

Comments