You want to measure a voltage? But it’s outside the range of your microcontroller’s 0 to 3.3v or 5v? We can achieve this with resistors.

There are three distinct problems, each with its own solution.

## Table of Contents

- The positive voltage is above 3.3v or 5v
- The voltage is below ground/negative
- Both voltages are out of range

## The positive voltage is above 3.3v or 5v

If we apply double our maximum voltage over two identical resistors in series, we expect to measure half our voltage at the midpoint. It is this midpoint we are going to measure.

The voltage at the top can be calculated by multiplying the analog-read-voltage by 2. In this example I will assume a 5V microcontroller.

If we add another identical resistor, we add another 5V to the maximum voltage we can read, we can extend this as many times as we like.

We do only intend to measure after the first resistor, and then multiply the measured voltage by three to get the correct voltage. This means we can group the other resistors together by adding them up.

## The voltage is below ground/negative

If we want to measure below ground, we have to set this resistor network upside down. This example assumes a 3.3V microcontroller.

Instead of connecting the bottom end to the ground, we now connect the top to the maximum of our controller. And it is now after the top resistor where we read our voltage.

Once again, we simplify the network to only use two resistors by adding them up.

Calculating the actual voltage is not that complicated. First we multiply the voltage on the analog input by three and then add the lowest voltage we can read on the network, which is -6.6V. On the positive network we did not do this because that value was 0V.

So if we read +3.3V the actual value = (3.3 x 3) – 6.6 = +3.3V.

And if we read 0V the actual value = (0 x 3) – 6.6 = – 6.6V.

## Both voltages are out of range

When the input can be below ground as well as above the controller’s maximum, we can’t tie one end of the network to ground or max-voltage. We need to tie it in the middle, using another resistor divider. This example assumes a 5V controller.

The standing resistors on the left are equal, and without any voltage to measure would produce +2.5V at the middle for the analog pin to read.

The to-measure-voltage applied to the right will then pull that voltage up or down through the third resistor.

Then how to calculate that third resistor? And how to translate the value read at the analog pin back to the real world value? I could not figure this out in a simple way so I wrote a tool for the Windows platform to do this for me.

This tool gives you the resistor values you need and a map function to translate the value back to real-world-voltage. At the right side you can see the simulation results.

The resistor values are very high, to use as little power as possible, but you can lower them as long as you divide all of them with the same value.