#define redLed 5
#define greenLed 6
#define buzzer A1
#define button 2
#define rainSensor 0
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
unsigned int rain;
bool enable;
void setup()
{
lcd.init();
lcd.backlight();
bootingScreen();
pinMode(redLed,OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer,OUTPUT);
pinMode(button, INPUT_PULLUP);
enable=HIGH;
delay(2000);
}
void loop()
{
rain= map(analogRead(rainSensor),0,1024,0,100);
if(rain>50 & enable)
{
warning();
}
else
{
digitalWrite(greenLed,HIGH);
digitalWrite(redLed,LOW);
digitalWrite(buzzer,LOW);
homeScreen();
}
if(digitalRead(button)==LOW)
{
enable=!enable;
delay(1000);
}
}
void bootingScreen()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" RAIN DETECTOR ");
lcd.setCursor(0,1);
lcd.print("WARMING UP.....");
delay(1000);
}
void homeScreen()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" RAIN ALERT ");
lcd.setCursor(0,1);
lcd.print("RAIN LEVEL:");
lcd.setCursor(12,1);
lcd.print(rain);
lcd.setCursor(15,1);
lcd.print("%");
delay(500);
}
void warning()
{
digitalWrite(greenLed,LOW);
digitalWrite(redLed,HIGH);
digitalWrite(buzzer,HIGH);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" !!WARNING!! ");
lcd.setCursor(0,1);
lcd.print(" RAIN DETECTED ");
delay(1000);
}