Secure checkout on Amazon.com.tr · Amazon delivery & returns Shop Arduino Products
∞arduinoforumBRING YOUR IDEAS TO LIFE. Find My Next Deal
ARDUINO GUIDE

Arduino Relay Module Guide: How to Wire 1, 2 and 4-Channel Relays Safely

Arduino Relay Module Guide: How to Wire 1, 2 and 4-Channel Relays Safely

A relay module lets a small Arduino pin switch a much bigger load: a lamp, a pump, a fan, a door lock or a 12 V LED strip. The relay is an electrically isolated switch — the Arduino only drives the coil, and the load runs through separate contacts. This guide shows how to wire a relay module, how to program it and which mistakes to avoid.

How a relay module works

Each channel has a relay with a coil and three screw terminals:

  • COM (common) — connect one side of your load circuit here.
  • NO (normally open) — connected to COM only when the relay is on. Use this for most projects, so the load is off if the Arduino resets.
  • NC (normally closed) — connected to COM when the relay is off.

Most modules also include a transistor driver, a flyback diode and an LED for each channel, so you can connect them directly to an Arduino pin.

Wiring a relay module to Arduino

Relay module pin Arduino
VCC 5V
GND GND
IN1 (IN2, IN3, IN4) Any digital pin, for example 7

A typical 5 V relay coil draws roughly 70–90 mA. One or two channels can run from the Arduino’s 5V pin when it is powered by USB; for four or more channels, use a separate 5 V supply.

Optoisolated modules and the JD-VCC jumper

Optoisolated boards have a JD-VCC jumper. With the jumper fitted, the relays are powered from VCC. For full isolation, remove the jumper, power JD-VCC and GND from a separate 5 V supply, and connect only VCC and the IN pins to the Arduino.

Example code (active-low relay)

Many relay modules are active-low: the relay switches on when the input is LOW. Check the module’s description or test it — if the relay is on when you expect it off, swap the two constants below.

const int RELAY_PIN = 7;
const int RELAY_ON  = LOW;   // active-low module
const int RELAY_OFF = HIGH;

void setup() {
  digitalWrite(RELAY_PIN, RELAY_OFF); // set the level before enabling the output
  pinMode(RELAY_PIN, OUTPUT);
}

void loop() {
  digitalWrite(RELAY_PIN, RELAY_ON);
  delay(2000);
  digitalWrite(RELAY_PIN, RELAY_OFF);
  delay(2000);
}

Writing the OFF level before pinMode() prevents the relay from clicking on briefly at start-up.

Relay, MOSFET or solid-state relay?

  • Mechanical relay: switches AC or DC, simple and isolated. Not suitable for fast switching or PWM dimming.
  • MOSFET module: best for DC loads such as LED strips and motors, and supports PWM speed or brightness control.
  • Solid-state relay (SSR): silent and long-lasting for AC loads that switch often, but needs a heatsink at higher currents.

Safety rules

  • Mains voltage (230 V) can kill. If you are not trained to work with mains wiring, switch only low-voltage DC loads (5–24 V) and use ready-made, certified smart plugs for mains devices.
  • The contact rating printed on the relay is the maximum, not a comfortable working point. Stay well below it, especially with motors and pumps.
  • Always use a fuse in the load circuit and put the module in a closed enclosure.
  • Never let the load wiring touch the low-voltage side of the board.

Building a home automation or garden watering project? Share your wiring in the Projects & Showcase board and get feedback before you power it up.

Sources & further reading

Comments

No comments yet. Questions about this guide, or tried it yourself? Share it below.

Leave a comment