# How to calculate pull-down resistor resistance

I have a 12V input which I am using a 100k and 20k resistor as R1 and R2 respectively as a voltage divider to feed into a Raspberry Pi GPIO pin.

When the 12V signal is switched off, I would like to pull this pin low.

I cannot seem to quite grasp how one calculates the resistance required to do this.

Can someone please explain this to me?

Thanks.

• This seems to have little to do with the Pi. If you actually provided some details of what you have it may be possible to comment Nov 16, 2020 at 9:12
• @Milliways, the Pi is connected to the ignition of a vehicle. I have no problems getting the voltage down to an acceptable range for the GPIO, but when the ignition is off, I need the pin in the pi to be pulled-down to low. I will need a pull-down resistor to do this. I was just wondering how to figure this out. Nov 17, 2020 at 1:55
• @tlfong01 Thanks for this! I will take a look. Nov 17, 2020 at 1:55
• Without a circuit we are working in the dark. If you are using a voltage divider the voltage will be zero, so I don't understand what you are asking. Incidentally if you are working on automotive electronics the values you are using are ludicrously HIGH. You also need protection from transients. I speak from 50 years experience installing electronics in cars. Nov 17, 2020 at 2:21
• (1) R1 and R2 are meaningless without a diagram and (2) what you describe is not a pull-down, it's called a voltage divider. Nov 17, 2020 at 7:28

simulate this circuit – Schematic created using CircuitLab

### Vout = [ R2 ÷ (R1 + R2) ] × Vin

For Vin = 12V :

Vout = 20K ÷ (100K + 20K) × 12

= (20 ∕ 120) × 12

= 2.0 Volts

When Vin = 0V

Vout = 0V

As an intuitive aid, consider this equation says, "The voltage across a resistor is divided in the same ratio as the value of that resistor to the total resistance."

With a bit of algebra, we can re-write the above to solve for the value of R2 needed to match the GPIO voltage at 3.3V:

### R2 = ( R1 × Vout ) ∕ ( Vin - Vout )

R2 = ( 100K × 3.3 ) ∕ ( 12 - 3.3 ) = 37.9K𝛀

Since 37.9K𝛀 is not a standard value resistor, and we should never exceed 3.3V at a GPIO pin, we should choose the next smaller value: 33K𝛀.

For a more detailed explanation. It takes some time to get this - to really get it. Read as much as you can, download LTspice & simulate some simple circuits.

• Thanks for this Seanus, it is a really helpful explanation. My reasoning for the 100K and 20K (which I should have mentioned) was to compensate for voltage fluctuations in the system as it would be in an automobile. I figured 2 volts was enough to signal the GPIO (with testing) and at an extreme of 18v, not too much to damage it. What I would really like to know is the value I should make the third resistor to pull-down the GPIO pin when the 12v input is low. How does one calculate this? Nov 17, 2020 at 1:50
• @Seamus, I think your answer is very good for the newbie OP. The OP's problem is a general one: "How to convert a 12V DC level signal to 3V3 logical level which is then input compatible to 3V3 Rpi or other MCU/SBC?". For more advanced users, I would tend to suggest ／　ｔｏ　ｃｏｎｔｉｎｕｅ，．．．（Ｓｏｒｒｙ，　ｆｏｎｔ　ｅｒｒｏｒ，　ｔｏ　ｃｏｒｒｅｃｔ　ｌａｔｅｒ）． Nov 17, 2020 at 2:48
• @JustinLillico: You don't need a third resistor. R2 (ref schematic above) will serve as a pull down, and keep your input from "floating". Wrt voltage fluctuations: In the automotive application where there may be surges that you want to guard against, I would suggest you consider replacing R2 with a 3V Zener diode. In this case, R1 should be smaller than 100K so that you keep the Zener in its reverse breakdown region - about 5 mA with part# BZX55C3V0 Nov 17, 2020 at 3:09
• @Seamus, you're right. I somehow missed this (perhaps due to my lack of experience). I will look into the zener diode. Thanks! Nov 17, 2020 at 3:20
• @Seamus, Ah, using a one resistor and 3V Zener diode seems to be an improvement over the two resistor solution, because the Zener protects the Rpi input GPIO pin from over voltage. I think there is still a small chance of a "latching" problem, so I think using a optical coupler would reduce the latching risk, at the same time reduce the effect of glitches/transients/noise at the car's ignition hardware. Nov 17, 2020 at 3:21

Question

How to shift down a 12V DC signal for 3V3 Rpi GPIO pin in input mode?

There are a couple of ways as described below:

(1) Using NPN BJT such as 2N2222

(2) Using Optocoupler such as EL817C

Discussion, Recommendation, and Warning

(1) 2N2222 is usually used to shift up a low level signal eg 3V3 to 5V0. However, it can also be used to shift down a signal, eg, in this case, from 12V to 3V3 or 5V0.

(2) For the OP's application environment of car ignition, with heavy noise voltage glitches, spikes, and noises, the optocoupler interface is highly recommendation.

(3) For down shifter using voltage divider or 2N2222, there is a risk of "latching" (see Ref (1), Appendix D below) which might damage GPIO pin or Rpi, so usi9ng the optocoupler approach can reduce the risk of latching.

(4) Warning - @tlfong01 is just a friendly hobbyist, he has zero experience in car electronics, there is no guarantee that no nothing won't blow up or melt down. :)

References

• EL8177C Optocoupler (Part C)

• Latching up problem, frying the Rpi, or shortening its life (Appendix D)

• @Justin Lillico, You are welcome. Cheers. Nov 18, 2020 at 1:33