How to drive a +12V load (e.g. a relay) from 8051 port pin?
Submitted By: Jan Waclawek FAQ Last Modified: 07/18/06
- (Answer compiled from multiple contributions, mainly by Kai Klaas, Sasha Jevtic, Michael Karas, Steve M. Taylor and Oleg Sergeev, taken mostly from discussion following this post, where more detailed information can be found.)
If only a single output is required, try the following diagram:
or a modification with less current consumption:
However, note that 1N4148 is a signal diode and if it drives a "bigger" relay coil, it can be easily destroyed (literally) by the induction "kick" from the relay coil. It has to withstand at least the same current as flows in the coil when the transistor is on, but there is no need to have a high reverse voltage type. Make sure that the diode turn-on time is shorter than the transistor's turn-off time, otherwise the diode won't protect the transistor from the induction kick properly.
There are also integrated solutions available, with multiple drivers per package (e.g. ULN2803/2804/2003/2004 - second sourced by more manufacturers). They contain also a freewheeling diode for each driver, but usually the relay is situated away from the drivers (sometimes not even on the PCB, but connected via cables/connectors) and the inductive current flowing back to the diode would cause problems - the diode must be placed directly at the coil.
They are also similar or better drivers with added shift register and latch, so multiple loads can be driven using only a couple of pins (such as TI's TPIC6B595 and similar).
Another option to drive a higher voltage load would be to use an optocoupler to decouple the two supply voltages, for example:
As a driver, also bipolar transistor can be used, with appropriate biasing resistors.
But be aware ?
Submitted By: Steve M. Taylor FAQ Last Modified: 07/18/06
- That the output of the 8052 goes HIGH on reset. Be prepared for this as your system boots. The circuit designs above DO take account of that, by needing a LOW on their inputs to turn on the loads.
This does not apply for the ULN2x0y's so if this matters, an invertor should be inserted (74xx04 or whatever; unfortunately, only 6 in a package in a rather stupid arrangement - which won't quite complement the ULN's).
Steve
Add Information to this FAQ: If you have additional information or alternative solutions to this question, you may add to this FAQ by clicking here.