#define SENSOR 9
#define BUZZER 13
//Defines each pin as a word
#include <LiquidCrystal_I2C.h>
//Set to insure lots of code doesn't need to be included
LiquidCrystal_I2C lcd(0x27, 20, 4);
//Sets rows into different collums
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
pinMode(9, INPUT);
//lets the board know what pin is an input and output
lcd.init();
lcd.backlight();
//Lights up the screen so code is able to be seen
}
void loop()
{
// put your main code here, to run repeatedly:
int state = digitalRead(9);
if (state == HIGH)
//Tells board that motion is detected
{
digitalWrite(13, HIGH);
//informs that motion was detected so buzzer starts buzzing
tone(BUZZER, 100);
//allows board to know what tone the buzzer should be at
lcd.setCursor(0,0);
lcd.print("Motion has been");
lcd.setCursor(2,1);
lcd.print("detected");
//lets the board know what to right on screen
//and where to position text
delay(1000);
lcd.init();
//Erases text from screen
}
if (state == LOW)
//indetify motions not detected
{
digitalWrite(13, LOW);
//if motion not detected then buzzer doesn't go
noTone(BUZZER);
//Informs that buzzer shouldn't have a tone so it's not going
lcd.init();
}
}