Build a Plant Watering System with a Soil Moisture Sensor

An automatic plant watering system reads soil moisture with a probe, compares that reading against a threshold, and switches a small water pump on only when the soil has actually dried out. The whole loop runs on an Arduino Uno: the probe reports a raw analog number, the sketch decides "wet enough" or "too dry," and a driver stage between the Arduino and the pump does the actual switching, because the Uno's own pins cannot carry the current a pump needs. Get the threshold and the driver stage right and the plant gets watered on a schedule nobody has to remember.

What parts does an automatic plant watering system need?

At minimum: a microcontroller (Arduino Uno), a soil moisture sensor, a small DC water pump, a switching stage between the board and the pump (a relay module or a motor driver module), a power supply, and wiring. A capacitive soil sensor is worth the small price difference over a resistive one because its probe is coated and does not corrode from sitting in wet soil for months. The pump itself only needs to be a low-voltage DC pump rated for a few hundred milliamps; nothing in this build needs mains power near the plant.

How does a soil moisture sensor work?

A capacitive soil moisture sensor measures moisture as a change in capacitance along its probe and outputs that as an analog voltage, which the Arduino reads on an analog pin as a raw number, typically somewhere in the 0-1023 range. There is no fixed "this means dry" value out of the box — dry air, dry soil, and freshly watered soil all produce different raw numbers depending on the specific sensor, the soil type, and even the probe's depth, which is exactly why calibration (below) is not optional.

Is it safe to run a water pump from an Arduino?

Not directly from a digital pin. An Arduino Uno pin can safely source only a few tens of milliamps, while even a small DC water pump draws on the order of 150-300 mA at startup — enough to damage the pin or the whole board if you wire the pump straight to it. The fix is a switching stage that sits between the Arduino and the pump: the Arduino sends a low-current logic signal to the switching stage, and the switching stage uses a separate supply to deliver the pump's actual current. A single-channel relay module is the simplest version of this: the Arduino's signal energizes a coil, the coil closes a mechanical contact, and the contact carries the pump's power completely isolated from the Arduino's circuitry. A motor driver module (such as an L298N) does the same isolating job through transistors instead of a mechanical contact, and adds the ability to run the pump in reverse or vary its speed with PWM — capability this build does not need, but it is not unsafe to use one where a relay would do. In the live capture below, Compoden's storefront assistant equipped this exact build with an L298N motor driver rather than a plain relay; the firmware demo further down was generated against a dedicated relay module instead. Either part does the same job of keeping the pump's current off the Arduino's pins — pick whichever one is in your tray.

How do you calibrate the dry/wet threshold?

Push the probe into the soil, read the raw analog value while the soil is at its driest (before watering), then water the plant thoroughly and read the value again a few minutes later once water has had time to soak in. Those two numbers are your calibration points. Set the "turn the pump on" threshold somewhere between them, closer to the dry reading than the wet one, so the pump does not fire on borderline readings. Because the exact numbers depend on your specific probe and soil, do this calibration once per sensor rather than trusting a value copied from someone else's build.

Watch it built live

We typed this into Compoden's AI build assistant on the live storefront:

"I want to build an automatic plant watering system using a soil moisture sensor and a water pump with an Arduino Uno"

Compoden AI build assistant parts tray for an Arduino Uno plant watering system

The assistant matched a full tray of seven in-stock parts in about two seconds and then walked through why each part was chosen. On the sensor, it wrote:

"The Capacitive Soil Moisture Sensor V2.0 measures how much water is in the soil. It uses a capacitive method, which means it senses changes in an electrical field to figure out moisture levels... It's important to know that this sensor needs to be calibrated, which means you'll need to set its 'dry' and 'wet' points yourself for accurate readings."

On the switching stage, it explained the same isolation problem covered above:

"The L298N Motor Driver Module is needed because the Arduino cannot directly provide enough power to run the pump. A motor driver acts like an intermediary, taking control signals from the Arduino and using a separate, more powerful supply to run the motor."

It also flagged a real power-budget problem rather than staying silent about it: with the pump and motor driver both active, the build's parts draw more current than the bundled 5V 2A adapter alone comfortably supplies during peak load, and it called that out directly in its reasoning instead of hiding it.

Watch the firmware get generated

Separately, we asked Compoden's PWA build tool (Soldr) to write firmware for the same project, this time naming a relay module specifically:

"I'm building an automatic plant watering system with an Arduino Uno, a soil moisture sensor, a relay module, and a water pump. Write the full firmware to check soil moisture and turn the pump on when it's dry."

Soldr firmware editor showing generated Arduino code for the plant watering system

Soldr matched all seven parts against the catalog — including a 5V Single Channel Relay Module for this pass — compiled a build plan, and generated a commented Arduino sketch. The tool's own summary of the code it wrote:

"Here's the complete firmware for your automatic plant watering system. It reads the capacitive soil moisture sensor, and if the moisture level falls below a threshold (indicating dry soil), it activates the relay to turn on the peristaltic pump for a set duration. The serial monitor will show the moisture readings and pump status."

The generated source defines the sensor on analog pin A2 and the relay control line on a digital pin, and the sketch is explicit about polarity: "The relay is assumed to be active-LOW, meaning writing LOW to the pin turns it ON." That is the kind of detail that trips people up when they wire a relay module and find the pump running exactly backwards from what they expected, so having it spelled out in the generated comments is genuinely useful.

Who this build is for

This suits a first automation project for someone comfortable wiring a breadboard and uploading a sketch through the Arduino IDE, but who has not yet driven a motor or pump from a microcontroller. The main new concept beyond a typical sensor project is the switching stage between the board and the pump — once that clicks, the same pattern applies to fans, lights, and other loads an Arduino cannot drive directly.

Get everything in this build

This is the exact tray Compoden's AI assistant matched for the prompt above, with live prices and one-click cart links per part.

Part Role Price Add to cart
Arduino Uno R3 CH340G ATmega328P Board Microcontroller Rs.230 Add to cart
Capacitive Soil Moisture Sensor V2.0 Soil moisture sensor Rs.55 Add to cart
Mini Submersible Pump 3-6V DC Water pump Rs.180 Add to cart
L298N Motor Driver Module Pump switching stage Rs.180 Add to cart
5V 2A Micro-USB Power Adapter Power supply Rs.140 Add to cart
23 AWG Multi-Strand Breadboard Wire Prototyping wire Rs.10 Add to cart
Male-to-Male Breadboard Jumper Wires (20 cm, 24 AWG) Jumper wires Rs.40 Add to cart
Total (7 parts) Rs.835 Add all 7 to cart

If you would rather build around a plain relay module instead of the L298N motor driver above, swap it for the 5V Single Channel Relay Module used in the firmware demo — the wiring and code both work the same way, since a relay and a motor driver's single channel do the identical isolating job for an on/off load like this pump.

Built and Backed by Compoden

Every part in the table above is pulled live from Compoden's own catalog, matched by the same AI assistant that just walked you through the wiring logic, and shipped from Compoden's stock rather than drop-shipped from a marketplace listing. If a part goes out of stock or a better-fit alternative appears, the assistant re-runs the match against current inventory rather than pointing you at a static list that goes stale.

Frequently asked questions

Why can't the pump plug straight into the Arduino?
An Arduino Uno pin safely sources only a few tens of milliamps. A DC water pump can draw 150-300 mA or more, especially at startup, which is enough to damage the pin. A relay or motor driver module carries the pump's current on a separate supply and only takes a low-current logic signal from the Arduino.

Should I use a resistive or capacitive soil moisture sensor?
Capacitive. A resistive probe has exposed metal traces that corrode after weeks in damp soil and drift out of calibration. A capacitive probe's traces are coated, so it holds its calibration far longer for a small price difference.

How do I set the dry/wet threshold?
Read the sensor's raw value in dry soil and again in freshly watered soil, then set the pump's trigger point between the two, closer to the dry reading. The exact numbers vary per sensor and per soil, so calibrate each build individually rather than reusing someone else's numbers.

Can I use a relay module instead of a motor driver?
Yes. For a simple on/off pump like this one, a single-channel 5V relay module and a motor driver module both isolate the pump's current from the Arduino's pins the same way. The motor driver adds reverse and speed control this build does not use.

Back to blog