Interfacing a relay module with Arduino
A relay module is an electronic circuit that uses a small electrical current to control a larger electrical current. This is done by using an electromagnet to switch the connections between two or more terminals. Relay modules are often used to control high-voltage or high-current devices from a low-voltage or low-current source.
working of relay module
A relay module typically has five terminals:
- COM (common): This is the terminal that is always connected to either the NC or NO terminal, depending on the state of the relay.
- NC (normally closed): This terminal is connected to the COM terminal when the relay is not activated.
- NO (normally open): This terminal is not connected to the COM terminal when the relay is not activated.
- COIL1 and COIL2 (coil): These terminals are connected to the power supply that energizes the electromagnet.
When a voltage is applied to the coil terminals, the electromagnet is activated and the contacts switch position. This connects the COM terminal to either the NC or NO terminal, depending on the design of the relay module.

code
A relay module can be easily interfaced with an Arduino using the digital I/O pins. The following code shows how to do this:
C++
// Define the relay pin
int relayPin = 8;
void setup() {
// Set the relay pin as an output
pinMode(relayPin, OUTPUT);
}
void loop() {
// Turn on the relay
digitalWrite(relayPin, HIGH);
delay(5000);
// Turn off the relay
digitalWrite(relayPin, LOW);
delay(5000);
}
Use code with caution. Learn morecontent_copy
This code will turn the relay on for 5 seconds, then off for 5 seconds, repeatedly. The digitalWrite()
function takes two arguments: the pin number and the desired state. A value of HIGH
turns the pin on, and a value of LOW
turns the pin off.
More complex relay control
The code above is a simple example of how to control a relay with an Arduino. However, it is possible to do more complex things with relay modules. For example, you could use a relay module to control a motor, a light bulb, or any other device that requires a high-voltage or high-current input.
You could also use multiple relay modules to control multiple devices. For example, you could use one relay module to control a light bulb and another relay module to control a motor.
Conclusion
Relay modules are a versatile tool that can be used to control a wide variety of devices. They are easy to interface with Arduino and other microcontrollers, and they can be used to do a variety of tasks.