#include <LiquidCrystal.h>
//code for motion detector circuit
const int ledPin= 13;
const int PIRPin= 8;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
// Include the message to show in msg
String msg = "Motion detected";
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a initial message to the LCD.
lcd.print("Hello human");
delay(2000);
pinMode(ledPin, OUTPUT);
pinMode(PIRPin, INPUT);
}
void loop() {
int value= digitalRead(PIRPin);
if (value == HIGH)
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
if (msg.length()>32){
for (int i = 0; i <= msg.length()+15; i++) {
lcd.clear();
if (i < 16) {
lcd.setCursor(16-i, 0);
lcd.print(msg.substring(0, i));
}
else {lcd.print(msg.substring(i-15, i+1));}
delay(100);
}
}
else{
lcd.setCursor(0, 0);
lcd.print(msg.substring(0, 16));
lcd.setCursor(0, 1);
lcd.print(msg.substring(16, 32));
}
}
else
{
digitalWrite(ledPin, LOW);
lcd.setCursor(0, 0);
lcd.print("Motion stopped");
}
}