Introduction
A relay module is the bridge between your Arduino’s low-voltage world (5V) and high-voltage appliances (230V AC). It uses an electromagnet to physically switch high-power circuits on and off under microcontroller control — allowing you to turn on/off bulbs, fans, water pumps, and heaters with just a GPIO pin.
Important Safety Warning
Warning: Working with 230V AC mains electricity is dangerous and potentially lethal. Ensure you are using a proper enclosure and following electrical safety guidelines. If you are not confident, ask a qualified electrician for help.
Components Needed
- Arduino Uno
- 5V Relay Module (1-channel or 4-channel)
- An appliance to control (lamp recommended for testing)
Wiring the Relay
| Relay Module Pin | Arduino |
|---|---|
| VCC | 5V |
| GND | GND |
| IN | Digital Pin 7 |
Project 1: Basic Relay Control
#define RELAY_PIN 7
void setup() {
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH); // Most relay modules are active LOW - HIGH = OFF
}
void loop() {
digitalWrite(RELAY_PIN, LOW); // Relay ON (appliance ON)
delay(5000);
digitalWrite(RELAY_PIN, HIGH); // Relay OFF (appliance OFF)
delay(5000);
}
Project 2: Timer-Controlled Fan
#define RELAY_PIN 7
void setup() {
Serial.begin(9600);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH); // Start OFF
}
void loop() {
Serial.println("Fan ON for 10 seconds...");
digitalWrite(RELAY_PIN, LOW); delay(10000);
Serial.println("Fan OFF for 5 seconds...");
digitalWrite(RELAY_PIN, HIGH); delay(5000);
}
Understanding Active LOW vs Active HIGH
Most relay modules are Active LOW — sending a LOW signal triggers the relay (connects COM to NO). Always check your module’s datasheet. Writing HIGH to IN means OFF, and LOW means ON.
Conclusion
The relay module is one of the most powerful tools in the maker toolkit. Combined with ESP32 Wi-Fi and MQTT, you can build a full smart home automation system that controls real appliances from your phone!