What Is a Relay Module in Arduino? How It Works and Wiring
A relay module in Arduino is a switch the board controls to turn lamps, pumps and fans on and off. How it works, NO/NC/COM pins, wiring, a button sketch and safety.
A relay is an electrically operated switch that uses a small electrical signal to turn a much bigger load on and off. An Arduino pin can only supply 5 V and a few tens of milliamps; that's enough for an LED, but not for a lamp, a fan, a water pump or a device running on 230 V mains. A relay module bridges the gap: the Arduino sends a small signal, and the relay closes its internal contacts so the large current flows through the load. It's the core part of smart home, automatic watering and timer projects.

How does a relay work?
Inside a relay there's a coil (an electromagnet), a movable metal arm and a set of contacts. When current flows through the coil, the magnetic field pulls the arm and closes the contacts; the "click" you hear is that movement. When the current stops, a spring pushes the arm back and the contacts open.
The key point is that there's no electrical connection between the coil side (the control circuit) and the contact side (the load circuit). They're linked only magnetically. That keeps your 5 V Arduino circuit isolated from the mains line.
What's on a relay module?
You can't connect a bare relay straight to an Arduino pin: the coil draws more current than the pin can supply, and when it switches off it produces a voltage spike that can destroy the pin. A module board comes with the parts that solve these problems:
- Driver transistor: switches the 70–80 mA the coil needs using the small signal from the pin.
- Flyback diode: absorbs the reverse voltage produced when the coil switches off, protecting the transistor and the Arduino.
- Optocoupler (on some models): passes the control signal across as light, fully separating the Arduino from the relay circuit.
- Status LED: lights up when the relay is on; very handy for checking that your code works.
- Screw terminals: let you connect the load wires securely without soldering.
What do NO, NC and COM mean?
The load side of a relay has three terminals. Which ones you use decides whether your device is on or off when the relay is not energised:
| Terminal | Meaning | When is it connected to COM? |
|---|---|---|
| COM | Common; one of the load wires goes here | Always connected to either NO or NC |
| NO | Normally Open | Only when the relay is energised |
| NC | Normally Closed | When the relay is not energised |
Specifications (common 5 V module)
| Feature | Value |
|---|---|
| Coil voltage | 5 V DC |
| Coil current | About 70–80 mA (per channel) |
| Contact rating | 10 A 250 V AC / 10 A 30 V DC (printed on the relay) |
| Trigger | Active LOW or active HIGH (depends on the module) |
| Control pins | VCC, GND, IN (IN1, IN2... on multi-channel boards) |
| Load terminals | COM, NO, NC |
Connecting a relay module to Arduino
The control side takes three wires: connect the module's VCC to 5V, GND to GND and IN to digital pin 7. On the load side, you cut one of the wires of the device you want to control and connect its two ends to the COM and NO terminals. The relay simply takes the place of an ordinary wall switch.
1const int RELAY_PIN = 7;
2
3void setup() {
4 pinMode(RELAY_PIN, OUTPUT);
5 digitalWrite(RELAY_PIN, HIGH); // aktif LOW modülde kapalı başla / start OFF on active-LOW modules
6}
7
8void loop() {
9 digitalWrite(RELAY_PIN, LOW); // röle çeker, cihaz açılır / relay on
10 delay(3000);
11 digitalWrite(RELAY_PIN, HIGH); // röle bırakır, cihaz kapanır / relay off
12 delay(3000);
13}Controlling a relay with a button: on-off switch
In real projects you usually control the relay with a button, a sensor or a timer. The code below toggles the relay each time you press the button, so you can switch a mains lamp with a tiny push button. For button wiring and bounce, see How to Connect a Push Button to Arduino.
1const int RELAY_PIN = 7;
2const int BUTTON_PIN = 2; // butonun diğer ucu GND'de / other leg to GND
3
4bool relayOn = false;
5bool lastButton = HIGH;
6
7void setup() {
8 pinMode(RELAY_PIN, OUTPUT);
9 pinMode(BUTTON_PIN, INPUT_PULLUP);
10 digitalWrite(RELAY_PIN, HIGH); // başta kapalı / start OFF (active LOW)
11}
12
13void loop() {
14 bool button = digitalRead(BUTTON_PIN);
15 if (lastButton == HIGH && button == LOW) { // yeni basış / new press
16 relayOn = !relayOn;
17 digitalWrite(RELAY_PIN, relayOn ? LOW : HIGH);
18 delay(50); // sıçrama önleme / debounce
19 }
20 lastButton = button;
21}JD-VCC and the optocoupler: full isolation
On optocoupler modules, next to the VCC, GND and IN pins there's a pin called JD-VCC with a jumper. With the jumper fitted, the relay coil is also powered from the Arduino's 5 V. If you remove the jumper and connect a separate 5 V adapter to JD-VCC and its own GND, the coil current comes entirely from that adapter, and the Arduino side only lights the optocoupler's LED. With noisy loads such as motors and pumps, this greatly reduces Arduino freezes and resets.
Relays with the ESP32 and Raspberry Pi Pico
ESP32 and Pico pins output 3.3 V. Most 5 V relay modules will trigger from this signal, but on an active-LOW module a 3.3 V HIGH may not always release the relay fully; if your relay stays on all the time, this is why. The fix is to buy a 3.3 V-trigger module, use an optocoupler board with a JD-VCC split, or add a small NPN transistor. The module itself should still be powered from 5 V. Controlling a relay from a Pico in MicroPython is as simple as this:
1from machine import Pin
2import time
3
4relay = Pin(15, Pin.OUT, value=1) # GP15, aktif LOW: 1 = kapalı / active LOW: 1 = off
5
6while True:
7 relay.value(0) # röle çeker / relay on
8 time.sleep(3)
9 relay.value(1) # röle bırakır / relay off
10 time.sleep(3)Safety rules for working with mains voltage
- Respect the current rating: never exceed the value printed on the relay (for example 10A 250VAC). With high-power devices such as heaters, air conditioners and kettles, stay well below that limit.
- Switch the live wire: when controlling a lamp or socket, route the live wire through the relay, not the neutral, so no voltage remains on the device when it's off.
- Use proper cable: breadboard jumper wires aren't made for mains; on the load side use insulated cable of a suitable cross-section.
- Insulate the underside of the board: the module's solder side carries mains voltage; don't leave it touching metal surfaces or bare hands.
- Add a fuse: a suitably rated fuse in the load line prevents a fire in case of a short circuit.
Relay, transistor or solid-state relay?
| Feature | Mechanical relay | Transistor / MOSFET | Solid-state relay (SSR) |
|---|---|---|---|
| Switches | AC and DC | DC only | Mostly AC |
| Speed | Slow (milliseconds) | Very fast, can do PWM | Fast |
| Noise | Clicks | Silent | Silent |
| Lifetime | Contacts wear over time | Very long | Very long |
| Best for | Lamps, sockets, pumps | Motor speed, LED strips | AC loads switched often |
In short: if you'll switch a device on and off now and then, a mechanical relay is the cheapest and easiest solution. To adjust a motor's speed or an LED strip's brightness, choose a transistor or MOSFET, and for AC loads switched many times a second, a solid-state relay. To choose a suitable transistor, have a look at the Transistors tool.
Relay project ideas
- Smart watering: run a water pump when the soil moisture sensor says the soil is dry.
- Motion-activated light: turn a lamp on when a PIR sensor detects someone and off again after a while.
- Humidity-controlled fan: start the bathroom extractor when humidity rises; for measuring, see DHT11 Temperature and Humidity Sensor.
- Remote-controlled socket: switch a socket with an IR receiver and a TV remote.
- Timer: turn an aquarium light on and off at the same time every day.
- Phone control: manage a lamp from a web page using the ESP32's Wi-Fi.
Common mistakes and how to fix them
- The relay works backwards: the module is active LOW; swap HIGH and LOW in the code.
- The relay keeps clicking: the power supply may be too weak; use an external 5 V adapter, especially with several relays.
- The Arduino resets when the motor starts: noise and voltage drop; power the coil separately via JD-VCC and add a capacitor across the motor.
- The LED is on but the load doesn't run: the load wires may be on NC, or a terminal screw may be loose.
- The relay never releases with an ESP32: the 3.3 V HIGH can't switch off an active-LOW module; use a 3.3 V-compatible module or a transistor.
- Connecting a bare relay straight to a pin: the coil current and reverse voltage destroy the pin; always use a module, or a transistor plus a diode.
Once you pair a relay with a sensor, you start building automations that are genuinely useful. To see which sensor does what, take a look at the Arduino Sensors Guide; in the BlueGrays app you'll find relay lamp, watering and lighting projects step by step with circuit diagrams.
Frequently asked questions
Why does my relay module keep clicking?
The most common cause is a weak power supply: when the relay pulls in, the voltage drops, the Arduino resets and the relay releases. If you use several relays or power the Arduino from USB, use an external 5 V adapter. Also check that your code doesn't have a loop that keeps switching the relay.
What does an active-LOW relay mean?
It's a relay module that turns on when its IN pin is LOW (0 V) and off when it's HIGH. Most cheap modules work this way. In code you write digitalWrite(pin, LOW) to switch it on and HIGH to switch it off; setting it HIGH first in setup() so it starts off is a good habit.
Can a relay control a DC motor?
For switching the motor on and off, yes, but you can't adjust its speed or easily change its direction. For speed control use a MOSFET or a PWM motor driver, and for direction an H-bridge such as the L298N.
What is the JD-VCC jumper for?
On optocoupler modules it separates the relay coil supply (JD-VCC) from the control supply (VCC). If you remove the jumper and give JD-VCC its own 5 V, the Arduino is fully isolated from the relay circuit and noise from loads such as motors can't reach it.
Should I buy a 5 V or a 12 V relay?
The coil voltage must match the voltage you power the module with. For Arduino projects a 5 V coil module is the most practical, because the Arduino's 5 V or a USB adapter is enough. A 12 V coil relay needs a 12 V supply; it has nothing to do with the voltage on the load side.
How many relays can one Arduino control?
Each relay needs one digital pin, and an Uno has up to 20 usable pins. The real limit is current: each coil draws about 70–80 mA, so for more than 2 relays power the module from an external 5 V adapter rather than the Arduino. For more channels there are 8- and 16-channel modules too.
Projects to build after reading this
See all projects
Lighting 220V Bulb with Push Button
As long as you hold the button, a real 220-volt bulb stays lit, and it goes out the moment you let go.

Lighting 220V Bulb with Button (On-Off)
Want to switch a real household bulb on and off with a tiny button? Each time you press the button, the Arduino flips a relay and the bulb lights up; press again and it goes off.

Lighting 220V Bulb with Remote Control
Switch a real light bulb in your home on and off with a TV remote, without getting up from the sofa.

Smart Irrigation Station
A gardener that waters your plants on its own, so they don't dry out while you're on vacation.

ESP32 Smart Lighting (PIR + LDR + Relay + OLED)
With an ESP32, a PIR motion sensor, an LDR light sensor and a relay module, we turn your hallway, bathroom or pantry into smart lighting. If the room is already bright, the light stays off even when there is motion, so it never wastes energy during the day. The light stays on for 30 seconds, and the time extends automatically while motion continues.

Automatic Lighting with the ESP32 PIR Motion Sensor
In this project an HC-SR501 PIR motion sensor detects someone entering the room and turns on an LED automatically. millis() tracks how long the LED stays on: each HIGH reading refreshes the last-motion time, and the LED turns off at least 10 seconds after the last HIGH. The code also waits 50 ms with delay(50) in every loop, so the loop is not fully non-blocking. Great for stairs, hallways, bathrooms or closet lighting.

Doorbell and Light with Motion Sensor
When someone comes up to your door, you know before they even ring. As soon as the motion sensor spots someone, the LED lights up and the buzzer plays a three-note chime from high to low; when the…
More articles
BlueGrays app
Build this circuit step by step on your phone
Wiring diagram, code and parts list on one screen. 500+ Arduino, ESP32, ESP8266, Pico, mBot and micro:bit projects ready to build.
Scan with your phone
Point your camera at the code and your phone's app store opens.
or open the store

