Arduino UNO Based Soil Moisture Monitoring and Water Pump Control System
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to monitor soil moisture levels and control a water pump accordingly. It uses an Arduino UNO as the central microcontroller to read data from a soil moisture sensor (YL-69 Sonda) through an LM393 comparator module (YL-83 Module LM393). The system drives a relay module (KY-019 Relay module 1 channel) to turn a water pump on or off based on the moisture level. Additionally, an I2C LCD screen (16x2) displays the status of the soil moisture and the state of the water pump. The circuit is powered by a 9V battery.
Component List
Arduino UNO
- Microcontroller board based on the ATmega328P
- Provides I/O pins and power for the circuit
KY-019 Relay module 1 channel
- A single-channel relay module for controlling high power devices
- Acts as a switch for the water pump
YL-69 Sonda
- A soil moisture sensor probe
- Detects the moisture level in the soil
YL-83 Module LM393
- A comparator module that interfaces with the YL-69 Sonda
- Outputs a digital signal representing the soil moisture level
I2C LCD 16x2 Screen
- An alphanumeric LCD display with I2C interface
- Displays the soil moisture status and water pump state
Water Pump
- A device that moves water through the system
- Controlled by the relay module
9V Battery
- Provides power to the circuit
Wiring Details
Arduino UNO
GNDconnected to the ground of the circuit5Vprovides power to other componentsA0reads the analog output from the YL-83 Module LM393A4 (SDA)connected to the SDA pin of the I2C LCD ScreenA5 (SCL)connected to the SCL pin of the I2C LCD ScreenD7controls the relay module
KY-019 Relay module 1 channel
Ssignal pin connected toD7on the Arduino UNO5VandGNDconnected to the 5V and ground of the circuitCOMconnected to the positive terminal of the 9V BatteryNOnormally open contact connected to the positive terminal of the water pump
YL-69 Sonda
+and-connected to the corresponding+and-pins on the YL-83 Module LM393
YL-83 Module LM393
A0connected toA0on the Arduino UNOGNDandVCCconnected to the ground and 5V of the circuit+and-connected to the corresponding pins on the YL-69 Sonda
I2C LCD 16x2 Screen
SDAconnected toA4 (SDA)on the Arduino UNOSCLconnected toA5 (SCL)on the Arduino UNOVCC (5V)andGNDconnected to the 5V and ground of the circuit
Water Pump
positiveterminal connected to theNOcontact of the relay modulenegativeterminal connected to the negative terminal of the 9V Battery
9V Battery
+connected to theCOMcontact of the relay module-connected to the negative terminal of the water pump
Documented Code
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int sensor_pin = A0;
int relay_pin = 7;
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
lcd.backlight();
lcd.setBacklight(HIGH);
pinMode(sensor_pin,INPUT);
pinMode(relay_pin,OUTPUT);
}
void loop() {
int sensor_data = analogRead(sensor_pin);
Serial.print("Sensor_data: ");
Serial.print(sensor_data);
Serial.print("\t | ");
if(sensor_data > 950){
Serial.print("No Moisture, Soil is Dry");
digitalWrite(relay_pin, HIGH);
lcd.setCursor(0,0);
lcd.print("Soil is Dry");
lcd.setCursor(0,1);
lcd.print("Motor On");
}
else if(sensor_data >= 400 && sensor_data <=950){
Serial.print("There is Some Moisture, Soil is Stable");
digitalWrite(relay_pin, LOW);
lcd.setCursor(0,0);
lcd.print("Soil is Stable");
lcd.setCursor(0,1);
lcd.print("Motor Off");
}
else if(sensor_data < 400){
Serial.print("Soil is Wet");
digitalWrite(relay_pin, LOW);
lcd.setCursor(0,0);
lcd.print("Soil is Wet");
lcd.setCursor(0,1);
lcd.print("Motor Off");
}
delay(100);
}
This code is designed to run on the Arduino UNO. It initializes the LCD screen and sets up the sensor and relay pins. In the main loop, it reads the moisture level from the sensor and prints the value to the serial monitor. Depending on the moisture level, it controls the relay to turn the water pump on or off and updates the LCD display with the current soil status and pump state.