A 2-channel relay module is an electronic switch that allows a low voltage or current signal to control a much higher voltage and current circuit. This module contains two independent relays that can be used to control various devices like motors, lights, and other home appliances. It is commonly used in automation projects, home automation systems, and with microcontrollers such as the Arduino UNO.
Pin | Description |
---|---|
VCC | Connect to 5V power supply |
GND | Connect to ground |
IN1 | Control signal for relay 1 (active LOW or HIGH depending on the module) |
IN2 | Control signal for relay 2 (active LOW or HIGH depending on the module) |
NO1 | Normally open contact for relay 1 |
COM1 | Common contact for relay 1 |
NC1 | Normally closed contact for relay 1 |
NO2 | Normally open contact for relay 2 |
COM2 | Common contact for relay 2 |
NC2 | Normally closed contact for relay 2 |
// Define relay control pins
const int relay1Pin = 2;
const int relay2Pin = 3;
void setup() {
// Set relay pins as output
pinMode(relay1Pin, OUTPUT);
pinMode(relay2Pin, OUTPUT);
// Initialize relays to OFF (assuming LOW trigger relays)
digitalWrite(relay1Pin, HIGH);
digitalWrite(relay2Pin, HIGH);
}
void loop() {
// Turn on relay 1
digitalWrite(relay1Pin, LOW);
delay(1000); // Wait for 1 second
// Turn off relay 1
digitalWrite(relay1Pin, HIGH);
delay(1000); // Wait for 1 second
// Turn on relay 2
digitalWrite(relay2Pin, LOW);
delay(1000); // Wait for 1 second
// Turn off relay 2
digitalWrite(relay2Pin, HIGH);
delay(1000); // Wait for 1 second
}
Q: Can I control the relay module with a 3.3V signal? A: Some relay modules can be triggered with 3.3V, but it's important to check the specifications of your specific module.
Q: Is it safe to switch AC loads with the relay module? A: Yes, but ensure that you are qualified to work with AC voltages and that all safety precautions are taken.
Q: Can I use PWM to control the relay module? A: No, relays require a steady LOW or HIGH signal to switch states. PWM signals will cause erratic behavior.