Step-by-Step Guide: Automating Watering System With Soil Moisture Sensors, Pump, Relay, and Mobile Alerts

by EkanshAgarwal01 in Circuits > Remote Control

24 Views, 0 Favorites, 0 Comments

Step-by-Step Guide: Automating Watering System With Soil Moisture Sensors, Pump, Relay, and Mobile Alerts

arduino-automatic-irrigation-system-wiring-diagram.jpg

Maintaining the health of plants can be a challenging task, especially when it comes to ensuring they receive the right amount of water at the right time. An automated watering system is a practical and efficient solution for this. By combining soil moisture sensors, a water pump, a relay module, and mobile alerts, you can create a system that not only waters your plants based on their needs but also keeps you informed about their condition in real-time. This step-by-step guide will walk you through the process of building a smart watering system, helping you save time, conserve water, and keep your plants thriving, whether you’re at home or away.

Supplies

ebd7211b-7fbd-4337-b089-ee847def511f.jpg

Soil Moisture Sensor: Measures soil moisture level.

ESP32 Microcontroller: Processes data and sends alerts via Wi-Fi.

Relay Module: Controls the water pump based on sensor data.

Water Pump: Supplies water to plants.

Tubing and Drip Emitters: Delivers water to each plant.

Water Reservoir: Stores water for the system.

Power Supply: Powers the pump and ESP32.

Blynk App (or similar): Mobile app for monitoring plant health and receiving alerts.

Jumper Wires and Breadboard: For connections.

Wiring the Components

Soil Moisture Sensor to ESP32:

  1. A0 (Analog Output) → ESP32 GPIO36.
  2. VCC → 3.3V pin on ESP32.
  3. GND → GND pin on ESP32.

Relay to ESP32:

  1. IN (Signal) → ESP32 GPIO25.
  2. VCC → 3.3V pin on ESP32.
  3. GND → GND pin on ESP32.
  4. NO (Normally Open) and COM (Common) → Connect to the water pump circuit.

Water Pump:

  1. Connect pump power supply to the relay’s NO and COM terminals.

Tubing and Drip Emitters:

  1. Arrange tubing around plants and install drip emitters at the base of each plant.

Setting Up the Mobile App

  1. Install Blynk App:
  2. Download Blynk App on your smartphone.
  3. Create a project and note the auth token.
  4. Configure Widgets:
  5. Add a Gauge Widget for soil moisture level.
  6. Add a Notification Widget for alerts.
  7. Add a Button Widget to manually control watering.

Programming the ESP32

#define BLYNK_TEMPLATE_ID "Your_Template_ID"
#define BLYNK_DEVICE_NAME "Your_Device_Name"
#define BLYNK_AUTH_TOKEN "Your_Auth_Token"

#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

#define MOISTURE_PIN 36 // GPIO pin for soil moisture sensor
#define RELAY_PIN 25 // GPIO pin for relay control
#define PUMP_THRESHOLD 40 // Moisture threshold to activate pump (0-100 scale)

// WiFi credentials
char ssid[] = "Your_SSID";
char pass[] = "Your_Password";

BlynkTimer timer;

void setup() {
Serial.begin(115200);

// Initialize Blynk
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

// Initialize relay and sensor
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW); // Start with pump off

// Schedule regular updates
timer.setInterval(2000L, checkSoilMoisture);
}

void checkSoilMoisture() {
int moistureValue = analogRead(MOISTURE_PIN); // Read sensor
int moisturePercentage = map(moistureValue, 0, 4095, 100, 0); // Convert to %

Serial.print("Soil Moisture: ");
Serial.print(moisturePercentage);
Serial.println("%");

Blynk.virtualWrite(V1, moisturePercentage); // Update app gauge

if (moisturePercentage < PUMP_THRESHOLD) {
digitalWrite(RELAY_PIN, HIGH); // Turn on pump
Serial.println("Pump ON: Watering plants...");
Blynk.notify("Soil is dry! Watering plants.");
delay(5000); // Run pump for 5 seconds
digitalWrite(RELAY_PIN, LOW); // Turn off pump
Serial.println("Pump OFF");
} else {
Serial.println("Soil is moist, no watering needed.");
}
}

void loop() {
Blynk.run();
timer.run();
}


Deploying the System

Upload Code:

  1. Connect ESP32 to your computer and upload the code using Arduino IDE.

Test the System:

  1. Insert the soil moisture sensor into the soil.
  2. Check the soil moisture readings in the Blynk app.
  3. Ensure the pump activates when the soil is dry and deactivates when moist.

Monitoring and Alerts

Real-Time Monitoring:

  1. View soil moisture levels in the app.
  2. Manually trigger watering using the button widget in Blynk.

Automatic Alerts:

  1. Receive notifications when the soil is too dry or the pump is activated.

Integrating With Solar Power

Power Supply:

  1. Connect the water pump and ESP32 to the solar-powered battery pack.

Backup Power:

  1. Use a small UPS or secondary battery to ensure uninterrupted operation.