This circuit is designed to monitor soil moisture levels and automatically water a plant when the soil is dry. It uses an Arduino UNO microcontroller to read data from a moisture sensor and control a water pump via a relay. An I2C LCD screen is used to display the moisture level and the status of the watering process.
Arduino UNO
Humidity YL-69
1-Channel Relay (5V 10A)
I2C LCD 16x2 Screen
Mini Water Pump
5V Adapter
Adafruit JTAG 2x10 to SWD 2x5
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD with I2C address 0x27 and 16x2 dimensions
LiquidCrystal_I2C lcd(0x27, 16, 2);
int moisturePin = A0; // Moisture sensor connected to A0
int relayPin = 7; // Relay signal connected to digital pin 7
int moistureValue = 0; // Variable to store moisture sensor value
int threshold = 500; // Moisture level threshold (adjust as needed)
void setup() {
// Initialize the LCD
lcd.begin();
lcd.backlight();
// Initialize the relay pin as an output
pinMode(relayPin, OUTPUT);
// Ensure the relay is off initially
digitalWrite(relayPin, HIGH); // Relay is LOW-active, so HIGH means OFF
// Begin serial communication for debugging (optional)
Serial.begin(9600);
// Welcome message on the LCD
lcd.setCursor(0, 0);
lcd.print("Plant Monitor");
delay(2000);
lcd.clear();
}
void loop() {
// Read moisture sensor value (analog)
moistureValue = analogRead(moisturePin);
// Display moisture level on the LCD
lcd.setCursor(0, 0);
lcd.print("Moisture: ");
lcd.print(moistureValue);
// Determine if soil is dry or wet
if (moistureValue < threshold) {
// Soil is dry, activate the water pump
digitalWrite(relayPin, LOW); // Turn ON the pump (relay is LOW-active)
lcd.setCursor(0, 1);
lcd.print("Watering Plant");
} else {
// Soil is wet, turn off the pump
digitalWrite(relayPin, HIGH); // Turn OFF the pump
lcd.setCursor(0, 1);
lcd.print("Soil is Moist ");
}
// Optional: print sensor values to Serial Monitor for debugging
Serial.print("Moisture: ");
Serial.println(moistureValue);
// Small delay before next reading
delay(1000);
}
This code initializes the LCD and sets up the relay and moisture sensor. In the loop
function, it reads the moisture sensor value, displays it on the LCD, and controls the water pump based on the moisture level. The pump is activated when the soil is dry and deactivated when the soil is moist.