ElectroMartBDElectroMartBD

Build an Automatic Plant Watering System

Never forget to water your plants again! In this tutorial, we will build an automated plant watering box that monitors the soil moisture level and automatically pumps water when the soil gets too dry.

1. How It Works

The system uses an analog soil moisture sensor placed in the plant's soil. The Arduino constantly reads the moisture level. If the level drops below a specific threshold (meaning the soil is dry), the Arduino sends a signal to a relay module. The relay acts as a switch, turning on a mini water pump to water the plant for a few seconds.

What You Need:

  • 1x Arduino Uno R3
  • 1x Soil Moisture Sensor (Analog)
  • 1x 5V Relay Module
  • 1x 5V Submersible Mini Water Pump with Tubing
  • 1x Power Source (e.g., 5V 2A adapter or battery pack)
  • Jumper Wires

2. Wiring the System

Follow these connections carefully, especially when wiring the water pump and relay.

Soil Moisture Sensor to Arduino:

  • VCC to Arduino 5V
  • GND to Arduino GND
  • A0 (Analog Out) to Arduino A0

Relay Module to Arduino:

  • VCC to Arduino 5V
  • GND to Arduino GND
  • IN to Arduino Pin 8

Water Pump Circuit:

The water pump needs more current than the Arduino pins can provide, which is why we use a relay.

  • Connect the Positive (+) wire of your power supply to the COM (Common) terminal on the relay.
  • Connect the NO (Normally Open) terminal on the relay to the Positive (+) wire of the water pump.
  • Connect the Negative (-) wire of the water pump directly to the Negative (-) wire of your power supply.

Safety Warning: Do not use high voltage (like 220V AC mains) for this project. Stick to a 5V or 12V DC water pump to ensure safety.

3. The Arduino Code

Upload the following code to your Arduino. You can adjust the moistureThreshold value depending on how dry you want the soil to get before watering.

const int moisturePin = A0;
const int relayPin = 8;

// Define the threshold for dry soil
// Note: In some sensors, a higher analog value means drier soil
const int moistureThreshold = 600; 

void setup() {
  Serial.begin(9600);
  pinMode(relayPin, OUTPUT);
  
  // Make sure pump is off initially
  digitalWrite(relayPin, HIGH); // For active-low relays
}

void loop() {
  int moistureLevel = analogRead(moisturePin);
  Serial.print("Soil Moisture: ");
  Serial.println(moistureLevel);
  
  // If soil is dry (value is higher than threshold)
  if (moistureLevel > moistureThreshold) {
    Serial.println("Soil is dry! Watering plant...");
    
    // Turn on pump
    digitalWrite(relayPin, LOW); 
    
    // Water for 3 seconds
    delay(3000); 
    
    // Turn off pump
    digitalWrite(relayPin, HIGH); 
    
    // Wait a while before checking again to let water soak in
    delay(10000); 
  } else {
    Serial.println("Soil is moist.");
    // Wait 2 seconds before reading again
    delay(2000); 
  }
}

4. Testing the System

Submerge the pump in a container of water, and place the tubing so it points into your plant's pot. Insert the soil moisture sensor deeply into the soil. Open the Serial Monitor in the Arduino IDE to see the real-time moisture readings. Try taking the sensor out of the soil to simulate dry conditions—you should hear the relay click and see water pumping!