#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "dht.h"
#include "customChars.h"
#define SOIL_PIN A0
#define RELAY_PIN 8
LiquidCrystal_I2C lcd(0x27,16,2);
void customChars(){
lcd.createChar(0, waterDropEmpt);
lcd.createChar(1, waterDropHalf);
lcd.createChar(2, waterDropFull);
lcd.createChar(3, thermometer);
}
void setup() {
Serial.begin(9600);
Wire.begin();
dht.begin();
lcd.init();
lcd.backlight();
customChars();
}
void loop() {
int16_t soilMoisture = analogRead(SOIL_PIN);
int8_t moisturePercentage = map(soilMoisture, 905, 420, 0, 100);
String msg = moisturePercentage < 20 ? "WET" : moisturePercentage > 75 ? "DRY" : "OK";
int8_t temperature = dht.readTemperature();
// debug
Serial.print("Sensor Value = ");
Serial.print(soilMoisture);
Serial.print("; Percentage = ");
Serial.println(moisturePercentage);
lcd.clear();
lcd.setCursor(0,0);
moisturePercentage < 20 ? lcd.write(byte(2)) : moisturePercentage > 75 ? lcd.write(byte(0)) : lcd.write(byte(1));
lcd.setCursor(2,0);
lcd.print("Soil: ");
lcd.print(msg);
lcd.setCursor(0,1);
lcd.write(byte(3));
lcd.print(" ");
lcd.print(temperature);
lcd.write(byte(223));
lcd.print("C");
delay(500);
}