Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions arduino_home_security_with_pir_sensor_and_lcd_display1.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// source https://www.arduino.cc/en/Tutorial/LiquidCrystalAutoscroll

// library for the LCD display:
// source http://www.instructables.com/id/Home-Security-Alarm-or-a-Motion-Detector-Using-Ard/
// Source photo cell https://learn.adafruit.com/photocells/using-a-photocell

// library for the LCD display:
#include <LiquidCrystal.h>

int ledPin = 11;
int PIRpin = 8;
int pirState = LOW;
int val = 0;
// photocell circuit
int photocellPin = A0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the sensor divider

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);


void setup() {

pinMode(ledPin, OUTPUT);
pinMode(PIRpin, INPUT);
pinMode(photocellPin, INPUT);

Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(2, 0); // Set LCD cursor position (column, row)
lcd.print("P.I.R Motion "); // Print text to LCD
lcd.setCursor(0, 1); // Set LCD cursor position (column,row)
lcd.print("and Light Sensors"); // Print text to LCD
delay(2000); // wait 2s // Delay to read text

delay(2000); // Delay to read text
lcd.clear(); // Clear LCD
lcd.setCursor(0, 0);
lcd.print("Processing Data.");
delay(3000);
lcd.clear();
lcd.setCursor(3, 0); // Set LCD cursor position (column 0, row 0)
lcd.print("No Motion ");
lcd.setCursor(3, 1);
lcd.print("Waiting !");

}

void loop(){
val = digitalRead(PIRpin);
photocellReading = analogRead(photocellPin);

if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
delay(150);

if (pirState == LOW) {
Serial.println("Motion detected!");
lcd.clear() ;
lcd.setCursor(0, 0); // Set LCD cursor position (column 0, row 0)
lcd.print("Motion Detected!");
lcd.setCursor(0, 1); // Set LCD cursor position (column 0, row 1)
lcd.print(photocellReading);
// We only want to print on the output change, not state
pirState = HIGH;
delay(5000) ;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF

// display no motion screen saver
scrollScreenSaver() ;
if (pirState == HIGH){
// There's no motion !

// change to no motion detected
pirState = LOW;
}
}
}

void scrollScreenSaver() {

// autoscroll https://www.arduino.cc/en/Tutorial/LiquidCrystalAutoscroll
lcd.clear() ;
lcd.setCursor(15, 0); // Set LCD cursor position (column 0, row 0)
lcd.print("No Motion ");
lcd.setCursor(15, 1);
lcd.print("Waiting !");
// scroll 7 positions (display length - string length) to the left
// to move it back to center:

for (int positionCounter = 0; positionCounter < 22; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(150);

}
}