A timer waters a plant whether it needs water or not. A sensor waters it only when the soil is dry. That is the difference between a gadget and a useful system, and a relay module is the part that makes it possible.

In this tutorial you will build an automatic plant watering system with a relay module and Arduino Uno. A soil moisture sensor watches the soil, and when it goes dry the relay switches a mini 5 V water pump on for 5 seconds. The pump gets its own 5 V supply, and the relay keeps the two circuits completely separate. You will also learn what COM, NO and NC mean, why this module switches on a LOW signal, and how to read the soil sensor’s digital and analog outputs together.

What You Need

PartQuantityPurpose
1-Channel Relay Module 5V for Arduino1Switches the pump on and off
Arduino UNO R3 DIP ATmega328P with USB Cable1Reads the sensor and controls the relay
Mini 5V DC Water Pump — Submersible1Waters the plant
Soil Moisture Sensor for Arduino1Detects dry soil
MB102 Breadboard 830 Points1Holds the connections without soldering
40-pin Dupont Jumper Wires 30cm (M-M, F-F, M-F)8Connects the relay and sensor to the Uno
5V USB charger or power bank1Separate power supply for the pump

A ready-made version of this project is also available on order, and all the components above are available in our store.

How a Relay Module Works

Inside the blue plastic case of the relay sits an electromagnet and a metal arm called an armature. When current flows through the coil, the electromagnet pulls the armature. The armature carries the moving contact, called COM (common). At rest, COM touches the NC contact (normally closed). When the coil is energised, COM moves and touches the NO contact (normally open). That click you hear is the armature moving.

The module adds three things around the bare relay. First, an optocoupler: a tiny LED and light sensor in one chip that carries the Arduino’s signal across as light, with no electrical connection. Second, a transistor that drives the coil, because the optocoupler alone cannot supply the coil’s ~71 mA. Third, a small red LED that lights up when the relay is energised, so you can see its state without listening for the click.

Two things about this module confuse almost every beginner. First, it is active LOW. Writing LOW to the IN pin turns the relay ON, and writing HIGH turns it OFF. That is backwards from an LED, and it is because the optocoupler’s LED is wired so that a LOW pin lets current flow through it. Second, the JD-VCC jumper. With the jumper on, the relay coil and the optocoupler share the same 5 V supply, which is how this tutorial wires it. Remove the jumper and you can power the coil from a separate 5 V supply for full isolation. Beginners should leave the jumper on.

Relay vs transistor: which one should you use?

A relay and a transistor both switch loads, but they are different tools.

FeatureRelay moduleTransistor / MOSFET
IsolationFull — coil and contacts are separateNone — same circuit
Can switch AC loadsYes, up to the contact ratingNo — DC only
Switching speedSlow, about 10 ms, with a clickVery fast, silent
PWM / dimmingNo — contacts wear outYes
CurrentUp to 10 A on this moduleDepends on the part
LifeAbout 100,000 operationsPractically unlimited

Rule of thumb: use a relay when you need isolation or you are switching an AC load or a load that needs its own power supply. Use a transistor when you need fast switching, PWM, or a small DC load. For a pump on its own supply, the relay is the right choice.

Key specifications of the 1-channel relay module (SRD-05VDC-SL-C relay):

SpecificationValue
Operating voltage5 V DC
Coil currentAbout 71 mA when energised
Coil resistance70 ohm ±10%
TriggerActive LOW (LOW = relay ON)
Contact formSPDT — COM, NO, NC
Contact rating10 A, 250 V AC / 30 V DC (printed on the relay)
Operate / release timeAbout 10 ms / 5 ms
Electrical lifeAbout 100,000 operations
IsolationOptocoupler between Arduino and coil

The full numbers are in the relay module manual.

Safety note: this tutorial switches only a 5 V DC pump. A relay can switch 220 V mains, but mains wiring is not a beginner project. It needs an enclosed, properly rated setup and respect for the danger. Do not switch mains with this tutorial.

Relay and Soil Sensor Wiring with Arduino Uno

The relay module has three signal pins on one edge and three screw terminals on the other. The signal pins, top to bottom, are IN, GND and VCC. The screw terminals are NO, COM and NC. The soil moisture sensor has four pins: VCC, GND, DO (digital output) and AO (analog output).

Relay module pinArduino Uno pin
IND7
GNDGND
VCC5V
Soil sensor pinArduino Uno pin
VCC5V
GNDGND
DOD2
AOA0

The pump does not connect to the Arduino at all. It gets its own 5 V supply (a USB charger or power bank). The relay contacts sit in the pump’s positive wire like a switch:

Pump wiringConnection
5 V supply +Relay COM terminal
Relay NO terminalPump red wire
Pump black wire5 V supply GND

When the relay is off, COM touches NC, so the pump circuit is open and the pump is off. When the relay is on, COM touches NO, the circuit closes, and the pump runs. The Uno’s GND and the pump supply’s GND are not connected to each other. That is the point of the relay: the two circuits are fully separate, and the pump’s current never passes through the Arduino.

The soil sensor gives two outputs at once. DO is a digital signal from the module’s comparator: HIGH when the soil is dry, LOW when it is wet. The threshold is set by the small potentiometer on the sensor board; turn it until the module’s own LED changes state at the dryness you want. AO is the raw analog reading, 0 to 1023, where lower numbers mean wetter soil. This tutorial uses DO to decide when to water and prints AO so you can see the moisture level.

Relay module automatic plant watering circuit diagram with Arduino Uno, soil sensor and pump
Relay module circuit diagram with Arduino Uno — IN to D7, soil sensor DO to D2, AO to A0, pump through NO and COM on its own 5V supply.

Library Installation

No library is needed. A relay is switched with a plain digitalWrite(), and the soil sensor is read with digitalRead() and analogRead(), so this project uses only the built-in Arduino functions.

Complete Arduino Code

/*
  Relay Module Automatic Plant Watering with Arduino Uno
  A soil moisture sensor watches the soil. When the soil is dry
  (sensor DO pin HIGH), the relay switches a mini 5V DC water
  pump on for 5 seconds, then rests for 10 seconds before
  checking again. The analog reading (AO) is printed so you
  can see how wet the soil is: lower numbers mean wetter soil.
  The relay module is ACTIVE LOW: writing LOW to IN turns the
  relay ON, writing HIGH turns it OFF.
  The pump runs on a SEPARATE 5V supply (USB charger or power
  bank). Its + wire goes through the relay contacts:
  supply + -> relay COM, relay NO -> pump red wire,
  pump black wire -> supply GND. The Uno and the pump supply
  share no wires - the relay isolates them.
*/

#define RELAY_PIN 7        // Relay IN pin
#define SOIL_DO_PIN 2      // Soil sensor digital output
#define SOIL_AO_PIN A0     // Soil sensor analog output
#define LED_PIN  13        // Built-in LED mirrors the pump

const unsigned long WATER_MS = 5000;    // Pump on for 5 seconds
const unsigned long REST_MS = 10000;    // Rest 10 seconds after watering
const unsigned long CHECK_MS = 2000;    // Check the soil every 2 seconds

unsigned long lastCheck = 0;
unsigned long waterStart = 0;
unsigned long restUntil = 0;
bool watering = false;

void setup() {
  Serial.begin(9600);
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(SOIL_DO_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, HIGH);   // Relay OFF (active LOW module)
  digitalWrite(LED_PIN, LOW);
  Serial.println("Relay Automatic Watering ready");
  Serial.println("Soil AO | Dry?");
}

void loop() {
  unsigned long now = millis();

  // Stop the pump when the 5 seconds are up.
  if (watering && now - waterStart >= WATER_MS) {
    watering = false;
    digitalWrite(RELAY_PIN, HIGH);   // Relay OFF
    digitalWrite(LED_PIN, LOW);
    restUntil = now + REST_MS;
    Serial.println("Pump OFF - resting 10 s");
  }

  // Check the soil every 2 seconds, only when not watering
  // and not resting.
  if (!watering && now >= restUntil && now - lastCheck >= CHECK_MS) {
    lastCheck = now;

    int soilAO = analogRead(SOIL_AO_PIN);       // 0-1023, lower = wetter
    bool dry = digitalRead(SOIL_DO_PIN) == HIGH; // DO HIGH = dry soil

    Serial.print(soilAO);
    Serial.print(" | ");
    Serial.println(dry ? "DRY" : "wet");

    if (dry) {
      watering = true;
      waterStart = now;
      digitalWrite(RELAY_PIN, LOW);    // Relay ON (active LOW)
      digitalWrite(LED_PIN, HIGH);
      Serial.println("Soil is dry - pump ON for 5 s");
    }
  }
}

Note: the 10-second rest after watering is there on purpose. Water takes time to soak into the soil, and the sensor needs a moment to feel it. Without the rest, the sensor would still read dry right after watering and the pump would run again immediately.

Code Explanation

Constants first. RELAY_PIN is 7, matching the wiring table. SOIL_DO_PIN is 2 and SOIL_AO_PIN is A0. LED_PIN is 13, the built-in LED, which mirrors the pump so you can see the state without the pump connected. WATER_MS is 5000, REST_MS is 10000 and CHECK_MS is 2000.

setup() sets the relay pin as an output and writes HIGH to it immediately. On this module HIGH means relay OFF, so the pump starts off. That first write matters: without it, the relay could switch on for a moment at startup.

loop() has two parts and no delay() anywhere. The first part stops the pump: when 5 seconds of watering have passed, it writes HIGH to the relay and sets restUntil to 10 seconds from now. The second part checks the soil every 2 seconds, but only when the pump is not running and the rest period has finished. It reads the analog value with analogRead() and the digital state with digitalRead(). If DO is HIGH, the soil is dry, so it starts the pump by writing LOW to the relay.

The most important line to understand is digitalWrite(RELAY_PIN, LOW). On an active LOW module, LOW turns the relay ON. If you write HIGH expecting the pump to start, nothing will happen. That is the single most common relay bug.

Demonstration: Expected Serial Monitor Output

If you have never uploaded code before, see our guide on how to upload code in Arduino Uno.

Upload the code, then open the Serial Monitor with Tools > Serial Monitor and set the baud rate to 9600. With the sensor in dry soil you should see output like this:

Relay Automatic Watering ready
Soil AO | Dry?
620 | DRY
Soil is dry - pump ON for 5 s
Pump OFF - resting 10 s
540 | DRY
Soil is dry - pump ON for 5 s
Pump OFF - resting 10 s
410 | wet
430 | wet

The AO number falls as the soil gets wetter. After a few watering cycles the sensor reads wet and the pump stays off. The exact numbers depend on your soil and on the potentiometer setting, so do not expect the same values. What matters is the pattern: high when dry, lower when wet, and DRY changing to wet after watering.

Troubleshooting

1. The pump runs all the time, even when the soil is wet. You probably wired the pump to NC instead of NO. On NC, the circuit is closed when the relay is OFF, which is the opposite of what you want. Move the pump wire from NC to NO. The screw terminals are labelled on the module.

2. The relay never clicks and the LED never lights. The relay is not being driven. Check that IN is on D7 and matches RELAY_PIN in the code, VCC is on 5V, and GND is on GND. Also check that the JD-VCC jumper is still on the module. Without it, the coil gets no power.

3. The sensor always says DRY, even in wet soil. The threshold potentiometer is set too far towards dry. Turn the small screw on the sensor board slowly until the module’s own LED changes state in wet soil. Also check that the sensor prongs are pushed into the soil, not just touching the surface.

4. The sensor always says wet, even in dry soil. The threshold is set too far towards wet, or the prongs are shorted. Turn the potentiometer the other way. If the AO reading is near zero in dry soil, the prongs may be touching each other or a metal pot.

5. The relay clicks, but the pump never runs. The Arduino side is working. Check the pump circuit: the 5 V supply + must go to COM, NO must go to the pump red wire, and the pump black wire must go back to the supply GND. Check that the supply itself is on and can give 5 V. A weak phone charger that cannot supply enough current will drop its voltage when the pump starts.

6. The relay clicks on and off rapidly by itself. The Uno may be resetting. The relay coil draws about 71 mA, and if the Uno is powered from a weak USB port, the extra load can drop the voltage and reset the board. Power the Uno from a proper 5 V 1 A USB charger, not a laptop port that is already loaded.

Project Ideas and FYP Ideas Using a Relay Module

1. Smart irrigation system. Put one sensor in each plant pot and one relay per pump. The Arduino waters each pot only when its own soil is dry. Add an LCD to show which pot was watered last. It is a strong FYP because it senses, decides and acts for every plant separately.

2. Greenhouse climate control. Combine the relay with a DHT11 temperature sensor and a soil sensor. The relay runs the pump when the soil is dry and a fan when the air is hot. One board, two relays, two different jobs, and a display that shows both readings.

3. Automatic water tank filling. Two water level sensors, one at the bottom and one at the top of a tank. When the level falls to the bottom sensor, the relay starts the pump. When it reaches the top sensor, the relay stops it. It is a real household problem with a simple relay answer.

4. Home automation: light control. Use the relay to switch a 12 V LED strip in a room, controlled by a timer or an LDR that turns the light on at dusk. Keep it at 12 V, not mains, for a student project.

5. Automatic gate or door lock. A relay switches a 12 V solenoid lock. Combine it with an RFID reader or a keypad so the lock opens only for the right card or code. The relay is the part that turns a small signal into a real mechanical action.

Need Help with the Build?

If the build does not work, message us on WhatsApp and we will help:

Frequently Asked Questions

What is COM, NO and NC on a relay?

COM is the moving contact. NO (normally open) is connected to COM only when the relay is ON. NC (normally closed) is connected to COM only when the relay is OFF. For switching a load on and off, wire the load through COM and NO.

Why is my relay module active LOW?

The optocoupler on the module is wired so that a LOW signal on the IN pin lets current flow through its LED, which switches the transistor and energises the coil. A HIGH signal stops that current. So LOW means ON and HIGH means OFF. It is the module’s design, not a fault.

Can a relay switch AC mains (220 V)?

The relay contacts are rated for it, but mains wiring is not a beginner project. It needs an enclosed, properly rated setup, correct wire sizes, and respect for the danger. This tutorial switches only a 5 V DC pump. Learn the relay on low voltage first.

Can I use a relay to dim a light or control motor speed?

No. A relay is an on/off switch that takes about 10 ms to move and wears out after about 100,000 operations. PWM dimming or speed control needs a transistor or MOSFET, which switches in microseconds and never wears out.

What is the relay module price in Pakistan?

The 1-channel relay module costs Rs 155 at Smart Circuit Hub. A complete setup with an Arduino Uno, pump, soil sensor, breadboard and jumper wires costs roughly Rs 2,160.

Conclusion

You have built a system that senses, decides and acts: a soil sensor reads the soil, the Arduino decides it is dry, and a relay switches the pump. You have also learned the three things that matter about relays: the contacts (COM, NO, NC), the active LOW trigger, and the rule that the load gets its own power supply while the relay keeps the two circuits separate. The same three ideas run every relay project, from a plant waterer to a tank filler to a door lock. Try the smart irrigation idea next. It adds one sensor and one relay per pot to this exact build, and the code already shows you the pattern.

Components for this project are available at Smart Circuit Hub with nationwide Cash on Delivery across Pakistan.

If you missed it, our DHT11 temperature and humidity tutorial and our HC-SR04 ultrasonic sensor tutorial build on the same wiring skills.

Leave a Reply

Your email address will not be published. Required fields are marked *