# scaling voltage with Op Amp for microcontrol simulate this circuit – Schematic created using CircuitLab

So I am having trouble trying to figure out how to scale voltage from 22-32V to 0-5V. I know that Vout= 0.5Vin - 11 will give me the proper voltage values I need. I am trying to monitor the voltage of a battery with my Arduino.

I tried doing a voltage divider for R1= 54K and R2=10k. When Vin=32 I do get Vout=5V, but when Vin=22 Vout=3.43. I have read that a third resistor or Op amp will help but I am just not sure how to pick the third value. How can I include the bias needed? Any links or examples would be greatly appreciated. simulate this circuit – Schematic created using CircuitLab

First solve the transfer function in terms of non-inverting gain and offset. Vout=(Vin-22)/2
=Vin/2-11
= (Vin/4)(1+|Av-|) -11V for Av-=-1 ( thus 4:1 divider and unity inverting gain )
Vout = Vin/2 -11V
e.g. 22V/2-11=0
e.g. 32V/2-11=5

You need to reduce the voltage range from 10 volts to 5 volts so you definitely need an equal-value-resistor attenuator but if you connect the "bottom" resistor to -22 volts instead of 0 volts you get what you want.

So when +22 volts is applied you get 0 volts out and, when +32 volts is applied, you get 5 volts out. That is the simplest way of doing it. You can add the op-amp to buffer the output.