How to wire a relay module to an Arduino Uno R4
To wire a relay module to an Arduino Uno R4, connect VCC to 5V, GND to GND and IN to pin 2. The Arduino Uno R4 drives IN at 5 V and the module’s own transistor carries the coil current, so the pin only supplies a few milliamps. The sketch below uses no library beyond what the board includes. It switches the relay on for a second and off for a second, printing a line each time.
- 5 V logic
- Library: none
- 3 wires
Relay module to Arduino Uno R4 wiring table
Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.
| Relay module pin | Arduino Uno R4 pin | Wire color | Why |
|---|---|---|---|
| VCC | 5V | red | The coil is a 5 V coil; it takes about 70 mA, more than any pin can give. |
| GND | GND | blue | Common ground. |
| IN | pin 2 | amber | A logic signal only: the module’s transistor switches the coil. |
| COM, NO, NC | The load | n/a | The switched side: COM is the arm, NO is open until the relay pulls in, NC is closed until then. |
Power and logic levels for relay module and Arduino Uno R4
Logic level
The Arduino Uno R4’s pins are 5 V logic. A 5 V part can drive them directly; a part whose signal pins are limited to 3.3 V needs a level shifter.
Supply
The relay module takes 5 V from 5V. That is the Arduino Uno R4’s 5 V rail, so the part shares the current the board can supply.
This pair
The Arduino Uno R4 drives IN at 5 V and the module’s own transistor carries the coil current, so the pin only supplies a few milliamps. The simulated relay triggers on HIGH; many blue modules trigger on LOW, set by the part’s trigger property.
Pins to leave alone
An Uno sketch’s source builds for the R4, but a compiled Uno program will not run on it: different chip. The R4’s pins source less current than an Uno’s, about 8 mA each, so do not drive a relay coil or a motor straight from one.
The working code for the Arduino Uno R4
Library: none, the sketch drives IN with digitalWrite(). This is the sketch the circuit above runs.
const int RELAY_PIN = 2; // IN, pin 2
void setup() {
Serial.begin(9600);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW); // released at start
}
void loop() {
digitalWrite(RELAY_PIN, HIGH); // pull in: COM to NO
Serial.println("Relay on");
delay(1000);
digitalWrite(RELAY_PIN, LOW); // release: COM back to NC
Serial.println("Relay off");
delay(1000);
}
What you should see
The relay clicks closed and open. The serial monitor, at 9600 baud, prints Relay on when the coil is energized and Relay off when it is released.
The switched side, COM, NO and NC, is isolated from the board: wire the load there, never to the board’s pins.
The serial monitor prints this, recorded from the circuit above running for two and a half seconds:
Relay on
Relay off
Relay onCommon mistakes wiring a relay module to an Arduino Uno R4
Active low modules
Many cheap relay boards switch when IN goes LOW, so the sketch seems inverted and the relay is on at boot. Check the board, and in the editor set the relay’s trigger property to low to match.
Driving a coil straight from a pin
A bare relay coil wants 70 mA or more and kicks back a voltage spike when it releases. On a module the transistor and the flyback diode are already there; a bare relay needs both, and never a direct pin.
Expecting an Uno’s pin current
The R4’s pins are 5 V like an Uno’s, but each one sources only about 8 mA where an Uno’s gives 20. A signal line to the relay’s IN pin is fine; an LED or a coil hung straight off the pin is not.
Build your own relay module project
Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.