Smart Plant Watering System
Build an Arduino-based automatic irrigation system with moisture sensors and a water pump for efficient plant care.
- Arduino
- Intermediate
- 60–90 minutes
- 5 steps
Shop this project
CartYou'll need
Prices from vilros.com. Tax and shipping at checkout.
Before you start, you'll need
- Arduino Uno
- Soil moisture sensor (waterproof recommended)
- Water pump (12V recommended)
- Relay module
- Flexible tubing
- Power supply (12V for pump)
- Breadboard
- Jumper wires
- Water reservoir
Connect the moisture sensor
About 10 minutes
Wire the soil moisture sensor to Arduino.
- Connect the moisture sensor VCC to Arduino 5V.
- Connect the moisture sensor GND to Arduino GND.
- Connect the moisture sensor analog output to Arduino A0.
- Insert the sensor probes into the soil of your plant.
You should see
The moisture sensor is wired and inserted into the soil.
Set up the water pump with relay
About 15 minutes
Wire the relay module to control the water pump safely.
- Connect the relay module VCC to Arduino 5V.
- Connect the relay module GND to Arduino GND.
- Connect the relay IN pin to Arduino digital pin 7.
- Connect the water pump positive wire to the relay NO (Normally Open) terminal.
- Connect the relay COM (Common) terminal to the positive terminal of your 12V power supply.
- Connect the water pump negative wire to the power supply GND.
- Connect the Arduino GND to the power supply GND (common ground).
You should see
The relay and pump are wired correctly. The relay module LED should be off (pump is off).
It didn't work
Relay always stays on or off.
Check the IN pin connection to pin 7. Verify you're using the correct relay terminal (NO, not NC). Test the relay with a simple digitalWrite(7, HIGH) command.
Set up water delivery
About 10 minutes
Connect tubing from pump to plants.
- Place the water pump in your reservoir (bucket or tank).
- Attach flexible tubing to the pump output.
- Route the tubing to your plant(s).
- Test manually by powering the pump briefly to check for leaks.
You should see
Water flows from the reservoir through the tubing when the pump is powered.
Upload the irrigation sketch
About 20 minutes
Program the Arduino to water when soil is dry.
- Open Arduino IDE and copy the complete irrigation sketch below.
- Adjust the DRY_THRESHOLD value based on your sensor readings (lower = drier soil).
- Upload to your Arduino.
- Open Serial Monitor (9600 baud) to see moisture readings and pump status.
const int moisturePin = A0;
const int pumpPin = 7;
const int DRY_THRESHOLD = 400;
const int WATERING_TIME = 5000;
unsigned long lastWatering = 0;
const unsigned long WATERING_INTERVAL = 3600000;
void setup() {
pinMode(pumpPin, OUTPUT);
digitalWrite(pumpPin, LOW);
Serial.begin(9600);
Serial.println("Smart Watering System Starting...");
}
void loop() {
int moistureLevel = analogRead(moisturePin);
Serial.print("Moisture Level: ");
Serial.println(moistureLevel);
unsigned long currentTime = millis();
if (moistureLevel < DRY_THRESHOLD &&
(currentTime - lastWatering > WATERING_INTERVAL)) {
Serial.println("Soil is dry. Watering now...");
digitalWrite(pumpPin, HIGH);
delay(WATERING_TIME);
digitalWrite(pumpPin, LOW);
lastWatering = currentTime;
Serial.println("Watering complete.");
} else {
Serial.println("Soil moisture OK.");
}
delay(60000);
}DRY_THRESHOLD varies by sensor and soil type. Test with dry and wet soil to calibrate. WATERING_TIME is in milliseconds (5000 = 5 seconds).
You should see
The sketch uploads successfully. Serial Monitor shows moisture readings.
Calibrate and test
About 15 minutes
Fine-tune moisture threshold and watering duration.
- Open Serial Monitor and observe moisture readings.
- Note the reading when soil is completely dry.
- Note the reading after watering.
- Adjust DRY_THRESHOLD in the code to trigger watering at your desired moisture level.
- Adjust WATERING_TIME based on how much water your plant needs.
- Monitor for 24 hours to ensure the system waters at the right times.
You should see
The system waters the plant when soil is dry and stops when soil is moist.
It didn't work
Pump runs constantly.
The threshold may be set too high. Lower the DRY_THRESHOLD value. Check that the sensor is properly inserted in soil and reading correctly.
System never waters.
The threshold may be too low. Raise the DRY_THRESHOLD value. Verify the sensor is working by checking Serial Monitor readings.
What to do next
- Soil Moisture SensorBuild another Arduino gardening project.
- More Arduino projectsExplore intermediate Arduino builds.
Stuck? Contact Vilros Support with your board model and what you see on screen.