/*
PIR sensor tester
*/
#include <LiquidCrystal_I2C.h>
//int ledPin = 13; // choose the pin for the LED
//int buzzer = 12;
int buzzer = 12;
int inputPin = 13; // choose the input pin (for PIR sensor)
int pirState = HIGH; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
// pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
lcd.init();
lcd.backlight();
// Print something
}
void loop() {
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
// digitalWrite(ledPin, HIGH); // turn LED ON
digitalWrite(buzzer, HIGH);
if (pirState == HIGH) {
// we have just turned on, YOU NEED TO TEKAN BUTTON
Serial.println("Water detected!");
// We only want to print on the output change, not state
pirState = LOW;
lcd.setCursor(0,0);
lcd.print("Water Level");
lcd.setCursor(0,1);
lcd.print("DETECTED");
}
} else {
// digitalWrite(ledPin, LOW); // turn LED OFF
digitalWrite(buzzer, LOW);
if (pirState == LOW) {
// we have just turned of
Serial.println("Water not detected!");
// We only want to print on the output change, not state
pirState = HIGH;
lcd.setCursor(0,0);
lcd.print("Water Level");
lcd.setCursor(0,1);
lcd.print("NOT DETECTED");
}
}
}