Using Relays with Arduino
The humble relay bridges the gap between Arduino’s low-voltage control world and the high-voltage realm of powering devices. This tutorial empowers you to control appliances and manage higher currents using relays with your Arduino, opening doors to various automation projects.
An Arduino relay isn’t a single component, but rather a combination of two parts:
- Relay: An electromechanical switch that uses a small control current from the Arduino to activate a coil. This coil triggers the physical opening or closing of contacts within the relay, allowing you to control a separate high-power circuit.
- Relay module: This simplifies the connection between the Arduino and the relay. It typically includes the relay itself, a driver circuit, and connection terminals. The driver circuit allows the Arduino’s low-voltage signal to control the relay coil.
Specifications to Consider:
- Control voltage: This is the voltage required by the relay module’s driver circuit to activate the relay coil. It’s usually 5V, compatible with the Arduino’s power output.
- Control current: This is the amount of current the Arduino’s digital pin can provide to activate the relay coil. Make sure your Arduino can provide enough current for the chosen relay module.
- Switching voltage and current: This refers to the maximum voltage and current the relay itself can handle in the high-power circuit you’re controlling (e.g., powering an appliance). It’s crucial to choose a relay with specifications exceeding the appliance’s requirements to ensure safe operation.
Relay Pinout
A relay has two groups of pins: input (low voltage) and output (high voltage). Here’s how they connect:
- Input Group (Connected to Arduino):
- DC- pin: Connect to GND (0V).
- DC+ pin: Connect to VCC (5V).
- IN pin: Receives the control signal from Arduino.
- Output Group (Connected to High Voltage Device):
- COM pin: Common pin used in both normally open (NO) and normally closed (NC) modes.
- NO pin: Normally open pin (used in NO mode).
- NC pin: Normally closed pin (used in NC mode).
Arduino Uno
Breadboard
Relay
Led
Cables
// constants won't change const int RELAY_PIN = 3; // the Arduino pin, which connects to the IN pin of relay // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin 9 as an output. pinMode(RELAY_PIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(RELAY_PIN, HIGH); delay(1000); digitalWrite(RELAY_PIN, LOW); delay(1000); }
Enhancing Your Project:
- Modify the code to control the relay state based on sensor readings (e.g., turn on a light when a motion sensor detects movement).
- Explore using multi-channel relay modules to control multiple appliances simultaneously.
- Integrate relays into home automation projects for remote appliance control.
Remember: Safety is paramount when working with high-voltage appliances. Ensure you understand relay specifications and electrical safety practices before implementing them in your projects.
This tutorial empowers you to leverage relays to control appliances with your Arduino. With a relay and some creative coding, you can automate tasks and add a layer of control to various applications!