#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const int ledPin = 2; // LED pin
void setup()
{
Wire.begin(23, 22); // Initialize the I2C communication with SDA pin 23 and SCL pin 22.
Serial.begin(9600); /// Initialize the serial communication at a baud rate of 9600 bits per second.
lcd.init(); // initialize the lcd
lcd.backlight(); // turn on the backlight
pinMode(ledPin, OUTPUT);
}
void loop()
{
int16_t i = analogRead(34);
// Use the ternary operator to determine the status based on the value of 'i'.
// If 'i' is less than 20, set 'msg' to "low"; if 'i' is between 20 and 50, set 'msg' to "ok"; if 'i' is greater than 80, set 'msg' to "high".
String msg = (i < 20) ? "low" : (i > 80) ? "high" : "ok";
lcd.clear();
lcd.print("pH Level: ");
lcd.print(msg);
if(i<=300){
digitalWrite(ledPin, HIGH); // will turn on the LED(motor) if the soil is dry (i<300)
}
else {
digitalWrite(ledPin, LOW);
}
lcd.setCursor(0, 1); // Set cursor to the first column and second row
lcd.print("SensorValue:");
lcd.print(i);
delay(500);
}