#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
int sensor = 5;
int lamp = 3;
int buzz = 6;
int val;
int stat;
const float BETA = 3950;
void setup() {
// put your setup code here, to run once:
pinMode(sensor, INPUT);
pinMode(lamp, OUTPUT);
pinMode(buzz, OUTPUT);
lcd.begin(16,2);
lcd.println("No Action Needed");
}
void loop() {
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
// put your main code here, to run repeatedly:
val=digitalRead(sensor);
if(val == 1){
digitalWrite(lamp, 1);
analogWrite(buzz, 1);
if(stat == 0){
lcd.clear();
lcd.setCursor(5, 0);
lcd.print("Alert!");
lcd.setCursor(0, 17);
lcd.print("Motion Detected!");
stat = 1;
}
} else{
analogWrite(buzz,0);
digitalWrite(lamp, 0);
delay(500);
if(stat == 1){
lcd.clear();
delay(100);
lcd.setCursor(0,0);
lcd.print("Motion Ended!");
delay(2000);
lcd.clear();
stat =0;
delay(100);
lcd.clear();
lcd.print("No Action Needed");
lcd.setCursor(0, 1);
lcd.print(":D");
}
}
}