Automated Irrigation System with Sensors and Relays
Table of Contents🔗
- Introduction
- Components Required
- System Design and Working Principle
- Sensor-to-Relay Wiring Guide
- Arduino Code Implementation
- Testing, Calibration, and Optimization
- Scaling for Agricultural Use
- Safety and Efficiency Best Practices
- Conclusion
Introduction🔗
Automated irrigation systems transform plant care by ensuring watering occurs only when needed, preventing water waste and maintaining plant health. This project combines soil moisture sensors with relay-controlled pumps to automate watering based on real-time soil conditions. Learn to build a closed-loop control system that integrates sensors, microcontrollers, and actuators-a foundational concept in IoT and automation.
Components Required🔗
Core Components
Component | Purpose | Key Specs |
---|---|---|
Arduino Uno | System brain | ATmega328P, 14 I/O pins |
Capacitive Soil Sensor | Measure soil humidity | Analog output (0-1023), 3.3-5V |
5V Relay Module | Control water pump | 10A @ 250VAC, optocoupler isolation |
12V Submersible Pump | Water delivery | 1.2L/min flow rate, 2m head |
Diode (1N4007) | Back-EMF protection | 1A, 1000V reverse voltage |
BC547 Transistor | Relay driver | 45V, 100mA |
Resistors | Signal conditioning | 10kΩ (pull-down), 220Ω (base) |
Optional Components
- LCD Display: Visualize moisture levels and system status.
- Water Flow Meter: Track water usage (e.g., YF-S201 hall effect sensor).
- Wi-Fi Module: Enable remote monitoring (e.g., ESP8266).
System Design and Working Principle🔗
The system uses closed-loop feedback control:
1. Moisture Measurement:
The capacitive sensor measures volumetric water content via dielectric permittivity (no electrolysis degradation).2. Decision Logic:
Arduino compares readings against two thresholds:- Dry Threshold:
analogRead() ≤ 400
(parched soil) - Wet Threshold:
analogRead() ≥ 800
(saturated soil)
3. Relay Activation:
The relay engages the pump when moisture drops below the dry threshold and disengages at the wet threshold. Advanced Optimization:// Hysteresis prevents relay chatter
if (moisture < DRY_THRESHOLD && !pumpActive) {
activatePump();
} else if (moisture > WET_THRESHOLD && pumpActive) {
deactivatePump();
}
Sensor-to-Relay Wiring Guide🔗
Critical Connections
1. Soil Sensor:
- VCC → 5V
- GND → GND
- SIG → A0 (add 100nF capacitor to reduce noise)
2. Relay Module:
- IN → D8 via BC547 transistor (to handle 20mA coil current)
- Flyback diode across relay coil for voltage spike suppression.
3. Pump:
- Connect to relay's NO (Normally Open) terminal.
Arduino Code Implementation🔗
Advanced Code with Hysteresis
const int sensorPin = A0;
const int relayPin = 8;
int moisture = 0;
bool pumpActive = false;
// Calibrate per soil type
#define DRY_THRESHOLD 400
#define WET_THRESHOLD 800
void setup() {
Serial.begin(9600);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH); // Relay OFF initially
}
void loop() {
moisture = analogRead(sensorPin);
Serial.print("Moisture: ");
Serial.println(moisture);
if (moisture <= DRY_THRESHOLD && !pumpActive) {
digitalWrite(relayPin, LOW); // Relay ON
pumpActive = true;
Serial.println("Pump ACTIVATED");
}
else if (moisture >= WET_THRESHOLD && pumpActive) {
digitalWrite(relayPin, HIGH); // Relay OFF
pumpActive = false;
Serial.println("Pump DEACTIVATED");
}
delay(2000); // Prevent rapid cycling
}
Simplified Single-Threshold Alternative
const int sensorPin = A0;
const int relayPin = 8;
const int moistureThreshold = 600;
void setup() {
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // Pump OFF initially
}
void loop() {
int sensorValue = analogRead(sensorPin);
if (sensorValue > moistureThreshold) {
digitalWrite(relayPin, HIGH); // Pump ON
} else {
digitalWrite(relayPin, LOW); // Pump OFF
}
delay(2000);
}
Testing, Calibration, and Optimization🔗
Calibration Protocol
1. Dry Calibration:
- Insert sensor in dry soil. Record analog value as
DRY_THRESHOLD
.
2. Wet Calibration:
- Submerge sensor in water (avoiding electrodes). Record as
WET_THRESHOLD
.
Troubleshooting Table
Issue | Solution |
---|---|
Pump doesn’t start | Test relay with 5V directly |
Erratic sensor values | Check wiring, apply conformal coating |
Relay chattering | Increase delay, add hysteresis |
Optimization Tips
- Data Logging: Add an RTC module to track watering schedules.
- Remote Monitoring: Use ESP8266 with Blynk:
Blynk.virtualWrite(V1, moisture); // Push to dashboard
- Energy Savings: Implement sleep mode:
#include <LowPower.h>
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
Scaling for Agricultural Use🔗
Industrial Modifications:- Multi-Zone Control: Use Arduino Mega with 8 relays/sensors.
- Water Flow Tracking: Integrate YF-S201 sensor:
volatile int pulseCount;
void pulseCounter() { pulseCount++; }
attachInterrupt(digitalPinToInterrupt(2), pulseCounter, FALLING);
Safety and Efficiency Best Practices🔗
1. Waterproofing: Pot sensor electronics in epoxy resin.
2. Power Isolation: Use separate 12V supply for the pump.
3. Maintenance: Weekly sensor validation with gravimetric soil tests.
Conclusion🔗
This automated irrigation system demonstrates the power of closed-loop control in real-world applications. By integrating sensors, microcontrollers, and relays, you can create a water-efficient solution adaptable to home gardens or agricultural fields. Experiment with thresholds, expand with IoT capabilities, and refine the design for your specific needs. Whether you're a hobbyist or a professional, this project offers valuable insights into electronics, programming, and sustainable technology.
Happy building! 🌱💧Author: Marcelo V. Souza - Engenheiro de Sistemas e Entusiasta em IoT e Desenvolvimento de Software, com foco em inovação tecnológica.
References🔗
- Adafruit Arduino Tutorials: learn.adafruit.com/category/arduino
- Arduino Forum: forum.arduino.cc
- Arduino IDE Official Website: arduino.cc
- Arduino Project Hub: create.arduino.cc/projecthub
- SparkFun Arduino Tutorials: learn.sparkfun.com/tutorials/tags/arduino