 # John Errington's Experiments with an Arduino

## Voltage measurement with the Arduino board (cont).

When measuring a voltage external to your system - for example logging computer power supply voltages - an accurate reference voltage is essential.  However when making measurements within your own system this may not be necessary.
Lets look at some different approaches.

NOTE: for optimal accuracy in examples 2, 3, 4 its necessary to calibrate the measurement system.

### 1: measuring a proportion of the supply voltage

Here we have no problems. Suppose you are using a simple potentiometer type sensor, like you find in a joystick or gamepad. Moving the joystick moves a sliding contact that taps off a fraction Vp of the applied voltage (see diagram). Suppose the potentiometer is set to 1/4 of its travel.  When the USB supply voltage is exactly 5V the voltage from the pot. will be
Vpot = 1/4 * 5V = 1.25V
Using the USB supply as reference this gives a reading of
n = 1.25V / 5V * 1024 = 256
If the USB supply falls to 4.40V the voltage from the pot changes to Vpot = 1/4 * 4.40 = 1.10V
Using the supply as reference this gives a reading of
n = 1.10V / 4.40V * 1024 = 256.
You can see the value of the supply voltage has no effect on the sensor reading.

### 2:  measuring an external voltage above 4V

We can use the same idea of a potentiometer to scale down voltages above the supply voltage so that the Arduino can measure them.  Here once again we need to use the 4.096V reference for good accuracy. The diagram shows an Arduino used to measure voltages in the range 0 - 8V According to the data sheet
"The ADC is optimized for analog signals with an output impedance of 10k or less. If such a source is used, the sampling time will be negligible. If a source with higher impedance is used, the sampling time will depend on how long time the source needs to charge the S/H capacitor, which can vary widely. The user is recommended to only use low impedance sources with slowly varying signals, since this minimizes the required charge transfer to the S/H capacitor."  (2: 26.6.1)

For this reason we choose a divider network that will provide a source of this impedance
(22k //22k = 11k)

### 3: measuring other external voltages

For positive voltages we use the same circuit as above, but simply change the divider chain. Lets design a circuit to measure in the range 0 - 20V. The divider needs to present a voltage of 0 - 4V at A0, so for a 20V input we will have 4V across R2 and 20 - 4 = 16V across R1. We need a ratio R1:R2 of 4:1, such that R1 // R2 = 10k.

Choosing R2 = 12k and R1 = 47k gives the range we need, with a source resistance of 9.6k

### 4: measuring negative voltages

We can also use the voltage divider network (with care) to measure negative voltages. Here we have a resistor R1 at the input, and R2 is connected to our 4.096V "supply". Suppose Vin = -20V. Then the voltage across the whole chain = 20+ 4.096 = 24V

24V / 12k + 62k = 24 / 74k = 0.324mA *see below

this gives a voltage across R2 of V = 0.324mA * 12k = 3.88V

when Vin = -20V then VA1 = 4.096 - 3.88 = +0.20V

When Vin = 0V then VA1 = 4.096 * 62 / 74 = + 3.432V

* Because current is drawn from the reference diode circuit we need to change the resistor (R560 previously)

It = 0.4 + 0.128 + 0.324 = 0.85 mA.

new R = 4.400 - 4.096 / 0.85 = 330 ohms.

Imax = 5.25V  - 4.096 / 0.330k = 3.5 mA (which is still within the required range i.e. <15mA)

Acknowledgements: All diagrams drawn with MeeSoft Diagram Designer