MOULDLKnowledge BaseElectrical Knowledge Base3D Model DownloadsMembership
中文版Model Store »
Knowledge Base › Electrical Knowledge Base › Driving a relay coil with a transistor switch
HomeModels
Table of contents

On this page

Electrical & Electronic Basics (600 articles)

Quick Reference

  • PLC & Programming
  • Electrical & Electronic Basics (monthly)(每月更新中)
  • Electrical Control & Drawings (monthly)(每月更新中)
  • Drives & Actuators (monthly)(每月更新中)
  • Sensors & Detection (monthly)(每月更新中)
  • Industrial Communication & Networks (monthly)(每月更新中)
  • HMI & Host Systems (monthly)(每月更新中)
  • Industrial Robots & Motion Control (monthly)(每月更新中)
  • Mechatronic System Integration (monthly)(每月更新中)
  • Fault Diagnosis & Standards (monthly)(每月更新中)

Driving a relay coil with a transistor switch

Connecting a relay straight to a microcontroller IO pin burns the pin, because the coil draws tens of milliamps while the IO can only source a few. This page covers the transistor switch, the base resistor and the essential freewheel diode.

1. How it works

A relay coil is inductive and its pull-in current is often 30 to 70mA, far above the 4 to 20mA a microcontroller IO can drive. The transistor acts as a switch: the base takes a few milliamps from the IO and the collector handles the coil current, so a small current controls a large one. An NPN with collector to coil low side and emitter to ground turns on with a high IO.

2. Numbers and practice

Size the base resistor for hard saturation. For a 12V 40mA coil and a conservative beta of 20, I_B must be at least 2mA. From a 5V IO minus 0.7V U_BE, R_B is about 2kohm. The collector saturation drop is then near 0.2V, so the coil sees about 11.8V and pulls in firmly. Too small a resistor overdrives the IO, too large leaves the transistor linear.

3. Pitfalls and fixes

The freewheel diode is mandatory. When the coil de-energises it kicks a reverse spike of tens of volts that destroys the transistor. Place a 1N4007 inverse-parallel across the coil, cathode to supply, so the inductive current has a path. Without it the transistor fails after a few operations. Solder the diode close to the coil.

4. Transistor relay driver design notes

ParameterValueNote
Coil voltage12 Vmatch supply
Pull-in current40 mAfrom rating
I_Bat least 2 mAbeta 20 margin
R_B2 kohm5 V IO
Freewheel1N4007across coil
U_CE satabout 0.2 Vdeep saturation

5. Notes

This fits 5V, 12V and 24V low-power relays, PLC output expansion and appliance controllers. Measure the coil resistance and rated current first, then compute R_B, and never omit the freewheel diode. Check its direction with a diode test before powering.

6. References

The quantities and component characteristics discussed here follow current national standards and the corresponding IEC documents: Low-voltage control design per GB/T 4728; equipment safety IEC 60204-1. Always check the device datasheet and the product design file for ratings and derating.

7. Cautions

⚠️ Three common pitfalls:
① Omit the freewheel diode: the coil spike destroys the transistor after a few cycles
② Base resistor too large: transistor leaves saturation and the relay chatters
③ Wire a PNP like an NPN: a high IO turns it on and the logic inverts

Locate the issue with the approach above, then confirm with measurements; safety-related circuits must follow the standards and manufacturer requirements.

Related reading

Related 3D models: Ready to build it? Download free 3D models & CAD drawings at MOULDL »
MOULDL · Electrical Knowledge Base · free self-study reference for electrical & automation engineers, 3D CAD models at MOULDL