Arduino Uno R4 · Relay

Arduino Uno R4 Relay Simulator: Wiring, Code and a Live Circuit

This is a single-channel 5 V relay module wired to an Arduino Uno R4 Minima, clicking on and off once a second live in your browser. The arm on the drawing moves between NC and NO as the board switches it.

VCC to 5V, GND to GND, and IN to pin 2. The pin only gives the signal; the module powers the coil.

  • 5 V logic
  • No library
  • IN on pin 2
  • Coil on 5V
Arduino Uno R4 · Relaylive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.

Wiring the Relay to the Arduino Uno R4

Every connection in the circuit above, with the board’s own pin names.

Relay pinArduino Uno R4 pinWhy
VCC5VThe coil is a 5 V coil; it takes about 70 mA, more than any pin can give.
GNDGNDCommon ground.
INpin 2A logic signal only: the module’s transistor switches the coil.
COM, NO, NCThe loadThe switched side: COM is the arm, NO is open until the relay pulls in, NC is closed until then.

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 on the Arduino Uno R4

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.

On a real bench

The Uno R4 Minima fits every Uno shield and every Uno breadboard layout, so wire the Relay exactly as you would on an Uno R3. It has a USB-C socket, and its VIN accepts up to 24 V where an Uno R3 stops at 12.

The code

The sketch the circuit above runs. Open it in the editor, change a line and press Run: it compiles in your browser.

Relay on Arduino Uno R4 pin 2
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);
}

digitalWrite(RELAY_PIN, HIGH) turns on the module’s transistor, which energizes the coil and pulls the arm from NC over to NO about 10 ms later. LOW lets it fall back.

The relay is off at the start because setup() writes LOW before anything else. Do the same in a real project, so the load does not flick on while the board boots.

Serial.begin(9600) opens the serial monitor. Serial is the USB port; Serial1 is on pins 0 and 1, which on the R4 are free for other serial devices.

Common mistakes with the Relay on the 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.

Questions and answers

Can I simulate a relay with an Arduino Uno R4 Minima?

Yes. The circuit at the top of this page is an Arduino Uno R4 Minima with a relay module, running in your browser on a simulated Renesas RA4M1 (Cortex-M4). The simulated relay has a pull-in and release time, and its contacts really connect COM to NO or NC, so a lamp wired through it switches. Press Run it in the editor to change the wiring or the code; it is free and needs no account.

Can the pin power the relay?

No: a pin gives about 20 mA and the coil wants more. The module’s transistor does the switching; the pin only drives the transistor.

What do NO and NC mean?

Normally open and normally closed. With the coil off, COM is connected to NC; with it on, COM is connected to NO. Wire a load to NO to have it off until the relay switches.

How fast can a relay switch?

A few times a second at most. It takes about 10 ms to pull in and its contacts wear with every click, so for anything faster, or for dimming, use a MOSFET.

Build your own Relay project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.