# Scaling DC voltage down for use with 5 V microcontroller

I'm working on a project that requires a flow sensor connected to a PLC, and I would like to have a readout of the flow rate visible; however, the manufacturer of the sensor doesn't produce a display for the sensor, and the output voltage is 6-24 Vdc, which would be too high for a microcontroller.

I need a method to scale down the voltage to 0-5 Vdc so that I can still use a microcontroller with an LCD, or just find a programmable alternative to display the flow rate.

• Use a resistor voltage divider. Commented Jul 14, 2022 at 17:13
• A resistive divider won't account for the offset voltage. If you just want it within the range that the micro can handle a divider will work, if you want to maximize the range you need to deal with the offset. See this answer to a similar question: electronics.stackexchange.com/questions/618856/… Commented Jul 14, 2022 at 17:20
• What sensor is it? Does it have digital or analog output? Commented Jul 14, 2022 at 17:38
• Are you sure it has an analog output, not a Hall effect sensor pulse output as is common with paddle wheel sensors? Commented Jul 14, 2022 at 17:45
• You must link the datasheet for details and your error budget. We suspect you are misunderstanding the requirements. Commented Jul 14, 2022 at 18:39

simulate this circuit – Schematic created using CircuitLab

R1 and R2 form a resistor potential divider. The relationship between the potentials at X and Y are:

$$V_Y = V_X \times \frac{R_2}{R_1 + R_2}$$

Using the values I've shown, this becomes:

\begin{aligned} V_Y &= V_X \times \frac{10k\Omega}{39k\Omega + 10k\Omega} \\ \\ &= V_X \times \frac{10}{49} \\ \\ &\approx V_X \times 0.2 \\ \\ \end{aligned}

Keep the total $$\ R_1 + R_2 \$$ in the kilohms, or tens of kilohms. Not so low that the PLC's output is excessively loaded, but also not so high that your new signal's source impedance may be problematic for the next stage (microcontroller's ADC input).

As other users have pointed out, if you wish to map the entire 6-24V input to an output range of 0V to 5V, you'll need to offset the signal somehow. That will enable you to use the ADC's entire dynamic range, to achieve maximum resolution. If your ADC is 16 bits, for values from 0 to 65535, using the simple resistor divider above will limit you to values between $$\\frac{1.2}{5.0} \times 65536 = 15728\$$ and $$\\frac{4.9}{5.0} \times 65536 = 64225\$$. In other words, the ADC will never use roughly 16000 counts of its possible conversion space. If addressing this issue interests you, then read on.

To create the potential mapping of 6V→0V and 24V→5V, the algebraic relationship between input $$\V_X\$$ and output $$\V_Y\$$ would be:

\begin{aligned} V_Y &= (V_X - 6) \times \frac{5}{24 - 6} \\ \\ &= 0.28 (V_X - 6) \end{aligned}

In plain terms, this requires some system that offsets the input signal downwards by 6V, and then multiplies by 0.28. Or, that could be written:

\begin{aligned} V_Y &= 0.28 (V_X - 6) \\ \\ &= 0.28 V_X + 0.28 \times (-6) \\ \\ &= 0.28 V_X - 1.7 \end{aligned}

It's the same relationship, but describes a system that first multiplies by 0.28, and then shifts downward by 1.7V. You could build a circuit that does either, to obtain exactly the same behaviour overall.

Here is a circuit employing a single op-amp to perform these operations:

simulate this circuit

The algebra to obtain all the resistor values is quite complicated, and I won't go into it here (unless you ask). With the values shown, a simulation yields this relationship between input $$\V_X\$$ and output $$\V_Y\$$:

This circuit has a few significant advantages:

• The initial potential divider formed by R1 and R2 protects the op-amp's input from the high voltage PLC output. The voltage at P can never exceed 3V or so, which means the op-amp can be powered from the same source powering the microcontroller.

• The op-amp's output is constrained by its own power supply potentials. The output $$\V_Y\$$ can't ever fall outside the 0V to 5V range, and the ADC input is protected.

• The relationship between output and input is extremely linear. Other solutions (see below) may not be able to offer such a benefit.

The model of op-amp is quite important. The one I chose here, the TLC2272 is used because it has a rail-to-rail output, and can operate from a low voltage power supply. This is beneficial if you wish to power the op-amp from the same supply as the microcontroller, and obtain an output that can swing between those two extremes of supply potential.

Here are a couple of other possible approaches, both of which have problems. I only include them here for completeness:

simulate this circuit

The first (left) circuit uses a zener diode to develop a permanent 6V drop, which will effectively be subtracted from $$\V_X\$$, prior to being scaled by the resistor divider. This relies on the voltage across the zener diode being constant, but unfortunately it won't be. It will vary (very little, but it will vary) as current through it changes, which occurs as $$\V_X\$$ rises and falls. The whole idea was to maximize the ADC's useful resolution, but here we introduce more error. We have better ADC resolution, but we are working with worse data. There are devices which do exactly what the zener diode does here, but much much better. Such a device is the TL431 which could work well in this role, but I still prefer the op-amp solution above.

The second circuit (right) will work very well, but requires a low impedance, well regulated source of -2.3V, which I doubt you have. To build one would be far too much hard work. If you're wondering where I got -2.3V from, that's another algebra story, too long for here.

• Resistors should be precise with low tolerance and low ppm in order for it to be reliable. Commented Jul 14, 2022 at 20:02

You can use a simple resistive divider, but resolution will suffer a bit. Because the input doesn't go down to zero the output won't be able to either.

If you need the full 0-5 V resolution you can design a scaling circuit with offset.

Here is an example circuit that does this. It includes the simple divider for comparison. The supply voltage for the opamps could possibly be derived from the sensor supply, I have used 10 V here and 5 V as the reference for the offset. The type of opamp selected is more critical with a single supply design, it could be relaxed a bit if a dual supply were used. The LT6005 appears to work in the simulation, I have not tried it in hardware. The buffers keep the resistive dividers from being loaded down, it might be possible to do away with them if lower impedance dividers were used.

The output graph shows the difference in range compared to the resistive divider.

• You didn't really explain so I will. The circuit is called non-inverting op amp with inverting reference. You can find a TI application note with step by step calculations if you google it. Since it is non-inverting op amp, gain must be greater than 1. That's why the input is connected to the voltage divider, to scale it down so the gain is greater than 1. Commented Jul 14, 2022 at 19:59
• @Hedgehog Had not seen that before. I think that might work for eliminating the buffers as I had mentioned. Commented Jul 14, 2022 at 20:20

Here is a simple circuit using one op-amp that will do what you want.

The red trace shows linearity: V(out) / (V(in)-4).

This assumes you have a 24 V supply available.

E24 series resistors

• Why have so many resistors in series and parallel? Commented Jul 15, 2022 at 18:46
• @PStechPaul I've used standard value E24 series resistors which are easily obtainable and connected them as required to get the precise resistance values needed for the design.
– user173271
Commented Jul 15, 2022 at 23:46