Having trouble connecting my voltage divider circuit to my Pi

Thread Starter

zirconx

Joined Mar 10, 2010
130
Hi, I've been working on getting a water flow sensor connected to my Raspberry Pi. It's a simple hall effect sensor that sends 5v pulses to indicate the rate of water flowing.

So I tried to use a voltage divider to reduce the 5v to about 3v. I got this to work fairly easily as a stand alone circuit. But when I connect it to the pi, the voltage changes. What should be a 3v pulse now reads around 1v. I think the problem is the internal pull down resistor? I thought these could usually be ignored because they are very weak?

I finally got it work by using a 10k pot as the voltage divider. Then I was able to easily manually the voltage while the device was connected (and sending HIGH signal) so that 3v ends up on the GPIO pin. Is this a good solution? Am I missing something? When I read about connecting 5v devices to the pi a voltage divider was often recommended. Maybe I should be disabling the internal pull down resistor somehow? I am using the npm onoff library which does not support changing the internal pull up/down resistors. I tried adding a pull up resistor, but then the sensor could not pull the signal LOW.

Thanks.
 

KeithWalker

Joined Jul 10, 2017
1,779
The electrical characteristics of the input/output pins are not adequately specified in the Raspberry Pi documentation or processor datasheet. Broadcom doesn't specify the value of the input pull-up/down resistor. It is likely to be in the 40 to 100 KΩ range. The transistors that enable the pull-up/down resistor contribute their appreciable nonlinear resistance to it, so the effective resistance is not constant over the input pin voltage range. The pull-up behavior is somewhat of a cross between constant resistance and constant current behavior. You can use resistive dividers to match 5V logic levels to the 3V input levels required by the PI but it will take some experimentation to find the right resistance values. Never source or sink more than 0.5 mA into an input pin. Once you have done this, there is no guarantee that these will work with a different Raspberry PI. It is much better to use 5V to 3V logic level shifters. They are bi-directional, inexpensive and readily available.
Regards,
Keith
 

Thread Starter

zirconx

Joined Mar 10, 2010
130
Sure. You can see I have the potentiometer set as an 85k/10k voltage divider. My calculations say this should produce just under 4.5v, and indeed it does when it's not connected to the pi. When it's connected to GPIO pin 26 I get around 3v. Obviously the GPIO pin is impacting the circuit. When I test the GPIO pin by itself with my DMV I see 0v. I've tried adding a resistor inline to the GPIO pin but it didn't help. Well a very high value resistor (megaohms) did help, the circuit no longer dropped voltage, but then the voltage at the pin was very low.

Oh I mislabeled the pot in the diagram, I thought it was a 10k pot but when I measured the individual legs I realize it must be a 100k pot.
 

Attachments

Thread Starter

zirconx

Joined Mar 10, 2010
130
The electrical characteristics of the input/output pins are not adequately specified in the Raspberry Pi documentation or processor datasheet. Broadcom doesn't specify the value of the input pull-up/down resistor. It is likely to be in the 40 to 100 KΩ range. The transistors that enable the pull-up/down resistor contribute their appreciable nonlinear resistance to it, so the effective resistance is not constant over the input pin voltage range. The pull-up behavior is somewhat of a cross between constant resistance and constant current behavior. You can use resistive dividers to match 5V logic levels to the 3V input levels required by the PI but it will take some experimentation to find the right resistance values. Never source or sink more than 0.5 mA into an input pin. Once you have done this, there is no guarantee that these will work with a different Raspberry PI. It is much better to use 5V to 3V logic level shifters. They are bi-directional, inexpensive and readily available.
Regards,
Keith
This is good info, thank you. I do plan to move this circuit to my "production" pi, right now I'm trying it on a different pi on my bench. So the voltage might change once I connect it to the other pi.

A logic level converter seems overly complicated for just counting pulses. What about using a zener diode to drop the 5v to 3v? I would have tried this already but I cannot find my bag of assorted zeners. Or what if I dig through my bin of LEDs and find one that has a 2v voltage drop?
 

ElectricSpidey

Joined Dec 2, 2017
1,653
Considering the fact that any time you add or remove resistance in a divider the output will change, the pot should have been your first choice.

I recommend those nice 20 turn trim pots from a company like Bourns.
 
Last edited:

KeithWalker

Joined Jul 10, 2017
1,779
This is good info, thank you. I do plan to move this circuit to my "production" pi, right now I'm trying it on a different pi on my bench. So the voltage might change once I connect it to the other pi.

A logic level converter seems overly complicated for just counting pulses. What about using a zener diode to drop the 5v to 3v? I would have tried this already but I cannot find my bag of assorted zeners. Or what if I dig through my bin of LEDs and find one that has a 2v voltage drop?
A 3V zener to ground with a series resistor from the sensor will work. You could substitute three series 1N4001 diodes for the zerner. Don't use a LED connected from the sensor to the IO pin. The voltage drop will depend on the amount of current flowing and may damage the input.
 
Top