#include <Servo.h>
#include <MagicPot.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
MagicPot pot(A0);
Servo h2o;
int val = 0, dryVal = 400, airVal = 600, flow = 90, noFlow = 180;
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.backlight();
h2o.attach(11);
pot.begin();
h2o.write(noFlow);
}
void loop() {
// put your main code here, to run repeatedly:
while (millis() % 1000 == 0) {
delay(1);
pot.read();
val = pot.getValue();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Dryness: ");
lcd.setCursor(9,0);
lcd.print(val);
if (val >= dryVal && val < airVal) {
lcd.setCursor(0, 1);
lcd.print("Low Moisture");
h2o.write(flow);
}
else if (val >= airVal) {
lcd.setCursor(0, 1);
lcd.print("Air Detected");
h2o.write(noFlow);
}
else {
lcd.setCursor(0, 1);
lcd.print("Enough Moisture");
h2o.write(noFlow);
}
}
}