Further to my previous question, Using a PIC to perform switch on and timed shutdowns in automotive environment

I've been pointed at zener diodes and voltage dividers, but I'm now confused by the PICs builtin weak pull-up resistors (and if I check the datasheet, values are TBD... I assume something like 10k?)

So the PIC input pin protection circuit I think I have understood is this:PIC input pin protection circuit

But using weak pullups, I think I could do this:

enter image description here

But all this does is swap a resistor to a transistor.


Further to comment from @PJC50, I now think the circuit utilising the PIC's pullup resistors would look like this: enter image description here It's now clear why I should do this and how it reduces component count.

How do I choose a resistor and transistor that are suitable?

  • Is the voltage divider circuit correct?
  • Is the circuit that uses the weak pullups correct? (i think not)
  • Why would I use pullups over normal voltage divider?

So my new circuit looks like this: enter image description here

Update 2:

I've tested the circuit with pull ups, and I think I'm getting closer to real solution, any further comment/critique welcome!

  • 1
    \$\begingroup\$ If you select a suitable transistor and base resistor, you can lose the Zener diode as well. You've created an "open collector" signal, which works fine as long as you don't need it to operate at high speed. \$\endgroup\$
    – pjc50
    Nov 6, 2012 at 9:56

3 Answers 3


If you are using the NPN method as I described in #4 of my answer https://electronics.stackexchange.com/a/47250/4512, then you don't need a zener diode. The B-E diode of the transistor will limit the voltage by itself.

To clarify, here is how you can use two resistors and a zener diode to safely drive a 5 V PIC input from car power:

With 12 V in, the resistor dividers by themselves would drop the output to 6 V. However, the zener will clamp that to a bit below 5 V, which keeps the voltage safe for the PIC. Even if IN momentarily went to 50 V, for example, the zener will limit the voltage at OUT to a safe level.

The transistor method looks like this:

The B-E junction of the transistor will limit the voltage accross it to around 700 mV, so there is no need to protect the resistor. In this case I set the voltage divider so that it takes a few volts on IN to turn on the transistor. If the base is about 600 mV when the transistor first turns on, then there needs to be about 5 V on IN for that to happen. This gives you better noise immunity than just connecting a resistor to the base of a transistor without a pulldown there.

When IN is high, the transistor turns on, pulling OUT low. Since the transistor can only pull down or not pull at all, you need something to pull the line high when the transistor is off. This can either be the deliberate R3 as shown, or it can be a pullup resistor built into the PIC. In the latter case, you don't need R3 and you just tie the collector directly to the PIC input without any additional parts.


Basically ANY NPN BJT transistor will do. The collector current is tiny, so it won't be a problem. Choose the base resistor to give the at leas the collector current divide by the transistor's Beta. A few kilo-ohms will do fine. I would add a resistor from the base to ground, value ~ twice the other resistor. (same or tenfold will do too) This resistor makes sure the transistor is off even when a small input voltage (0.5V or so) is present.

The circuits you show with the zener put it in the wrong position: it should be after the resistor. Otherwise it is prone to become a firecracker. And the resistor values are too low to my taste, 1k or even 10k is more like it.


In the first circuit the 4.7V zener is in the wrong place. As shown there is nothing to limit the current through it, so it will burn out. It should on the input pin side to limit any spikes the divider can't handle.
Also, the resistor values are unneccesarily low - 12V / 100Ω+70Ω = ~70mA, and 70mA * 12V = 0.85W. You would need at least 1W resistors. If you change to something like 7k and 5k you can use standard 1/4W resistors.

For the final circuit shown, the base resistors are also too low. The base-emitter drop is only ~0.7V, so you will have (12V - 0.7V) / 100Ω = 113mA, which is way too high for this transistor (10-20mA max is more like it). Again, change it to something like 10k, since you will need very little current gain to pull down the weak pullup (also add a pulldown as mentioned in Wouter and Olin's answers - the diagrams in Olin's answer should make things nice and clear)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.