Keep your plants alive even when you forget to water them. This automatic plant watering system uses a soil-moisture sensor to check how dry the soil is, and switches a small water pump through a relay whenever the soil gets too dry. It’s a genuinely useful build — and a favourite school and university project.
You’ll get a clear wiring diagram, the full Arduino code, and calibration tips so it waters at the right moment. Every part is in stock at Arduino Corner.
What you’ll need
- Arduino Uno R3 (with USB cable) — runs the code
- Soil Moisture Sensor — measures how dry the soil is
- 1-Channel Relay Module — safely switches the pump on and off
- Mini Submersible Water Pump — pumps water to the plant
- Jumper Wires — connect everything together
Youβll also need a length of tubing and a separate battery or adapter for the pump. New here? The Arduino Uno Starter Kit covers the board, breadboard and wires.
Wiring diagram

The same connections as a quick reference table:
| From (module) | To (Arduino Uno) |
|---|---|
| Soil sensor — VCC | 5V |
| Soil sensor — GND | GND |
| Soil sensor — AO | A0 |
| Relay — VCC | 5V |
| Relay — GND | GND |
| Relay — IN | D7 |
Tip: The pump draws more current than the Arduino can give, so power it from its own 5–12V battery/adapter through the relay’s COM and NO terminals — never straight from the Arduino’s 5V pin.
How it works
The soil sensor gives an analog value: wet soil conducts electricity well (low reading), dry soil conducts poorly (high reading). The Arduino reads this on A0 and compares it to a threshold. When the soil is too dry, it tells the relay to close — the relay is just an electrically-controlled switch that lets a tiny 5V signal turn a much bigger pump circuit on and off safely.
The Arduino code
No libraries needed — this sketch uses only built-in Arduino functions.
#define SOIL_PIN A0
#define RELAY_PIN 7
const int DRY_LEVEL = 600; // higher reading = drier soil (calibrate yours)
void setup() {
Serial.begin(9600);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH); // relay OFF (most modules are active-LOW)
}
void loop() {
int moisture = analogRead(SOIL_PIN);
Serial.print("Soil reading: ");
Serial.println(moisture);
if (moisture > DRY_LEVEL) { // the soil is dry
digitalWrite(RELAY_PIN, LOW); // pump ON
delay(3000); // water for 3 seconds
digitalWrite(RELAY_PIN, HIGH); // pump OFF
}
delay(2000);
}
Understanding the code
analogRead(SOIL_PIN) returns a number from 0–1023. Open the Serial Monitor and note the value when the soil is nicely watered and when it’s bone dry, then set DRY_LEVEL in between. Most relay modules are active-LOW, which is why LOW turns the pump ON. The short delay(3000) waters for three seconds — adjust it for your plant.
Troubleshooting
- Pump never runs: your soil reading may never cross
DRY_LEVEL. Watch the Serial Monitor and lower the threshold. - Pump runs non-stop: the relay is likely active-LOW — swap
HIGHandLOW, or check the pump’s own power supply. - Arduino resets when the pump starts: the pump must have its own power source, not the Arduino’s 5V pin.
Take it further
- Add an I2C LCD to show the live moisture level.
- Water two or more pots with extra relays and pumps.
- Run it from a solar panel + battery for a self-sufficient garden.
Frequently asked questions
How do I calibrate the soil sensor?
Insert it in well-watered soil and note the reading, then in dry soil and note that reading. Set DRY_LEVEL roughly halfway between the two.
Can the Arduino power the pump directly?
No. Even small pumps draw too much current and can damage the board. Always drive the pump through the relay with its own battery or adapter.
Will the sensor rust?
The basic two-prong sensor can corrode over weeks of constant contact. Powering it only during a reading (or using a capacitive sensor) makes it last much longer.
Related project guides
- Make an automatic night light with an LDR
- Control home appliances with a relay module
- Build a temperature & humidity meter with a DHT11
Get the parts
Everything for this build is in stock at Smart Home | Arduino Corner — Shaheen Market, DAV College Road, Rawalpindi — and ships across Pakistan with cash on delivery. Grab the soil moisture sensor, a relay module and a mini water pump. Message us on WhatsApp and we’ll put the whole kit together for you.