Relay module with Arduino Uno circuit diagram — timed plant watering

How to Use a Relay Module with Arduino Uno: Timed Plant Watering

Intro

An Arduino Uno pin can switch a small LED. It cannot switch a water pump. A digital pin gives 5 V and at most 40 mA, while even a small 5 V pump wants 200 mA or more at startup. Connect the pump straight to the pin and you will burn the pin, or the whole board.

That is what a relay is for. A relay is an electrically operated switch. The Arduino switches a small electromagnet inside the relay, and the electromagnet moves a metal contact that switches the pump. The two sides never touch each other electrically, so the pump’s current never flows through the Arduino at all.

In this guide, you will learn how to use a 1-channel relay module with Arduino Uno to build a timed plant watering system. The pump runs for 5 seconds every 30 seconds, on a millis() timer, with no delay() anywhere. You will also learn what COM, NO and NC mean, why this module switches on a LOW signal, and how to wire a real load safely.

Components Required

PartQuantityPurposePrice
1-Channel Relay Module 5V1Switches the pump on and offRs 155
Arduino Uno R3 DIP1Controls the relay and runs the codeRs 1,200
Mini 5V DC Water Pump Submersible1Waters the plantRs 250
MB102 solderless breadboard, 830 points1Holds the relay connections without solderingRs 250
40-pin male-to-male jumper wires6Connects the relay to the UnoRs 180
5V USB charger or power bank1Separate power supply for the pumpAvailable at home

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 guide 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 guide 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 guide.

Relay Module Pinout and Wiring with Arduino Uno

The 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.

Relay module pinArduino Uno pinWire colour used here
IND7Yellow
GNDGNDBlack
VCC5VRed

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.

Relay module with Arduino Uno circuit diagram — timed plant watering
Relay module circuit diagram with Arduino Uno — IN to D7, VCC to 5V, GND to GND, pump through NO and COM.

Library Installation

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

Complete Arduino Code

/*
  Relay Module Timed Plant Watering with Arduino Uno
  A 1-channel relay switches a mini 5V DC water pump on for
  5 seconds every 30 seconds, using millis() timing.
  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 LED_PIN  13        // Built-in LED mirrors the pump

const unsigned long WATER_MS = 5000;    // Pump on for 5 seconds
const unsigned long CYCLE_MS = 30000;   // One watering every 30 seconds

unsigned long cycleStart = 0;
bool watering = false;

void setup() {
  Serial.begin(9600);
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, HIGH);   // Relay OFF (active LOW module)
  digitalWrite(LED_PIN, LOW);
  cycleStart = millis();
  Serial.println("Relay Timed Watering ready");
  Serial.println("Pump ON 5 s, then OFF until the next 30 s cycle");
}

void loop() {
  unsigned long now = millis();
  unsigned long elapsed = now - cycleStart;

  // Start a watering burst at the top of each cycle.
  if (!watering && elapsed < WATER_MS) {
    watering = true;
    digitalWrite(RELAY_PIN, LOW);    // Relay ON (active LOW)
    digitalWrite(LED_PIN, HIGH);
    Serial.println("Pump ON - watering...");
  }

  // Stop the pump when the 5 seconds are up.
  if (watering && elapsed >= WATER_MS) {
    watering = false;
    digitalWrite(RELAY_PIN, HIGH);   // Relay OFF
    digitalWrite(LED_PIN, LOW);
    Serial.println("Pump OFF - waiting for the next cycle");
  }

  // Restart the cycle every 30 seconds.
  if (elapsed >= CYCLE_MS) {
    cycleStart = now;
  }
}

Code Explanation

Constants first. RELAY_PIN is 7, matching the wiring table. LED_PIN is 13, the built-in LED on the Uno, which mirrors the pump so you can see the state without the pump connected. WATER_MS is 5000 and CYCLE_MS is 30000: the pump runs 5 seconds out of every 30.

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() runs on a millis() schedule, not on delay(). It tracks how long the current cycle has run. At the top of a cycle (elapsed under 5 seconds) it switches the relay on by writing LOW, lights the LED, and prints “Pump ON”. Once 5 seconds have passed, it switches the relay off by writing HIGH. When 30 seconds have passed, it restarts the cycle. Because there is no delay() anywhere, the loop is free to do other work between checks, and the timing stays accurate.

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. You should see output like this:

Relay Timed Watering ready
Pump ON 5 s, then OFF until the next 30 s cycle
Pump ON - watering...
Pump OFF - waiting for the next cycle
Pump ON - watering...
Pump OFF - waiting for the next cycle

Each “Pump ON” line is followed by a click from the relay and the pump running for 5 seconds. The built-in LED lights up with the pump. If you hear the click but the pump does not run, the problem is in the pump wiring or the pump’s own supply, not in the Arduino side.

Troubleshooting

  1. 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.
  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 pump runs all the time, even when the code says OFF. 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.
  4. 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.
  5. The code uploads but the Serial Monitor is empty. Check the baud rate in the Serial Monitor. It must be 9600, the same as Serial.begin(9600). Also check that you selected Arduino Uno as the board and the right COM port under Tools.
  6. The relay works with the LED test but not with the pump. A pump is an inductive load: its motor coil fights changes in current and can send a voltage spike back when it switches off. The relay contacts handle that, but the spike can disturb the Arduino if the pump wires run right next to the signal wires. Keep the pump wires short and away from the IN wire. If the Uno resets when the pump stops, that spike is the cause.

Project Ideas and FYP Ideas Using a Relay Module

  1. Automatic plant watering with a soil sensor. Add a soil moisture sensor and water only when the soil is dry. The sensor tells the Arduino when to switch the relay, so the pump runs on need, not on a timer. It is the natural next step from this guide.
  2. Home automation: light control. Use the relay to switch a 12 V LED strip in a room, controlled by a push button or a timer. Keep it at 12 V, not mains, for a student project. Add an LDR so the light turns on automatically at dusk.
  3. Automatic fan control. Connect a relay to a 12 V DC fan and a DHT11 temperature sensor. When the room passes 30 °C, the relay switches the fan on. When it falls below 28 °C, it switches off. The two-degree gap stops the fan flicking on and off.
  4. Water tank level controller. 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.
  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.

Still stuck?

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

You can also watch our videos on YouTube:

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 guide 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 QKZee Technologies. A complete starter setup with an Arduino Uno, pump, breadboard and jumper wires costs roughly Rs 2,040.

Conclusion

A relay module with Arduino turns a small 5 V signal into real switching power. You have learned the three things that matter: 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 timed watering system you built is a complete project, and it is also the base for bigger ones: add a soil sensor and it waters on need, add a DHT11 and it cools a room, add an RFID reader and it opens a lock. The relay is the part that makes all of them real.

Components for this project are available at QKZee Technologies, and smart circuit hub with nationwide Cash on Delivery across Pakistan.

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

Similar Posts

Leave a Reply

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