December 5, 2026

Driving a Relay From an Arduino: Coil Current, the Transistor, and the Base Resistor That’s Too Big

A microcontroller board wired to a relay module controlling a small lamp

A common 5-volt relay, the Songle SRD-05VDC-SL-C found on countless hobby boards, has a 70-ohm coil that draws about 71 milliamps. An Arduino Uno output pin is meant for about 20. That mismatch is why a relay almost never connects straight to a microcontroller pin, and why nearly every relay circuit has the same three supporting parts: a transistor to carry the coil current, a resistor to drive the transistor, and a diode to catch the spike when the coil turns off. A set of circuit simulations for this post shows what each part does, and what happens when the resistor is picked wrong.

Video: Julian Ilett on YouTube

What the relay needs

The datasheet numbers

The Songle SRD datasheet, hosted by Components101, gives the 5-volt coil a nominal current of 71.4 mA and a resistance of 70 Ω, with coil power of about 0.36 W. Two more figures matter as much: a pull-in voltage of “75% Max.” and a drop-out voltage of “10% Min.” The coil is guaranteed to pull the contacts in once it sees 75% of its rated voltage, 3.75 volts for this 5 V part, and guaranteed to release once it drops to 10%, half a volt.

What the contacts can switch

The same datasheet’s contact table rates the changeover version at 10 A at 250 VAC and 10 A at 30 VDC for resistive loads, with lower figures for inductive loads such as motors. Those ratings are for the relay itself. The PCB traces, screw terminals and wiring on a cheap module may not carry anything like 10 amps safely, and switching mains voltage is a job for an enclosure, a fuse and someone who knows the local electrical code.

Blue circuit board

Why not straight from the pin

The current limit

Arduino’s Uno documentation, summarized on the Uno’s Wikipedia page, lists “DC Current per I/O Pin: 20 mA” and says each pin can provide or receive 20 mA “as the recommended operating condition.” The ATmega328P’s absolute maximum is 40 mA per pin, as the ArduinoInfo wiki lists from the chip’s specifications, alongside “Good Design Value is 20.0 mA.”

A 71 mA coil is more than three times the recommended figure and well past the absolute maximum. Connecting it directly might click the relay a few times. It also stresses the pin and the chip’s internal wiring well beyond its ratings, and the voltage spike at turn-off goes straight into the microcontroller.

The fix: a switch that can take the current

An NPN transistor such as the 2N3904, rated by onsemi’s datasheet for 40 V and 200 mA continuous collector current, sits between the coil and ground. The Arduino pin only has to supply a small base current; the transistor carries the coil current.

Choosing the base resistor

The simulation

An ngspice model of a 2N3904 switching the 70 Ω coil from 5 volts, with the base driven from a 5 V logic output through different resistors, gave:

Base resistor Base current (from the pin) Coil current Voltage across transistor
220 Ω 18.2 mA 69.4 mA 0.14 V
1 kΩ 4.2 mA 68.9 mA 0.18 V
4.7 kΩ 0.89 mA 68.1 mA 0.23 V
10 kΩ 0.42 mA 53.8 mA 1.23 V
47 kΩ 0.09 mA 15.0 mA 3.95 V

Saturated versus starved

With 220 Ω, 1 kΩ or 4.7 kΩ, the transistor is fully on, or saturated. It drops only a fraction of a volt, and the coil gets almost all of the 5 volts. With 1 kΩ, the pin supplies about 4 mA, comfortably within its 20 mA recommendation.

At 10 kΩ, the transistor isn’t fully on. It holds 1.23 V across itself, leaving the coil 3.77 V, just over the 3.75 V the datasheet guarantees will pull the relay in. That relay might click on the bench and fail on a cold day, a slightly low supply or a weaker-than-typical transistor. At 47 kΩ, the coil sees barely a volt, nowhere near enough.

The rule of thumb behind it

A transistor used as a switch needs much more base current than its gain alone would suggest, because the gain falls when it’s driven hard into saturation. Designers commonly aim for a base current around a tenth to a twentieth of the collector current. For a 70 mA coil, that’s 3.5 to 7 mA, which lands right on the 1 kΩ row. The transistor also dissipates very little when saturated: 69 mA times 0.18 V is about 12 milliwatts.

A MOSFET instead

A small N-channel MOSFET such as the 2N7000 does the same job with a different drive requirement: its gate draws essentially no steady current, so there’s no base resistor to size, only a small series resistor if desired and a pull-down to keep it off while the microcontroller boots. In a simplified ngspice model of a 2N7000-class part (threshold about 2.1 V), a 5 V gate drive gave 68.6 mA through the coil with 0.20 V across the MOSFET, and a 3.3 V gate gave 66.4 mA with 0.35 V. Both energize the coil comfortably. The 3.3 V result matters for boards like the ESP32 or Raspberry Pi Pico, whose pins never reach 5 volts. A real part’s datasheet gate-threshold spread decides how much margin a given board actually has.

Black and white electric meter

The flyback diode

Why it’s there

A relay coil is an inductor, and an inductor resists sudden changes in current. When the transistor switches off, the coil tries to keep current flowing and produces whatever voltage it takes to do so, pushing it across the transistor. Without protection, that spike can exceed the 2N3904’s 40 V rating many times over.

Where it goes

A diode across the coil, cathode to the positive supply and anode to the transistor’s collector, gives that current a path to circulate harmlessly. During normal operation it’s reverse-biased and does nothing. At turn-off, it clamps the collector to about one diode drop above the supply. A small-signal 1N4148 or a 1N4007 rectifier both work for a coil this size, and either should sit right across the coil’s pins.

The slower release

With the diode in place, the coil current decays through the diode and coil resistance rather than collapsing instantly, so the relay contacts open a few milliseconds later. For switching a lamp or a pump, that delay doesn’t matter. Faster-release circuits add a Zener diode or resistor in series with the flyback diode, at the cost of a higher clamp voltage.

Relay modules and their quirks

What’s already on the board

Prebuilt relay modules for microcontrollers usually include the transistor, base resistor, flyback diode and an indicator LED, so they connect directly to a logic pin. The datasheet figures still apply to the relay itself, and it’s worth confirming the diode is present by looking at the board before relying on it.

Inputs that work backward

Many multi-channel modules are “active low”: the relay turns on when the input pin is pulled low, not high. A sketch that writes HIGH to turn a light on will find it does the opposite. Checking the module’s documentation, or simply testing with a single digitalWrite, avoids a confusing first afternoon. Setting the pin’s state before switching it to an output also avoids a brief click at power-up.

Separate power for the coils

Some modules include an optocoupler and a jumper that allows the relay coils to run from a separate 5 V supply. Several relays switching together can draw a few hundred milliamps, enough to sag a USB-powered board’s supply and reset the microcontroller. A separate supply for the coils, with the grounds handled as the module’s documentation describes, keeps the logic side stable.

A 3D render of an electronic module with wires connected

A worked checklist

Before wiring

  1. Read the coil current from the relay’s datasheet: 71.4 mA for the 5 V SRD.
  2. Pick a transistor rated well above that current and the supply voltage: a 2N3904 at 200 mA and 40 V has margin.
  3. Size the base resistor for roughly a tenth of the coil current: 1 kΩ from a 5 V pin gives about 4 mA.
  4. Put a diode across the coil, cathode to positive.
  5. Check the contact ratings against the load, and keep mains wiring enclosed and fused.

After wiring

A multimeter across the coil while it’s energized should read close to the full supply voltage. If it reads well under 4 volts for a 5 V relay, the transistor isn’t saturating, and the base resistor is the first thing to check. That one measurement would have caught the 10 kΩ case in the table, where the relay sat just 20 millivolts above the edge of not working at all.

Parts for the circuit

The components in this post, as sold in hobby quantities:

As an Amazon Associate I earn from qualifying purchases. A commission may be earned if you buy through this link, at no extra cost to you.

Sources

  • Songle SRD series relay datasheet (via Components101): https://components101.com/sites/default/files/component_datasheet/5V%20Relay%20Datasheet.pdf
  • Wikipedia, “Arduino Uno”: https://en.wikipedia.org/wiki/Arduino_Uno
  • ArduinoInfo wiki, “Arduino Pin Current”: https://arduinoinfo.mywikis.wiki/wiki/ArduinoPinCurrent
  • onsemi, 2N3903/2N3904 datasheet: https://www.onsemi.com/pdf/datasheet/2n3903-d.pdf

920 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *