Skip to content
cropped-image.webp

cropped-banner-promo-full-yellow.jpg

Connect with Us

  • Facebook
  • Twitter
  • Linkedin
  • VK
  • Youtube
  • Instagram
Primary Menu
  • Home
  • Blog
Light/Dark Button
Watch Video
  • Home
  • The Lab
  • ESP32 Smart Plant Watering System
  • The Lab

ESP32 Smart Plant Watering System

Friday February 19, 2026 (Last updated: February 20, 2026) 3 minutes read

Difficulty: Intermediate
Time Required: 2-3 hours
Cost: $15-25
ESP Board: ESP32

What You’ll Need

Component Approximate Cost Where to Buy
ESP32 Dev Board $5-8 Amazon
Capacitive Soil Sensor $3-5 Amazon
5V Water Pump $4-6 Amazon
5V Relay Module $2-4 Amazon
Jumper Wires $2 Amazon
Water Container $2-3 Local store

Circuit Diagram

ESP32 Pin Component Notes
3.3V Soil Sensor VCC Power
GND Soil Sensor GND Ground
GPIO 34 Soil Sensor OUT Analog read
5V Relay VCC Power
GND Relay GND Ground
GPIO 26 Relay IN Control pump

The Complete Code

/*********************************************************************
 * ESP32 Smart Plant Watering System
 * 
 * Monitors soil moisture and waters plants automatically
 * Hardware: ESP32, Capacitive Soil Sensor, 5V Pump, Relay
 *********************************************************************/

#include 
#include 

// ============== CONFIGURATION ==============
#define BLYNK_AUTH "YOUR_AUTH_TOKEN"

const char* wifi_ssid = "YOUR_WIFI";
const char* wifi_password = "YOUR_PASSWORD";

// ============== PINS ==============
#define SOIL_SENSOR_PIN 34    // ADC pin
#define PUMP_RELAY_PIN 26      // GPIO 26
#define MOISTURE_THRESHOLD 40  // Dry when below 40%

// ============== TIMING ==============
#define CHECK_INTERVAL 60000   // Check every 60 seconds
#define PUMP_DURATION 5000     // Water for 5 seconds
#define DRYING_PERIOD 3600000  // Wait 1 hour after watering

unsigned long lastCheck = 0;
unsigned long pumpStartTime = 0;
bool isWatering = false;
unsigned long dryingEndTime = 0;

// ============== SETUP ==============
void setup() {
  Serial.begin(115200);
  Serial.println(F("\n======================================"));
  Serial.println(F("Smart Plant Watering System Starting..."));
  Serial.println(F("======================================"));
  
  pinMode(SOIL_SENSOR_PIN, INPUT);
  pinMode(PUMP_RELAY_PIN, OUTPUT);
  digitalWrite(PUMP_RELAY_PIN, HIGH);  // Pump OFF
  
  analogReadResolution(12);
  
  connectToWiFi();
  Blynk.begin(BLYNK_AUTH, wifi_ssid, wifi_password);
  
  Serial.println(F("Setup complete!"));
}

// ============== MAIN LOOP ==============
void loop() {
  Blynk.run();
  
  if (millis() - lastCheck > CHECK_INTERVAL) {
    lastCheck = millis();
    checkMoisture();
  }
  
  // Check if watering period is over
  if (isWatering && millis() - pumpStartTime > PUMP_DURATION) {
    stopWatering();
  }
  
  // Check if drying period is over
  if (dryingEndTime > 0 && millis() > dryingEndTime) {
    dryingEndTime = 0;
    Serial.println(F("Drying period complete. Ready to check again."));
  }
}

// ============== FUNCTIONS ==============

void checkMoisture() {
  if (dryingEndTime > 0) {
    return;  // Still in drying period
  }
  
  int moisture = analogRead(SOIL_SENSOR_PIN);
  int moisturePercent = map(moisture, 0, 4095, 100, 0);
  
  Serial.print(F("Moisture: "));
  Serial.print(moisturePercent);
  Serial.print(F("% (Raw: "));
  Serial.print(moisture);
  Serial.println(F(")"));
  
  Blynk.virtualWrite(V0, moisturePercent);
  
  if (moisturePercent < MOISTURE_THRESHOLD && !isWatering) {
    Serial.println(F("Soil is dry! Starting pump..."));
    startWatering();
  }
}

void startWatering() {
  isWatering = true;
  pumpStartTime = millis();
  digitalWrite(PUMP_RELAY_PIN, LOW);  // Pump ON
  Blynk.virtualWrite(V1, 1);
  Serial.println(F("Pump ON"));
}

void stopWatering() {
  isWatering = false;
  digitalWrite(PUMP_RELAY_PIN, HIGH);  // Pump OFF
  dryingEndTime = millis() + DRYING_PERIOD;
  Blynk.virtualWrite(V1, 0);
  Serial.println(F("Pump OFF. Entering drying period..."));
}

void connectToWiFi() {
  Serial.print(F("Connecting to WiFi"));
  WiFi.begin(wifi_ssid, wifi_password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(F("."));
  }
  Serial.println(F(" Connected!"));
}

// ============== END OF CODE ==============

Troubleshooting

Problem Solution
Pump not starting Check relay wiring; relay is active LOW
Soil readings always 0 Check sensor connection; ensure VCC is 3.3V or 5V
Pump runs continuously Increase threshold or pump duration

Frequently Asked Questions

Q: How do I determine the threshold?

A: Read moisture when soil is dry and when wet. Set threshold between the two values.

Q: Can I use a 12V pump?

A: Use a relay rated for the pump voltage and a separate power supply.

About The Author

Friday

See author's posts

Post navigation

Previous: ESP32 Air Quality Monitor with MQ Sensors
Next: ESP8266 Motion Sensor Security System

Related Stories

  • The Lab

Raspberry Pi Pico vs ESP32: Which Should You Choose? 2026

Friday March 4, 2026
  • The Lab

ESP32-C3 vs ESP32-S3: Detailed Comparison 2026

Friday March 4, 2026
  • The Lab

STM32 vs ESP32: Battle of the Microcontrollers 2026

Friday March 3, 2026

Connect with Us

  • Facebook
  • Twitter
  • Linkedin
  • VK
  • Youtube
  • Instagram

Trending News

7 Best Shopify Alternatives for Dropshipping in 2026 1
  • Latest News

7 Best Shopify Alternatives for Dropshipping in 2026

Friday March 4, 2026
ESP32-C3 vs ESP32-S3: Detailed Comparison 2026 2
  • The Lab

ESP32-C3 vs ESP32-S3: Detailed Comparison 2026

Friday March 4, 2026
Raspberry Pi Pico vs ESP32: Which Should You Choose? 2026 3
  • The Lab

Raspberry Pi Pico vs ESP32: Which Should You Choose? 2026

Friday March 4, 2026
STM32 vs ESP32: Battle of the Microcontrollers 2026 4
  • The Lab

STM32 vs ESP32: Battle of the Microcontrollers 2026

Friday March 3, 2026
Arduino Mega vs ESP32: Processing Power Face-off 2026 5
  • The Lab

Arduino Mega vs ESP32: Processing Power Face-off 2026

Friday March 3, 2026

You May Have Missed

  • Latest News

7 Best Shopify Alternatives for Dropshipping in 2026

Friday March 4, 2026
  • The Lab

ESP32-C3 vs ESP32-S3: Detailed Comparison 2026

Friday March 4, 2026
  • The Lab

Raspberry Pi Pico vs ESP32: Which Should You Choose? 2026

Friday March 4, 2026
  • The Lab

STM32 vs ESP32: Battle of the Microcontrollers 2026

Friday March 3, 2026
CoreEcom provides honest, research-backed reviews and essential guides. We filter the noise to help global consumers find quality products that deliver real value, ensuring every purchase is a smart investment.

Categories

Buyer's Manuals Deep Reviews Editor's Choice Latest News Setup Guides The Lab

Quick Links

  • About
  • Editorial Standards
  • Privacy
  • Impressum
  • Contact
  • Facebook
  • Twitter
  • Linkedin
  • VK
  • Youtube
  • Instagram
Copyright © Growthscout 2026 All rights reserved. | ReviewNews by AF themes.