Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Arduino & Microcontrollers

How to Use Relay Module with Arduino (1, 2, 4, 8 Channel)

How to Use Relay Module with Arduino (1, 2, 4, 8 Channel)

March 11, 2026 /Posted byJayesh Jain / 0

An Arduino relay module is the bridge between the low-voltage world of microcontrollers and real-world AC appliances like lights, fans, and water pumps. With a relay, your Arduino can switch devices running on 230V mains – the standard voltage in India – just as easily as it blinks an LED. In this tutorial we explain how relays work, cover all channel variants (1, 2, 4, 8 channel), explain the optocoupler isolation that makes them safe, and provide real working code for home automation basics.

SAFETY WARNING: Mains voltage (230V AC in India) is lethal. Always disconnect power before wiring relay circuits. Use an enclosure for all mains connections. Keep AC and DC wiring separated. If you are not confident working with mains voltage, use a low-voltage DC load (12V LED strip, motor, etc.) to learn relay control first. Never touch relay terminals while the circuit is powered.

Table of Contents

  • What is a Relay and How Does it Work?
  • Types: 1, 2, 4, and 8 Channel Relay Modules
  • Optocoupler Isolation Explained
  • Wiring Relay Module to Arduino
  • Arduino Code Examples
  • Controlling AC Appliances Safely
  • Home Automation Basics
  • Frequently Asked Questions

What is a Relay and How Does it Work?

A relay is an electrically operated switch. Inside the relay module is a small electromagnetic coil. When your Arduino sends a signal to activate the relay, current flows through the coil, generating a magnetic field that physically moves a switch arm (the armature) to make or break a circuit. This means your 5V Arduino signal can safely switch a completely separate 230V AC circuit without any direct electrical connection between the two.

The relay has three contact terminals on the high-voltage side:

  • COM (Common) – the common terminal, always connected to your load’s power supply
  • NO (Normally Open) – open circuit when relay is off, connected to COM when relay is on
  • NC (Normally Closed) – connected to COM when relay is off, open circuit when relay is on

For controlling a light or fan, you wire COM to the live wire from the mains, and NO to the appliance. When Arduino activates the relay, COM connects to NO and power reaches the appliance. When deactivated, the circuit opens and the appliance turns off.

Types: 1, 2, 4, and 8 Channel Relay Modules

Relay modules are sold in 1, 2, 4, and 8 channel variants. Each channel controls one independent load. Choose based on how many appliances you need to control:

Module Channels Control Pins Best For
1 Channel 1 1 digital pin Single appliance, simple switch
2 Channel 2 2 digital pins Light + fan control
4 Channel 4 4 digital pins Room automation, multiple zones
8 Channel 8 8 digital pins Full home automation, 8-appliance control

All variants work identically – more channels just mean more relays on the same board sharing common VCC and GND connections. A 4-channel module is the sweet spot for most projects: enough channels for a living room (light, fan, TV power, AC control) while staying compact and affordable.

Recommended: 4 Channel 5V Relay Module – The most popular relay module in India for Arduino home automation projects, includes optocoupler isolation on each channel.

Optocoupler Isolation Explained

Quality relay modules include optocouplers (also called optoisolators) between the Arduino’s control signal and the relay coil. An optocoupler uses an LED and a phototransistor in the same package. Your Arduino signal lights the LED, and the phototransistor detects the light and switches the relay coil — with complete electrical isolation between input and output.

Why does this matter? Without optocoupler isolation, voltage spikes from the relay coil’s collapsing magnetic field can damage the Arduino’s digital output pins. With isolation, even if something goes wrong on the relay side, your microcontroller is protected. Always prefer relay modules with optocouplers, identified by small rectangular ICs (usually PC817 or EL817) next to each relay.

Most 5V relay modules use active LOW triggering with optocouplers: write LOW to the control pin to activate the relay, HIGH to deactivate. Some modules (rare) are active HIGH. Check your module’s datasheet or the silk screen markings to confirm.

Wiring Relay Module to Arduino

A standard 4-channel 5V relay module has these connections:

  • Module VCC to Arduino 5V (or external 5V supply – see power note below)
  • Module GND to Arduino GND
  • Module IN1 to Arduino Digital Pin 2
  • Module IN2 to Arduino Digital Pin 3
  • Module IN3 to Arduino Digital Pin 4
  • Module IN4 to Arduino Digital Pin 5

Power supply note: Each relay coil draws 70-100mA when active. An Arduino Uno’s 5V pin can supply about 400mA from USB, which means all 4 relays active simultaneously (400mA total) is right at the limit. For reliable operation, power the relay module from an external 5V power supply (like a phone charger with 5V output via the module’s VCC), and connect only the GNDs together. This is especially important for 8-channel modules.

Some relay modules have a separate VCC and JD-VCC (jumper-selectable) that allows powering the relay coils from a different supply than the optocoupler logic side. Removing the JD-VCC jumper and powering each side separately gives maximum isolation and protects your Arduino even further.

Arduino Code Examples

Since most relay modules are active LOW, you activate a relay by writing LOW and deactivate with HIGH. This is the opposite of what beginners expect, so it catches many people off guard.

// Single Channel Relay - Basic Control
const int RELAY_PIN = 2;

void setup() {
  pinMode(RELAY_PIN, OUTPUT);
  // Initialize HIGH = relay OFF (active LOW module)
  digitalWrite(RELAY_PIN, HIGH);
  Serial.begin(9600);
  Serial.println("Relay Module Ready");
}

void loop() {
  // Turn relay ON
  Serial.println("Relay ON - appliance energized");
  digitalWrite(RELAY_PIN, LOW);   // LOW activates relay
  delay(2000);

  // Turn relay OFF
  Serial.println("Relay OFF - appliance de-energized");
  digitalWrite(RELAY_PIN, HIGH);  // HIGH deactivates relay
  delay(2000);
}

For a 4-channel module controlling multiple loads:

// 4-Channel Relay Module Example
// Active LOW: LOW = relay ON, HIGH = relay OFF

const int RELAY1 = 2;  // Living room light
const int RELAY2 = 3;  // Ceiling fan
const int RELAY3 = 4;  // Table lamp
const int RELAY4 = 5;  // TV power socket

const int relayPins[] = {RELAY1, RELAY2, RELAY3, RELAY4};
const int NUM_RELAYS = 4;

void setup() {
  // Initialize all relays OFF before anything else
  for (int i = 0; i < NUM_RELAYS; i++) {
    pinMode(relayPins[i], OUTPUT);
    digitalWrite(relayPins[i], HIGH);  // HIGH = OFF for active LOW
  }
  Serial.begin(9600);
  Serial.println("4-Channel Relay Ready");
}

// Helper functions
void relayOn(int pin)  { digitalWrite(pin, LOW);  }
void relayOff(int pin) { digitalWrite(pin, HIGH); }

void loop() {
  // Turn all relays on one by one
  for (int i = 0; i < NUM_RELAYS; i++) {
    relayOn(relayPins[i]);
    Serial.print("Relay ");
    Serial.print(i + 1);
    Serial.println(" ON");
    delay(1000);
  }
  delay(2000);

  // Turn all relays off one by one
  for (int i = 0; i < NUM_RELAYS; i++) {
    relayOff(relayPins[i]);
    Serial.print("Relay ");
    Serial.print(i + 1);
    Serial.println(" OFF");
    delay(1000);
  }
  delay(2000);
}

Controlling AC Appliances Safely

When you are ready to wire mains voltage (only after testing with DC loads first), follow this procedure carefully. In India, standard mains is 230V AC 50Hz. The wiring uses three wires: Live (L, red or brown), Neutral (N, black or blue), and Earth (E, green/yellow).

Safe AC wiring procedure:

  1. Disconnect all power before wiring. Verify with a multimeter that voltage is zero.
  2. Mount everything in a suitable plastic enclosure. Never leave bare mains connections exposed.
  3. Connect the Neutral wire directly from the power source to the appliance (Neutral is not switched).
  4. Connect the Live wire from the power source to the COM terminal of the relay.
  5. Connect the NO (Normally Open) terminal of the relay to the Live wire of the appliance.
  6. Earth the enclosure and appliance chassis if applicable.
  7. Use wire rated for mains voltage (minimum 0.75mm2 for up to 6A, 1.5mm2 for up to 10A).
  8. Double-check all connections before reconnecting power.
IMPORTANT SAFETY: Use a properly rated relay for your load. Standard blue relay modules use SRD-05VDC-SL-C relays rated 10A/250VAC or 10A/125VAC. Do not exceed 10A load per relay. For high-power appliances (ACs, geysers, pumps above 1000W), use contactor relays rated appropriately. Have an electrician verify your first mains-voltage installation.
Recommended: ESP8266 WiFi 8 Channel Relay Module (ESP-12F) – Combines WiFi and 8 relays on one board for complete smart home control without a separate Arduino, controllable from anywhere via your phone.

Home Automation Basics

With a relay module and Arduino, you can build practical home automation projects. Here are the most popular implementations among Indian makers:

Time-Based Control

Add a DS3231 RTC module to your relay project and schedule appliances by time of day. Turn on garden lights at 6pm and off at 6am automatically, without any manual intervention. This is one of the most practical and energy-saving automation projects.

// Conceptual time-based relay control with DS3231 RTC
#include <RTClib.h>
RTC_DS3231 rtc;

const int LIGHT_RELAY = 2;

void setup() {
  pinMode(LIGHT_RELAY, OUTPUT);
  digitalWrite(LIGHT_RELAY, HIGH); // Start OFF
  rtc.begin();
}

void loop() {
  DateTime now = rtc.now();
  int hour = now.hour();

  // Turn light ON from 6pm (18:00) to 6am (6:00)
  if (hour >= 18 || hour < 6) {
    digitalWrite(LIGHT_RELAY, LOW);   // ON
  } else {
    digitalWrite(LIGHT_RELAY, HIGH);  // OFF
  }
  delay(30000); // Check every 30 seconds
}

Sensor-Triggered Control

Combine a relay with a DHT11/DHT22 temperature sensor to make a thermostat: turn on a fan when temperature exceeds 30 degrees C and off when it drops below 28. Add a soil moisture sensor to automate watering your balcony garden. These sensor-relay combinations form the basis of real smart home automation.

Serial/Bluetooth Control

Add an HC-05 Bluetooth module to control relays from your smartphone. Map characters (‘1’ = relay 1 on, ‘A’ = relay 1 off) and use a free Bluetooth terminal app or a custom MIT App Inventor app to send commands. This is the most popular beginner home automation project in India because it requires no internet or cloud service.

Frequently Asked Questions

Q: Why does my relay click ON when the Arduino first powers up?

This is the floating pin problem. Before your setup() function runs, digital pins are in INPUT mode with undefined states that can briefly go LOW, triggering active-LOW relays. Fix this by using Arduino’s EEPROM or by adding a 10k pull-up resistor from the relay’s IN pin to 5V. Better yet, switch to the ESP8266/ESP32 platform where you can set pin states in the boot configuration to prevent this issue entirely.

Q: Can I use a 3.3V Arduino (ESP32, ESP8266) with a 5V relay module?

Yes, in most cases. The optocoupler input on most relay modules can be triggered by 3.3V signals even though the module runs on 5V, because the optocoupler LED typically needs only 1.2-2V to conduct. However, for guaranteed reliability, use a level shifter or choose a relay module specifically rated for 3.3V control input. The ESP8266 WiFi 8-channel relay board is designed for exactly this use case.

Q: What is the difference between NO and NC terminals on the relay?

NO (Normally Open) means the circuit between COM and NO is open (disconnected) when the relay is not energized. Energizing the relay closes this circuit. NC (Normally Closed) is the opposite – it is connected when the relay is off and disconnects when energized. For controlling appliances that should be off by default (lights, fans), use COM-NO wiring. For safety systems that should activate on power failure, use COM-NC.

Q: My relay clicks but the appliance does not turn on. What is wrong?

Check that you are using the NO terminal and not NC. Use a multimeter in continuity mode to verify the COM-NO connection closes when you activate the relay. Also verify that the neutral wire goes directly to the appliance without passing through the relay. A common wiring mistake is switching neutral instead of live – the appliance remains live even when the relay is open, which is also a safety hazard.

Q: How do I protect my circuit from relay coil back-EMF?

Quality relay modules already include a flyback diode across the coil for exactly this purpose. If you are using a bare relay (not a module), add a 1N4007 diode in reverse-bias across the coil terminals. Without this protection, the voltage spike when the relay de-energizes can damage transistors and microcontroller pins over time.

Ready to Build Your Next Arduino Project?

Shop sensors, modules, and components at Zbotic.in – India’s trusted electronics store with fast shipping across India.

Browse Arduino Products

Tags: 4 channel relay, arduino ac control, arduino relay module, home automation arduino, optocoupler relay, relay module
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
How to Use Arduino with Motor ...
blog how to use arduino with motor driver l298n step by step 594476
blog how to build a raspberry pi nas network storage 594483
How to Build a Raspberry Pi NA...

Related posts

Svg%3E
Read more

Arduino Batch Programming: Flash Multiple Boards Quickly

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Based Radar System with Ultrasonic Sensor

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Automatic Plant Monitor: Sunlight, Moisture, Temperature

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Lie Detector: GSR Sensor Polygraph Project

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Metal Detector: Build a Treasure Finder

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading

Add comment Cancel reply

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

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now