Automatic plant watering with a soil moisture sensor on Arduino: design worksheet and code

A ₹1,102 design worksheet for a plant-watering system that waters only when the soil is dry, using a capacitive moisture sensor, a relay and a small pump, with hysteresis and run limits explained.

About the author · Editorial & verification standards

  • Parts₹1,102
  • Bench time4–6 h
  • LevelIntermediate
  • ReviewedNov 2026

A ₹1,102 watering system that gives a pot water only when the soil is dry and never floods it. A capacitive soil moisture sensor is read as a percentage, a relay switches a small pump, and the sketch has two safety limits so a stuck sensor cannot empty the bucket.

Scope: intermediate. This is a design worksheet with illustrative costs. It has not been bench-tested by this site. The percentage table and run limits below were computed by script. The raw sensor numbers in the sketch are placeholders: you must calibrate your own sensor in dry air and in a glass of water. Keep the pump and water away from the Arduino and mains.

How it works

A capacitive soil sensor outputs a voltage that falls as the soil gets wetter, so a dry sensor reads a high number and a wet one a low number. The sketch stores two calibration readings, DRY and WET, and converts any reading to a percentage with a straight line between them.

The pump starts when the moisture falls below 30 percent and stops when it rises above 45 percent. The gap between the two numbers is called hysteresis; without it the pump would switch on and off around a single threshold. Two extra limits protect the plant: the pump never runs for more than 10 seconds at a time, and after a run it waits 10 minutes for the water to soak through before reading again.

Bill of materials

PartQtyUnitTotal
Arduino Uno R3 (or compatible)1₹550₹550
Capacitive soil moisture sensor1₹120₹120
5 V relay module1₹70₹70
Mini submersible pump, 5 V1₹150₹150
Silicone tube, 1 m1₹40₹40
5 V power adapter for the pump1₹120₹120
1N4007 diode1₹2₹2
Jumper wires1₹50₹50
Parts total₹1,102

Scroll the table sideways to see every column.

Prices checked Nov 2026. Shipping and tools are not included.

Prices are illustrative figures for Indian sellers in November 2026, before shipping, and have not been checked against current listings.

The numbers

Raw reading (example DRY 620, WET 300)MoistureAction
6200%Water
52430%Start pump (below 30%)
47645%Stop pump (above 45%)
38075%Leave alone
300100%Leave alone
Percent = (DRY − raw) × 100 / (DRY − WET). The example numbers are placeholders, not your sensor.

Water per run is only a rough guess. Mini pumps are often listed around 80 litres per hour, about 22 ml per second, so a 10 second run is roughly 220 ml. Measure your own pump by running it for 10 seconds into a measuring jug, and adjust the limit.

Power and wiring

PartConnects toNote
Sensor VCC, GND, AOUT5V, GND, A0Check the sensor’s voltage range
Relay IND7Many relay modules switch on a LOW signal
Relay VCC and GND5V and GND
PumpRelay contacts and the separate 5 V adapterDo not run the pump from the Uno pin
1N4007 diodeAcross the pump terminalsStripe toward the positive side; it absorbs the kick when the pump stops
Keep the sensor’s electronics above the soil line; only the marked probe area goes in the soil.

The sketch

// Automatic plant watering: Uno + capacitive soil sensor + relay + pump
// Design worksheet: DRY and WET are placeholders; calibrate your own sensor.

const int SENSOR = A0;
const int RELAY = 7;
const bool RELAY_ON = LOW;          // many modules are active-low

const int DRY = 620;                // reading in dry air
const int WET = 300;                // reading in a glass of water
const int START_BELOW = 30;         // percent
const int STOP_ABOVE = 45;          // percent
const unsigned long MAX_RUN = 10000UL;       // 10 s
const unsigned long SOAK_WAIT = 600000UL;    // 10 min

bool pumping = false;
unsigned long runStart = 0, lastRun = 0;

int moisture() {
  long raw = analogRead(SENSOR);
  long pct = (long)(DRY - raw) * 100 / (DRY - WET);
  return constrain(pct, 0, 100);
}

void pump(bool on) { digitalWrite(RELAY, on ? RELAY_ON : !RELAY_ON); pumping = on; }

void setup() {
  pinMode(RELAY, OUTPUT);
  pump(false);
  Serial.begin(9600);
}

void loop() {
  int m = moisture();
  unsigned long now = millis();
  if (!pumping) {
    bool waited = (lastRun == 0) || (now - lastRun >= SOAK_WAIT);
    if (m < START_BELOW && waited) { pump(true); runStart = now; }
  } else if (m > STOP_ABOVE || now - runStart >= MAX_RUN) {
    pump(false); lastRun = now;
  }
  Serial.println(m);
  delay(500);
}

If the relay clicks the wrong way, change RELAY_ON. If the sensor ever reads outside the DRY to WET range, the constrain call keeps the percentage between 0 and 100, but a reading far outside it probably means a wiring fault. The sketch has been proofread but not compiled on this site.

Test plan

  1. Calibrate: print raw readings with the sensor in dry air and in a glass of water, and set DRY and WET.
  2. Dry run: run the pump into a jug with the sensor out of the soil and check the 10 second limit stops it.
  3. Measure the pump: time 10 seconds of flow and write down the volume.
  4. Soil test: use a pot with dry soil and see how the reading changes over the 10 minute soak.
  5. Fault test: unplug the sensor and confirm the pump still stops at the run limit.
  6. Leak check: look over the tube joints before leaving it unattended.

What usually goes wrong

SymptomLikely causeFix
Pump never startsCalibration values reversed or relay logic wrongPrint raw values and swap DRY and WET or RELAY_ON
Pump runs the full 10 s every timeSensor reads dry because it is not touching soilPush the probe in firmly
Reading drifts over weeksProbe corrosion or soil saltsChoose a capacitive sensor and recheck calibration monthly
Arduino resets when the pump startsPump on the Uno supplyUse a separate 5 V adapter with a common ground
OverwateringSoak wait too shortLengthen the wait or shorten the run limit

Upgrades

  • Water level: add a float switch so the pump never runs dry.
  • Logging: record the moisture each hour to see the drying rate.
  • Several pots: add a sensor and a relay channel per pot.
  • Remote alert: move to an ESP32 and send a message when the tank is low.

Cost and parts notes

The ₹1,102 total is an illustration and does not include shipping. Use the cost calculator to compare sellers.

Common questions

Two-prong resistive probes tend to corrode in wet soil. Capacitive sensors have no exposed metal in the soil.

Water takes time to spread to the sensor. Reading too soon makes the soil look dry and starts another run.

The pump stops, because the relay returns to off. The sketch restarts and reads the soil again.

Use any clean water. Keep every mains connection away from this circuit.

Last reviewed: November 2026. This is a design worksheet with illustrative costs. It has not been bench-tested by this site; library names, pins and limits must be checked against your board and the current library versions, and measurements from your build are welcome.

More builds

Next builds to try

Free: the final-year project pack

A shortlist with BOMs, a report outline that matches the usual chapter scheme, a costing sheet and 40 viva questions. Built for the February–April submission season.

The Build Note

One short email when something is worth your bench time.

A new build sheet, a part price that moved, or a mistake worth avoiding. No daily drip, no recycled news.

One short email when a build or a price is worth your time. Unsubscribe in one click.