Back to Basic Projects

🔌 Relay Module Switch

Safely control 230V AC appliances from a 5V Arduino signal using a relay module — understand high-voltage isolation.

📋 Overview

A relay is an electrically operated switch. A small Arduino signal energizes an internal electromagnet, which physically flips a metal contact to connect or disconnect a high-power circuit — giving total isolation between the low-voltage control side and the mains AC side.

Technical Insight: The relay module includes a BC817 transistor driver, 1N4148 flyback protection diode, and LED indicator. When Arduino drives the IN pin LOW (active-low), the transistor switches 75mA through the relay coil, pulling the armature and switching contacts rated at 10A/250VAC — a 1000× current amplification from a 10mA Arduino output.

In simple terms: Think of the relay as a TV remote controlling your TV. The small remote signal (Arduino) controls the big device (230V appliance) without ever touching its high-voltage wiring.

What you'll learn: Relay module wiring (NO/NC/COM), flyback diode importance, active-low vs active-high control logic, timed on/off scheduling, and high-voltage safety practices.

Estimated time: 30-40 minutes. Difficulty: ⭐⭐ Easy — but requires caution with the AC side.

🧩 Components Needed

ComponentSpecificationQtyNotes
Arduino Uno R35V1
5V Relay Module1-channel, SRD-05VDC-SL-C1With built-in driver
LED + Resistor220Ω, any color1Simulate AC load (safe demo)
Push ButtonMomentary SPST1Manual trigger (optional)
Breadboard + WiresHalf-size1

🗺️ Component Pin Mapping

Relay Module Switch Component Pin Mapping Infographic

📖 Step-by-Step Tutorial

1

Wire Control Side

Relay module: VCC → 5V, GND → GND, IN → Arduino pin 7. Most modules are ACTIVE-LOW, so LOW = relay energized.
2

Connect LED Load (Safe Demo)

Wire an LED (with 220Ω resistor) between relay COM and NO terminals, other end to 5V. The LED lights when relay is ON.
3

Upload Blink-Relay Code

Upload the code. The relay will click ON for 2 seconds, OFF for 2 seconds repeatedly.
4

AC Wiring (Advanced – supervised only)

For AC: Cut the live wire of an appliance cord. Wire one end to COM, other end to NO. Neutral goes directly. ALWAYS unplug before wiring!
5

Add Button Control

Connect a push button to pin 3 and add button-read logic to toggle the relay on/off manually.
💡
SAFETY FIRST: When working with the AC mains side, always unplug the cord before making any connections. Use proper insulated crimp connectors, not bare wires, and keep the AC wiring covered with insulating tape. Never touch the AC side while powered.

💻 Arduino Code

relay_switch.ino
INO
// Relay Switch — Volt X
// Relay IN pin is ACTIVE-LOW (LOW = relay ON)

const int RELAY_PIN = 7;
const int BTN_PIN   = 3;

bool relayState = false;
bool lastBtn    = HIGH;

void setup() {
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(BTN_PIN, INPUT_PULLUP); // Use internal pull-up
  digitalWrite(RELAY_PIN, HIGH);  // Start with relay OFF (active-low)
  Serial.begin(9600);
  Serial.println("Relay Switch — Volt X");
}

void loop() {
  bool btn = digitalRead(BTN_PIN);
  
  // Toggle on button press (falling edge)
  if (btn == LOW && lastBtn == HIGH) {
    relayState = !relayState;
    digitalWrite(RELAY_PIN, relayState ? LOW : HIGH); // active-low
    Serial.println(relayState ? "Relay ON" : "Relay OFF");

Reviews & Ratings

0 reviews
5★
0
4★
0
3★
0
2★
0
1★
0
...

Loading reviews...