#include <LiquidCrystal_I2C.h> // Including the LiquidCrystal_I2C library
LiquidCrystal_I2C lcd(0x27, 16, 2); // Initializing the LCD screen with I2C address, 16 columns, and 2 rows
void setup() {
lcd.init(); // Initializing the LCD screen
lcd.backlight(); // Turning on the LCD backlight
lcd.setCursor(0, 0); // Setting the cursor position to column 0, row 0
lcd.print("HW-038 Sensor"); // Displaying the text "HW-038 Sensor"
delay(3000); // Waiting for 3 seconds
lcd.clear(); // Clearing the LCD screen
}
void loop() {
int value = analogRead(A0); // Reading the analog value from pin A0
lcd.setCursor(0, 0); // Setting the cursor position to column 0, row 0
lcd.print("Value :"); // Displaying the text "Value :"
lcd.print(value); // Displaying the read value
lcd.print(" "); // Displaying empty spaces to clear previous characters
lcd.setCursor(0, 1); // Setting the cursor position to column 0, row 1
lcd.print("Level :"); // Displaying the text "Level :"
if (value < 10) {
lcd.print("No water "); // Displaying the text "No water"
}
else if (value >= 100 && value < 630) {
lcd.print("Low "); // Displaying the text "Low"
}
else if (value >= 630 && value < 670) {
lcd.print("Medium "); // Displaying the text "Medium"
}
else if (value >= 670)
{
lcd.print("High "); // Displaying the text "High"
}
}