A relay module lets the Uno switch something it could never power itself — a lamp, a fan, a solenoid valve. The module has a transistor, an optocoupler and a flyback diode on board, so the Uno’s pin only lights a small LED inside the opto.
On the Uno this is easier than on an ESP32: the board’s 5 V HIGH turns the common active-LOW modules fully off, so there is none of the “relay never releases” trouble that 3.3 V boards have. What catches Uno users out is the click at reset. The pin floats for a moment before setup() runs, and an active-LOW module reads that as “on”. The sketch fixes it by writing HIGH before switching the pin to an output.
The wiring below switches a 12 V DC lamp, which is the right way to test. If you later switch 230 V, read the safety notes first — the relay part is the easy bit.
Wiring
| Arduino Uno R3 | 1-channel relay module (5 V coil) | Wire | Notes |
|---|---|---|---|
| — | COM | — | To Load supply + (start with a 12 V DC lamp) (not drawn) |
| — | NO | — | To Lamp + (lamp − back to the 12 V supply −) (not drawn) |
| 5V | DC+ | red | About 70 mA per energised coil. Fine for 1–2 relays from USB; a 4- or 8-channel board needs its own 5 V supply (common GND). |
| GND | DC− | black | |
| D7 | IN | yellow | Any digital pin. The Uno’s 5 V HIGH fully turns these modules off — no 3.3 V trigger problem here. |
5 V coil part, 5 V board. The coil runs on 5 V, but the IN pin only drives an optocoupler LED. Pick a module rated for a 3.3 V trigger when using ESP32 or Pico — some 5 V-only modules never fully release from a 3.3 V HIGH.
Board quirks
- Most blue relay modules are active-LOW:
LOWturns the relay on. The sketch writes HIGH beforepinMode(OUTPUT), so the relay doesn’t click on during reset or upload. - The relay’s contacts may be printed 10 A / 250 VAC, but the PCB tracks and screw terminals on cheap modules are not. Switch a small lamp, a fan within rating, or the coil of a contactor — never a pump or motor directly.
- Learn with a 12 V DC load first. Anything on 230 V needs an MCB and RCCB upstream, an earthed metal or closed plastic enclosure, and wiring by a licensed electrician.
- A coil switching off can reset the Uno through a dip on 5 V. Modules with the JD-VCC jumper let you power the coil side separately: remove the jumper, feed JD-VCC from a separate 5 V supply, and keep only VCC/IN from the Uno.
Code
// 1-channel 5 V relay module on an Arduino Uno R3.
// DC+ → 5V, DC− → GND, IN → D7. Most modules are active-LOW: LOW = relay ON.
// Type 1 / 0 in the Serial Monitor (9600 baud) to switch it; it also toggles every 5 s.
const uint8_t RELAY_PIN = 7;
const bool ACTIVE_LOW = true; // set false for a high-level-trigger module
bool relayOn = false;
unsigned long lastToggle = 0;
void setRelay(bool on) {
relayOn = on;
digitalWrite(RELAY_PIN, (on ^ ACTIVE_LOW) ? HIGH : LOW);
Serial.println(on ? F("Relay ON (COM-NO closed)") : F("Relay OFF (COM-NC closed)"));
}
void setup() {
// Write the OFF level before making the pin an output, so the relay
// doesn't click on for a moment at every reset.
digitalWrite(RELAY_PIN, ACTIVE_LOW ? HIGH : LOW);
pinMode(RELAY_PIN, OUTPUT);
Serial.begin(9600);
Serial.println(F("Relay on D7. Send 1 = on, 0 = off"));
}
void loop() {
if (Serial.available()) {
char c = Serial.read();
if (c == '1') setRelay(true);
if (c == '0') setRelay(false);
lastToggle = millis(); // manual control pauses the demo toggle
}
if (millis() - lastToggle >= 5000) {
lastToggle = millis();
setRelay(!relayOn);
}
}// 1-channel 5 V relay module on an Arduino Uno R3.
// DC+ → 5V, DC− → GND, IN → D7. Most modules are active-LOW: LOW = relay ON.
// Type 1 / 0 in the Serial Monitor (9600 baud) to switch it; it also toggles every 5 s.
const uint8_t RELAY_PIN = 7;
const bool ACTIVE_LOW = true; // set false for a high-level-trigger module
bool relayOn = false;
unsigned long lastToggle = 0;
void setRelay(bool on) {
relayOn = on;
digitalWrite(RELAY_PIN, (on ^ ACTIVE_LOW) ? HIGH : LOW);
Serial.println(on ? F("Relay ON (COM-NO closed)") : F("Relay OFF (COM-NC closed)"));
}
void setup() {
// Write the OFF level before making the pin an output, so the relay
// doesn't click on for a moment at every reset.
digitalWrite(RELAY_PIN, ACTIVE_LOW ? HIGH : LOW);
pinMode(RELAY_PIN, OUTPUT);
Serial.begin(9600);
Serial.println(F("Relay on D7. Send 1 = on, 0 = off"));
}
void loop() {
if (Serial.available()) {
char c = Serial.read();
if (c == '1') setRelay(true);
if (c == '0') setRelay(false);
lastToggle = millis(); // manual control pauses the demo toggle
}
if (millis() - lastToggle >= 5000) {
lastToggle = millis();
setRelay(!relayOn);
}
}Expected serial output
Relay on D7. Send 1 = on, 0 = off
Relay ON (COM-NO closed)
Relay OFF (COM-NC closed)
Relay ON (COM-NO closed)Relay on D7. Send 1 = on, 0 = off Relay ON (COM-NO closed) Relay OFF (COM-NC closed) Relay ON (COM-NO closed)
Common errors
The LED on the module lights but the relay doesn’t click
Not enough current for the coil. Check DC+ is on 5V, not 3.3V. With several relays on, use a separate 5 V supply. See relay clicks but doesn’t switch.
The relay works the wrong way round
Your module is high-level trigger (or has its jumper set to H). Set ACTIVE_LOW = false in the sketch.
The Uno resets when the relay switches
Coil kickback or an inductive load. Use the JD-VCC separate supply, add a snubber across inductive loads, and keep load wires away from the Uno.