Measuring voltage with microcomputers

Measuring voltage with Raspberry Pi

This chapter includes short and simple instructions how to do voltage measurements with Raspberry Pi for hobbyist with limited knowledge of electronics.

Arguably the biggest disadvantage of Raspberry Pi is that, unlike its cousin Arduino, it does not have proper analog inputs. That means that all GPIO (general purpose input output) pins are purely digital, so in principle they only supply/recognise two voltages, 0.0V for False state and 3.3V for True state. If you want to read an arbitrary voltage, you need to use ADC (analogue digital converter) circuit and connect it to several GPIO pins.

[ADC Differential Pi] [ADC Pi Plus] [ADS1115]

Picking an ADC microprocessor chip, installing and programming it can be quite a feat, especially for a hobbyist. Fortunately, there are few ready commercial solutions for that purpose, with detailed instructions, program libraries and examples:

All these devices connect to I2C channel of the Raspberry Pi, where AB Electronics devices use two programmable and Adafruit device uses one programmable address. This is a plus, since all your GPIO pins remain free for other uses. All devices also have internal voltage reference, which makes voltage measurement very precise and independent on Raspberry Pi. The basic differences can be seen in the table:

NameVoltage (V)InputsMax. precisionMax. samples per secondImpedance (Ω)Addresses
ADC Differential Pi-2.048 to +2.0488 differential18 bit2402.25M/25M0x68 to 0x6F
ADC Pi Plus0.0 to +5.08 single ended18 bit24016.8k0x68 to 0x6F
ADS1115-3.3 to +3.32 differential16 bit86015M0x48 to 0x4B
0.0 to +3.34 single ended16 bit8606M0x48 to 0x4B

Unless you intend to mimic oscilloscope, the sampling speed is rather unimportant (and in that case you wouldn't use slow I2C channel anyway). Precisions are also comparable and satisfactory for all devices. The essential differences therefore are:

If you want to play safe, there is a relatively simple solution: you can buy ADC Differential Pi or ADS1115 and build a small simple voltage divider yourself. This is explained in the next section.

Building a simple and compact voltage divider

This chapter includes short and simple instructions how to build a simple and compact four channel voltage divider for hobbyist with limited knowledge of electronics.


We have to start with a principle of a voltage divider. This are essentially two resistors R1 and R2 in series attached to the source voltage Vin, as shown on the picture above. Voltmeter is attached to the second resistor R2 only. Since voltmeter internal resistance is very large, much larger than resistances R1 and R2, we can safely assume that the current through voltmeter IV equals zero. Then the current through both resistors I and voltage on the second resistor and voltmeter Vout can be easily evaluated.

Resistances must be carefully picked and should be much smaller than voltage internal resistance, but still as large as possible. For our needs values around 10kΩ are appropriate. Knowing the maximum source voltage and maximum voltmeter voltage, one can pick a suitable pair of resistors to do the voltage transfer. Note that widely available resistors come in discrete values, typically 1kΩ, 1.2kΩ, 1.5kΩ, 1.8kΩ, 2.2kΩ, 2.7kΩ, 3.3kΩ, 3.9kΩ, 4.7kΩ, 5.6kΩ, 6.8kΩ, 8.2kΩ, 10.0kΩ, etc.

Suppose that we want to transfer 5.0V to 2.048V, which is maximum voltage of ADC Differential Pi. Some of the suitable combinations are R1=10.0kΩ R2=6.8kΩ (used by ADC Pi Plus) and R1=6.8kΩ R2=4.7kΩ. In my demonstration below, I use the second combination.


In order to build four channel voltage divider, we need prototype board with copper stripes, breakable male pin row and at least eight resistors of power 1/8W and tolerance 1%, four of resistance R1 and four of resistanceR2. Tolerance of 1% is essential to get a reliable voltage value, while still being very cheap and easy to obtain. The final result can be improved by buying ten resistors of each value and pick four having resistivity closest to the average value.

[grahphic] [front side] [back side]

In order to create a compact four channel voltage divider, we cut out a board with seven stripes each containing ten holes, as shown on the left picture. Resistance of horizontal resistors is R1, while resistance of vertical resistors is R2. Connections under R1 resistors should be broken by scratching the copper stripe, as shown on the right picture. Top left pins can be connected to positive poles of four input source voltages Vin, while top right pins are connected to positive poles of four voltmeter voltages Vout. Bottom left connectors represent the ground and are connected to negative poles of source and voltmeter voltages.

Please report what else would you like to see here, suggestions, new tricks etc. to the author using feedback form.

Created by Marko Pinteric: feedback form.

Updated . Web page has been read by visitors since September 2004.

Valid XHTML 1.0! Valid CSS!