#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Define pin connections
#define RAIN_ANALOG 18
#define RAIN_DIGITAL 19
// Initialize the LCD with I2C address 0x27, 16 columns and 2 rows
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Set pin modes
pinMode(RAIN_ANALOG, INPUT);
pinMode(RAIN_DIGITAL, INPUT);
analogReadResolution(10);
// Initialize Serial communication
Serial.begin(9600);
// Initialize the LCD
lcd.init();
lcd.backlight(); // Turn on the LCD backlight
}
void loop() {
// Read the rain amount from the analog pin
int rainAmount = analogRead(RAIN_ANALOG);
// Print rain amount to Serial Monitor
Serial.print("Rain amount: ");
Serial.println(rainAmount);
// Clear the LCD and display the information
lcd.clear();
lcd.setCursor(0, 0); // Set cursor to the first line
lcd.print("Rain amount: ");
lcd.print(rainAmount); // Display the rain amount
// Check if it's raining and display the message
if (digitalRead(RAIN_DIGITAL)) {
Serial.println("It's raining!");
lcd.setCursor(0, 1); // Set cursor to the second line
lcd.print("It's raining!");
} else {
lcd.setCursor(0, 1); // Set cursor to the second line
lcd.print("No rain.");
}
delay(1000); // Delay for readability
}