In engineering practice, there is often a need to control a relay or other receiver connected to a higher voltage (12V or 24V) using a signal from a microcontroller operating with 5V logic. The standard solution is to use an additional NPN transistor or optoisolator, which increases the number of components and cost.
This article presents an alternative, industry-proven solution that requires only a single Zener diode selected to suit the supply voltage. The circuit has been used since the early 2000s in industrial controllers for the production of europallets and still works reliably today.
Assumptions
Microcontroller supplied with 5V (e.g. AT89C2051, AVR, PIC)
PNP transistor (e.g. BC557, 2N2907) working as a high-side switch
Receiver supply voltage: V_CC = 12V or 24V
Receiver: relay, coil, lamp, etc. connected between collector and ground
Commercially available Zener diodes with ±5% tolerance
Schematic diagram
V_CC (12V or 24V)
│
│
├───────────┐
│ ┌─┴─┐
│ │ │
┌─┴─┐ │ R │ Pull-up resistor when zener diode is not conducting
Emitter │ │
│ └─┬─┘
PNP │ |
(e.g. BC557) │ Base ───────┐
│ ┌─┴─┐ Cathode
│ │ │
Collector │ Dz │
└─┬─┘ │ │
│ └─┬─┘ Anode
│ │
│ │
│ │
│ ┌─┴─┐
│ │ │
│ │ │ Rb │ Base resistor
│ │ │ (1kΩ)
│ └─┬─┘
│ │
│ │
│ to output pin
│ of the microcontroller
┌─┴─┐
│ │
Coil
└─┬─┘
│
│
│
GND
The receiver (relay coil) is connected between the PNP collector and GND. A surge diode (1N4148) in parallel to the coil is necessary, but not shown for readability.
Operating principle
The PNP transistor conducts when its base is about 0.7V lower from the emitter, ie:
V_B ≈ V_CC - 0.7V
For V_CC = 24V: V_B ≈ 23,3V
For V_CC = 12V: V_B ≈ 11,3V
A Zener diode connected in series between the base and the microcontroller pin conducts in the reverse direction (as a Zener) only if the reverse voltage on it exceeds its Zener voltage Vz.
Case 1: Microcontroller pin in LOW state (0V)
The reverse voltage on the Zener is:
V_rev = V_B - V_LOW ≈ V_CC - 0.7V - 0V
For V_CC=24V: V_rev ≈ 23.3V
For V_CC=12V: V_rev ≈ 11,3V
If Vz is appropriately selected (see table), the Zener will break through, the base current can flow and the transistor turns on. The receiver is switched on.
Case 2: Microcontroller pin in HIGH state (5V)
The reverse voltage on the Zener is:
V_rev = V_B - V_HIGH ≈ V_CC - 0.7V - 5V
For V_CC=24V: V_rev ≈ 18.3V
For V_CC=12V: V_rev ≈ 6,3V
If Vz is higher than this value, the Zener does not punch through, the base current does not flow and the transistor remains off. The receiver is switched off.
Selection of Zener voltage Vz
For the circuit to operate reliably, the Zener voltage must meet the condition:
V_CC - 0.7V - 5V < Vz < V_CC - 0.7V - 0V
Simplifying:
V_CC - 5.7V < Vz < V_CC - 0.7V
Table of practical values
Supply voltage V_CC Theoretical range Vz Recommended Vz nominal Available Zener Notes
12V 6.3V < Vz < 11.3V 9.1V BZX55C9V1 Wide margin. Works with 8.2V or 10V
24V 18.3V < Vz < 23.3V 20V or 22V BZX55C20 or BZX55C22 For 20V - more reliable switching; for 22V - more reliable switching
Influence of tolerance
For V_CC=24V and Vz=20V (±5% = 19V..21V):
Minimum V_rev at LOW state (23.1V) > 21V → Zener always conducts
Maximum V_rev at HIGH state (18,3V) < 19V → Zener never conducts
The circuit is immune to Zener production tolerance and supply voltage variations.
Practical considerations
The base resistor Rb: 1kΩ is a universal value. For higher collector currents (above 100mA) it can be reduced to 470Ω.
Microcontroller pin current: In the LOW state, the pin is shorted to ground by the internal N-MOS transistor. The current flowing through the pin is approximately (V_CC - 0.7V - V_LOW) / (Rb + R_zener). For V_CC=24V, Rb=1kΩ, ignoring the Zener resistance, the current is about 23mA - which is within the typical 20-40mA limit for most microcontrollers. For safety, Rb can be increased to 2.2kΩ.
Zener diode: Use 0.5W or 1W types. It is always switched on in the ZENER (breakdown) direction, never in the conduction direction.
Surge protection: When controlling the relay coil, it is essential to use a 1N4148 diode in parallel to the coil (cathode to collector, anode to GND).
History and authorship
This circuit was first developed and used by myself (Wojciech Petrykowski) in the early 2000s in industrial machine controllers for manufacturing .... [unfortunately I cannot disclose what
]. It still works reliably today. It reappeared in the English-language literature in 2023 on circuitlab.com as "DrivingAPNPfromMCU", but with no author cited.
He hereby documents his independent discovery and many years of industrial use of this solution.
This article presents an alternative, industry-proven solution that requires only a single Zener diode selected to suit the supply voltage. The circuit has been used since the early 2000s in industrial controllers for the production of europallets and still works reliably today.
Assumptions
Microcontroller supplied with 5V (e.g. AT89C2051, AVR, PIC)
PNP transistor (e.g. BC557, 2N2907) working as a high-side switch
Receiver supply voltage: V_CC = 12V or 24V
Receiver: relay, coil, lamp, etc. connected between collector and ground
Commercially available Zener diodes with ±5% tolerance
Schematic diagram
V_CC (12V or 24V)
│
│
├───────────┐
│ ┌─┴─┐
│ │ │
┌─┴─┐ │ R │ Pull-up resistor when zener diode is not conducting
Emitter │ │
│ └─┬─┘
PNP │ |
(e.g. BC557) │ Base ───────┐
│ ┌─┴─┐ Cathode
│ │ │
Collector │ Dz │
└─┬─┘ │ │
│ └─┬─┘ Anode
│ │
│ │
│ │
│ ┌─┴─┐
│ │ │
│ │ │ Rb │ Base resistor
│ │ │ (1kΩ)
│ └─┬─┘
│ │
│ │
│ to output pin
│ of the microcontroller
┌─┴─┐
│ │
Coil
└─┬─┘
│
│
│
GND
The receiver (relay coil) is connected between the PNP collector and GND. A surge diode (1N4148) in parallel to the coil is necessary, but not shown for readability.
Operating principle
The PNP transistor conducts when its base is about 0.7V lower from the emitter, ie:
V_B ≈ V_CC - 0.7V
For V_CC = 24V: V_B ≈ 23,3V
For V_CC = 12V: V_B ≈ 11,3V
A Zener diode connected in series between the base and the microcontroller pin conducts in the reverse direction (as a Zener) only if the reverse voltage on it exceeds its Zener voltage Vz.
Case 1: Microcontroller pin in LOW state (0V)
The reverse voltage on the Zener is:
V_rev = V_B - V_LOW ≈ V_CC - 0.7V - 0V
For V_CC=24V: V_rev ≈ 23.3V
For V_CC=12V: V_rev ≈ 11,3V
If Vz is appropriately selected (see table), the Zener will break through, the base current can flow and the transistor turns on. The receiver is switched on.
Case 2: Microcontroller pin in HIGH state (5V)
The reverse voltage on the Zener is:
V_rev = V_B - V_HIGH ≈ V_CC - 0.7V - 5V
For V_CC=24V: V_rev ≈ 18.3V
For V_CC=12V: V_rev ≈ 6,3V
If Vz is higher than this value, the Zener does not punch through, the base current does not flow and the transistor remains off. The receiver is switched off.
Selection of Zener voltage Vz
For the circuit to operate reliably, the Zener voltage must meet the condition:
V_CC - 0.7V - 5V < Vz < V_CC - 0.7V - 0V
Simplifying:
V_CC - 5.7V < Vz < V_CC - 0.7V
Table of practical values
Supply voltage V_CC Theoretical range Vz Recommended Vz nominal Available Zener Notes
12V 6.3V < Vz < 11.3V 9.1V BZX55C9V1 Wide margin. Works with 8.2V or 10V
24V 18.3V < Vz < 23.3V 20V or 22V BZX55C20 or BZX55C22 For 20V - more reliable switching; for 22V - more reliable switching
Influence of tolerance
For V_CC=24V and Vz=20V (±5% = 19V..21V):
Minimum V_rev at LOW state (23.1V) > 21V → Zener always conducts
Maximum V_rev at HIGH state (18,3V) < 19V → Zener never conducts
The circuit is immune to Zener production tolerance and supply voltage variations.
Practical considerations
The base resistor Rb: 1kΩ is a universal value. For higher collector currents (above 100mA) it can be reduced to 470Ω.
Microcontroller pin current: In the LOW state, the pin is shorted to ground by the internal N-MOS transistor. The current flowing through the pin is approximately (V_CC - 0.7V - V_LOW) / (Rb + R_zener). For V_CC=24V, Rb=1kΩ, ignoring the Zener resistance, the current is about 23mA - which is within the typical 20-40mA limit for most microcontrollers. For safety, Rb can be increased to 2.2kΩ.
Zener diode: Use 0.5W or 1W types. It is always switched on in the ZENER (breakdown) direction, never in the conduction direction.
Surge protection: When controlling the relay coil, it is essential to use a 1N4148 diode in parallel to the coil (cathode to collector, anode to GND).
History and authorship
This circuit was first developed and used by myself (Wojciech Petrykowski) in the early 2000s in industrial machine controllers for manufacturing .... [unfortunately I cannot disclose what
He hereby documents his independent discovery and many years of industrial use of this solution.
Cool? Ranking DIY