How to wire a relay module to an Arduino Nano
To wire a relay module to an Arduino Nano, connect VCC to 5V, GND to GND and IN to pin 2. The Arduino Nano 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 Nano 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 Nano 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 Nano
Logic level
The Arduino Nano’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 Nano’s 5 V rail, so the part shares the current the board can supply.
This pair
The Arduino Nano 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
A6 and A7 are analog only: pinMode(A6, OUTPUT) does nothing and digitalRead(A7) is not there to call. D0 and D1 are the USB serial port.
The working code for the Arduino Nano
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 Nano
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.
Switching mains without care
The contacts are rated for mains, but the board and the screw terminals are not a safe enclosure. Learn on a 12 V lamp or a motor, and leave mains to a properly rated, enclosed module.
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.