#include <OneWire.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define waterValve 5
#define oilValve 6
#define wled 4
#define oled 3
#define buzzer 2
const int threshold =250;
String notification;
void setup()
{
Serial.begin(9600);
lcd.init();
lcd.backlight();
welcomeDisplay();
for(uint8_t i=2;i<=6;i++)
{
pinMode(i,OUTPUT);
digitalWrite(i,LOW);
}
alert(3);
}
void loop()
{
home_display(notification);
if(analogRead(0) >= threshold)
{
digitalWrite(waterValve,HIGH);
digitalWrite(oilValve,LOW);
digitalWrite(wled,HIGH);
digitalWrite(oled,LOW);
notification ="WATER DETECTED";
}
else
{
digitalWrite(waterValve,LOW);
digitalWrite(oilValve,HIGH);
digitalWrite(oled,HIGH);
digitalWrite(wled,LOW);
notification ="OIL DETECTED";
}
delay(500);
}
void welcomeDisplay()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("OIL WATER VALVES");
lcd.setCursor(0,1);
lcd.print(" AUTOMATION ");
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("INITIALIZING SYS");
lcd.setCursor(0,1);
lcd.print("PLEASE WAIT ....");
}
void home_display(String TEXT)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("AUTOMATIC VALVES");
lcd.setCursor(0,1);
lcd.print(TEXT);
}
void alert(uint8_t num)
{
for(uint8_t i=0;i<num;i++)
{
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer,LOW);
delay(500);
}
}