5 Voltage divider circuits that go beyond dividing

voltage divider circuits

Here are some ideas of what you can do with the humble voltage divider. This elementary circuit has a few inventive uses. To be upfront, one of these uses is NOT as a voltage regulator. If you need a voltage regulated, get a voltage regulator! At some point or another, I’ve built all five of these voltage divider circuits. For me, the voltage level shifter is the most common.

  1. Measure Battery Voltage
  2. Signal Level Shifter
  3. Reference Voltage
  4. R-2R Ladder
  5. One Analog Input with Many Buttons

#1 Measure Battery Voltage

There are a couple of different cases where you might need to “step down” your battery voltage. In this case, this is NOT a substitute for a buck regulator. Instead, you might need to step down the battery voltage to measure it. Let’s say you are using a 3v3 microprocessor (Raspberry Pi) or ESP8266 (Microcontroller). Your board is being powered by two LiPos in series. Together these batteries create a supply of 7.4 volts.

Simple Voltage Divider

Problem using Simple Voltage Divider Circuits

Two 100kohm resistors divide the voltage from 7.4 to 3.7 volts. While easy, that is still too high for a most 3.3 volt systems. (At least the ones you want to last.) When splitting the voltage in half does not work, I turn to this voltage divider calculator. With R1 at 100kOhm and R2 at 68kOhm, the divider outputs about 3.0 volts. Simple enough, right?

simple voltage divider 3v0

Well, there are two problems.

Leakage Current

First, connecting these two resistors in series to the battery will create a leakage current. No matter what else is going on in the circuit, 44 µA will flow through the divider. Sounds small, but that means 325 µWatts of wasted power. With USB there is little concern about that much leakage. When powered by batteries, however, that leakage means less battery life.

Back powering

If your board stays on all of the time the battery is connected, then “back feed” or “back powering” isn’t an issue for you. Here, let’s say you take the simple divider from above and leave it connected to the analog pin. At the microcontroller, you add a switch to turn it off. Now, this switch turns off VCC but not the battery voltage.

This circuit will cause the voltage divider to “power” the microcontroller through the I/O pin. This path can damage the microprocessor and means your battery-powered circuit stays powered! So you need a way to avoid back powering your circuit.

Add transistors to voltage divider circuits

Most applications don’t need continuous battery voltage monitoring. What if you could just turn on the voltage divider when you make the measurement? Ah-ha! Here’s a solution. Add a high-side PNP transistor to the simple voltage divider. A digital I/O pin controls a NPN, which turns the PNP on and off. With this configruation, no current can sneak through the analog pin’s protection diodes. And you have full control over how long the divider is activated.

Measure Battery PNP with NPN

Update: Thank you to James Whong from Mooshimeter for helping correct this circuit.

You’ll need to do some math to account for the voltage drop across the transistor, but this circuit solves the two problems: 1) leakage current is minimized and 2) minimal leakage current through the circuit.

Note: Using voltage divider circuits to measure the voltage of Lithium-Polymer batteries isn’t a reliable method to determine how much energy they have left. But I’m asked about it often, so I wanted to cover it here. (For those that are going to do it anyway.)

Raspberry Pi Doesn’t have Analog

Wait a minute; I mentioned the Pi. To read a battery voltage, don’t you need an analog-to-digital converter? Yes, you do, sometimes. An ADC is necessary to measure precise voltages. If you’re just looking for a low battery indicator, treat it as a digital signal! You could set the divider to 2.35 volts based on your battery’s “low voltage.” Any battery voltage above that point will give a larger value than 2.35 volts, which is the logic-high threshold of the Pi’s GPIO pins.

#2 Voltage Level Shifter

Modern microcontrollers are based on 3v3 logic with 1v8 logic right behind it. Using older 5.0-volt technology means you need to voltage-shift I/O signals. For example connecting an Arduino Uno’s output directly to an ESP8266 input can cause damage. (I don’t care what you read on that random forum. Don’t connect 5.0-volt logic to 3.3-volt boards!) Like I said this is the most common of the voltage divider circuits that I build.

One option is to use an application-specific chip. TI’s TXB0108 Bi-Direction shifter is one example. If you are interested in that chip, Adafruit offers a breakout board with it. This chip is designed for bi-directional operation. I2C signals are an example of a bi-directional bus. Serial, or UART, is a case of a unidirectional signal pair. So to connect serial between a 5.0-volt and 3.3-volt system, you need logic shifting.

I bet when I called this article “voltage divider circuits,” you didn’t expect two voltage divider examples in a row, right? For uni-directional signals just put two resistors in series and tap it’s Vout to go to the I/O pin. Good values to use here are R1 at 10kohm and R2 at 15kohm.

Voltage Shifter for Uno and Pi

Keep in mind signals going from the 3v3 system to the 5v0 system, don’t need shifting. The Raspberry Pi’s output voltage is high enough for an Arduino Uno to see it as a logic high. It is only when you go from 5.0 to 3.3 volts you need the voltage divider.

#3 Reference

Not all voltage divider circuits use just resistors. One example contains a resistor and diode.

Zener Reference Example

The diode’s reverse voltage creates a precision reference voltage. The resistor creates a series circuit, just like when used with an LED. Zener diodes are often used to create these reference voltages. When a Zener diode is reverse biased, it produces a relatively small voltage drop. The remaining voltage drops across the series resistor. Knowing your source voltage, the Zener’s reverse voltage, and the current needed through the Zener, you can calculate the series resistor’s value.

zener diode characteristics

An example is this 3.3V Zener from Diodes Inc (at Digi-Key). Looking at the data sheet, it’s nominal Zener drop is 3.3 volts when 5.0 mA is applied. Using a stable 5.0 volt supply, a 340 ohm resistor will give you a stable Vout of 3.3 volts. Keep in mind this isn’t a voltage regulator. Well, at least, not one that can provide much current.

Use it for the analog reference

Let’s say you have an 5 volt Arduino measuring the 7.4 volt lithium polymer battery pack from the first example. Attaching this circuit to the AREF pin will increase the resolution of the A/D converter. The full-scale range of the A/D is no longer VCC’s 5.0 volts. Instead, it will be the lower 3.3 volts. Why 3.3 volts? Well, I picked it as an easy to buy Zener. And to measure the battery with an Arduino, you’ll need to divide down anyway. So here you’ll do something like a 2.3:1 divider. For slightly better resolution you could use a 3.7 volt Zener, if you can find one.

#4 R-2R Ladder

An R-2R ladder is a bunch of repeating resistors, or a network of resistors. The idea is that as you turn on more inputs, it affects the output voltage. This circuit is one way to make a digital-to-analog converter (DAC). You apply digital inputs and get an analog voltage out. Since this is a form of a current divider, the performance depends on how well the resistors are matched to each other. So you should use precision parts or measure each to match them manually.

r-2r-simulation

Add more resistors to the string for more resolution. Use better matched resistors for more precision. In this example with 1K and 2K resistors, each bit is worth 313 mV. The max output is 4.68 volts. I might cover these in more detail in the future. For now, check out this great Tektronix blog post on R-2R DACs.

#5 One Analog Input Button for many Buttons

 

Multi Button voltage divider

Using a network of buttons and resistors you can use a single analog input for multiple buttons. Between each button is a resistor value. In this example, I used 470 ohms resistors. When you press a button, R1 (1k) creates a divider with the rest of the network.

Here I am pressing button two (2) which means the voltage out is a divider between 1 Kohm and 1.4 Kohm. You don’t have to use equal resistor values. My suggestion is that you pick values that give you a wide range between the buttons. That way your code reading the analog input can have a wide input range.

pressed button

By the way, to check a range in C/C++, you need to use a logical-AND statement. So for example, reading A0 on an Uno might look like this:

int analogValue = analogRead(A0);
If ( (analogValue > 128) && (analogValue < 512) )
    // Do something… it’s between 128 and 512.

Conclusion

Voltage dividers have a variety of uses. As you might notice, nowhere on this list is there a “voltage regulator.” The Zener reference comes close, but that circuit isn’t designed to drive much current. Or at least, not current to a load that might change.

Question: Did I miss any other voltage divider circuits? If so, leave a comment with them below. You can leave a comment by clicking here.

Long comments, URLs, and code tend to get flagged for spam moderation. No need to resubmit.

Leave a comment

17 thoughts on “5 Voltage divider circuits that go beyond dividing

  1. “Add transistors to voltage divider circuits”

    The circuit that you have depicted, what limits the current, IB from the PNP’s emitter to base? It looks like the limit is the 100k series resistor into the NPN and the NPN’s maximum hfe. Reconsider this circuit by adding say a 10k ohm resistor inseries between the PNP base and NPN collector node.

  2. Talking about transistors to voltage divider circuits.
    As mentioned before, a low side switch would be better choice. I would prefer a “logic level” NMOS over a bipolar transistor. Advantages are virtually no voltage drop due to very small RDSon and simple control of transistor’s Gate as no resistor needed to control it. That way you could even increase reasonably the current through divider to get a better result during short measurement. Remember internal resistance (and Caps in S&H) of ADC input is a virtual resistance parallel to divider and seen as a load.

  3. You missed a favorite of mine, the reverse of #3. Putting the zener in the high side before a voltage divider allows you to expand the scale by subtracting a fixed voltage. This can give a few more bits of data with an A/D.

  4. In 1978, ON4OVmade already a power sypply with a 7805, it was working perfectly, I toke it as base for all my power supply’s wiht LM317. I changed the 7805 to LM317 only because the tension was limited to 5V, with the LM317 1.2V is possible.
    I send the schematic to your Email adress.

  5. Re #5, reading multiple buttons with one Analog input pin:
    If you choose your resistors to produce evenly spaced codes, instead of using multiple if … statements the software an use a switch .. case structure, which in my opion gives simpler and more transparent code.
    The resistor values can be worked out most easily using a spreadsheet.
    For example, with 4 buttons, the resistors should be 1500 (SW1), 680 (SW2), 330 (SW3) and 100 (SW4) using your circuit with a 1000 ohm top resistor. Using preferred values for the resistors introduces some deviations from evenly spaced codes, but still OK.
    The voltages with 1 button pressed are: SW1 3.62V (code 740); SW2 2.63V (code 538); SW3 1.5V (code 308); and SW4 0.45V (code 93). Divide by the average gap between codes (a bit over 200) and the result is 3,2,1,0.
    The software can then be:

    int analogValue = analogRead(A0);
    switch (analogValue/200) {
      case 3: 
      // do something.. its between 600 and 799
      break;
      case 2: 
      // do something.. its between 400 and 599
      break;
      case 1: 
      // do something.. its between 200 and 399
      break;
      case 0: 
      // do something.. its between 0 and 199
      break;
      default:
      // no key pressed
    }
    
  6. Hi James! In the figure under “Add transistors to voltage divider circuits”, the diagram has a high side NPN transistor. To turn this transistor on, you will need a base voltage that is at least Vbat+0.7, which is probably impractical with 3.3V logic. I suggest using a high side PNP with the base current pulled down by a low side NPN, with the NPN switched by the 3.3V digital IO.

    Thanks for another great blog post!

      • another, simpler, yet working idea is to connect the low side of the voltage divider directly to the GPIO-pin – if you can put the GPIO-pin into a high-impedance state (input). Alternatively you can just switch the low side of the divider by an NPN transistor.

        In the high-impedance state or with the NPN off there is essentially no current flowing (in the case of the GPIO pin alone there might be a leakage current through the protection diodes!).

        When you switch the GPIO-pin to 0 or alternatively turn on the NPN with a 1, then current will flow. Yes, there is a drop over the output transistor or the collector-emitter of the NPN, but that is in the same order as your drop over the PNP (or even less), and for these low currents it should be negligible.

        • I’m not a fan of the pin-sinking idea. When in the High-Z state, (nearly) the full battery voltage is going to be applied to the IO pin. (Plus the leakage issue you mentioned.)

  7. Hello sir,
    I want to measure the energy consumed in our house accurately by using clamp sensors,
    Im requesting to give me your time to make a blog about measuring the sinusoidal waveform by using microcontrollers like arduino.or esp chip.

    I have a problem in measuring the energy(kwh) of inductive loads, i think this is due to powerfactor..
    I dont know how to measure the phaseshift beetween voltage ang current.

    If you have some time it will be a big help to me. Cause i love the way you explain circuits from simple to complex.

    Mathematicaly it is easy to calculate the energy by just using integral to get the average voltage.
    But making it in actual is a different thing.

    Thanks in advance

    • I’ll have to give this some thought. I’m generally don’t like to discuss AC circuits. I’m not a licensed electrician and I don’t have enough experience to comfortably give safe advice. Using clamp sensors, however, does reduce the risk. So, as you say it, it becomes more a discussion on handling sine waves and some math. I haven’t done work with PFC circuits for years, so it’ll require me to do some homework before I could help you. Which is to say, I’ll add it to my list of ideas, but it will be some time before I come back to it.