Arduino-Based Automated Water Sprinkling System with Soil Moisture and Rain Detection
View and Edit Project In Cirkit Designer
Automated Water Sprinkling System Documentation
Summary
This document details the design and implementation of an automated water sprinkling system. The system uses an Arduino UNO microcontroller to manage a relay module that controls a water pump. A soil moisture sensor is used to detect soil moisture levels, and an I2C LCD is used to display system status. The system is designed to water plants automatically based on soil moisture levels and prevent watering during rain.
Component List
Arduino UNO
- Description: Microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
Relay module 5v-30v
- Description: Relay module used to control high voltage devices.
- Pins: common contact, normally open, normally closed, trigger, V-, V+
Water pump
- Description: Pump used to water plants.
- Pins: positive, negative
SparkFun Soil Moisture Sensor
- Description: Sensor used to measure soil moisture levels.
- Pins: VCC, GND, SIG
16x2 I2C LCD
- Description: LCD display with I2C interface.
- Pins: GND, VCC, SDA, SCL
LM393
- Description: Comparator module used for rain detection.
- Pins: A0, D0, GND, VCC
Wiring Details
Arduino UNO
5V connected to:
- Relay module 5v-30v (V+)
- 16x2 I2C LCD (VCC)
- LM393 (VCC)
GND connected to:
- Relay module 5v-30v (V-)
- LM393 (GND)
- 16x2 I2C LCD (GND)
SCL connected to:
- 16x2 I2C LCD (SCL)
SDA connected to:
- 16x2 I2C LCD (SDA)
D6 connected to:
- LM393 (D0)
D3 connected to:
- Relay module 5v-30v (trigger)
Relay module 5v-30v
V+ connected to:
- Arduino UNO (5V)
V- connected to:
- Arduino UNO (GND)
trigger connected to:
- Arduino UNO (D3)
common contact connected to:
- Water pump (negative)
normally open connected to:
- Water pump (positive)
Water pump
negative connected to:
- Relay module 5v-30v (common contact)
positive connected to:
- Relay module 5v-30v (normally open)
SparkFun Soil Moisture Sensor
GND connected to:
- LM393 (GND)
VCC connected to:
- LM393 (VCC)
16x2 I2C LCD
GND connected to:
- Arduino UNO (GND)
VCC connected to:
- Arduino UNO (5V)
SDA connected to:
- Arduino UNO (SDA)
SCL connected to:
- Arduino UNO (SCL)
LM393
GND connected to:
- Arduino UNO (GND)
- SparkFun Soil Moisture Sensor (GND)
VCC connected to:
- Arduino UNO (5V)
- SparkFun Soil Moisture Sensor (VCC)
D0 connected to:
- Arduino UNO (D6)
Code Documentation
/*
* Automated Water Sprinkling System
* This code manages an automated water sprinkling system based on time and
* soil moisture level detection. The system uses a relay to control a water
* pump, a soil moisture sensor to detect soil moisture levels, and a rain
* sensor to prevent watering during rain.
*/
const int relayPin = 3; // Relay module trigger pin
const int rainSensorPin = 6; // Rain sensor digital output pin
const int soilMoisturePin = A0; // Soil moisture sensor analog output pin
void setup() {
pinMode(relayPin, OUTPUT);
pinMode(rainSensorPin, INPUT);
Serial.begin(9600);
}
void loop() {
int soilMoistureValue = analogRead(soilMoisturePin);
int rainSensorValue = digitalRead(rainSensorPin);
Serial.print("Soil Moisture: ");
Serial.println(soilMoistureValue);
Serial.print("Rain Sensor: ");
Serial.println(rainSensorValue);
if (rainSensorValue == LOW && soilMoistureValue < 300) {
digitalWrite(relayPin, HIGH); // Turn on water pump
} else {
digitalWrite(relayPin, LOW); // Turn off water pump
}
delay(60000); // Wait for 1 minute before next check
}
This code initializes the pins for the relay, rain sensor, and soil moisture sensor. In the loop function, it reads the soil moisture and rain sensor values, prints them to the serial monitor, and controls the relay to turn the water pump on or off based on the sensor readings. The system checks the sensor values every minute.