Using Relays with Arduino

The maximum current per I/O pin for the ATmega328 is 40mA, according to the datasheet. This is fine for driving other digital circuits or LEDS, but for devices with higher current requirements, or that need a higher voltage, you need to use a driver with higher current and voltage capability.

If you just need to switch things on and off relatively slowly, a relay works well and has the advantage of isolating the circuit. You can also use a transistor or specialized driver IC which works well for PWM, or directional control. Most circuits using relay have at least a transistor and a diode between the microcontroller and the relay. This is because the relay coil itself usually requires >50mA, and when it is switched off, there is a back EMF which the diode protects the rest of the circuit from.

Single relay circuit


It’s possible to build up a relay driving circuit yourself, but there are a lot of cheap multi-relay boards with isolated input available these days, why not use one?

A Relay Module

A Relay Module

The module pictured here needs only a 5v power supply to switch, and has 4 active low inputs. The outputs are screw terminals with common, normally open, and normally closed terminals. It’s possible to drive the relays from a separate power supply by removing the jumper between Vcc and JDVcc, and applying 5v to JDVcc.

Current measurements:

Vcc current per channel: 1.2mA     (current into transistor)
Input current per channel: 0.9mA (current to light up the LED inside the opto-isolator)
JDVcc per channel: 57mA                (current into relay)

Output circuit

The outputs of the relay are connected like a switch and are connected in series between the device to be powered and the power supply. In the example circuit below, I have a motor wired up to the common and NO terminals to switch on when the relay is activated. If you want a device to be on except when the relay is active, use the NC terminal.

motor relay connection

The relay module inputs can be connected directly to the output pins of the Arduino. The relays will activate when the input is low (GND).

Connection to breadboard

motor 1 way

Relay board and motor connections to Arduino nano on breadboard


The sketch for the above circuit is simple, it just toggles the state of D3 every second, which will switch the 1st relay and anything connected through it, on and off.

Click here to download






Author: Paul

Share This Post On

Leave a comment