**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.

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:

- ADC Differential Pi (picture, left) from AB Electronics uses two Microchip MCP3424 microprocessors,
- ADC Pi Plus (picture, middle) from AB Electronics uses two Microchip MCP3424 microprocessors and
- ADS1115 (picture, right) from Adafruit uses one Texas Instruments ADS1115 microprocessor.

All these devices connect to I^{2}C 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:

Name | Voltage (V) | Inputs | Max. precision | Max. samples per second | Impedance (Ω) | Addresses |
---|---|---|---|---|---|---|

ADC Differential Pi | -2.048 to +2.048 | 8 differential | 18 bit | 240 | 2.25M/25M | 0x68 to 0x6F |

ADC Pi Plus | 0.0 to +5.0 | 8 single ended | 18 bit | 240 | 16.8k | 0x68 to 0x6F |

ADS1115 | -3.3 to +3.3 | 2 differential | 16 bit | 860 | 15M | 0x48 to 0x4B |

0.0 to +3.3 | 4 single ended | 16 bit | 860 | 6M | 0x48 to 0x4B |

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

**Circuit board design**: While ADC Differential Pi and ADC Pi Plus are designed as a Raspberry Pi HATs (Hardware Attached on Top), that can be easily attached to and essentially become integral part of the Raspberry Pi, ADS1115 is designed as a small circuit board which is meant to be put on the breadboard.**Number of inputs**: ADC Differential Pi and ADC Pi Plus have significantly larger number of inputs than ADS1115.**Voltage range**: ADC Differential Pi and ADS1115 have smaller voltage range, with ADS1115 voltage range a bit larger. This voltage can be extended by the voltage divider explained in the next chapter. On the other hand, ADC Pi Plus has voltage range up to 5V, which is probably the highest voltage you need playing with the Raspberry Pi. However, this fact comes at a price. Higher voltage is achieved by the embedded voltage divider, which decreases the impedance of the device. This means that you cannot use another voltage divider and you are practically stuck with top voltage of 5V for good.

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.

**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 *R*_{1} and *R*_{2} in series attached to the source voltage *V*_{in}, as shown on the picture above. Voltmeter is attached to the second resistor *R*_{2} only. Since voltmeter internal resistance is very large, much larger than resistances *R*_{1} and *R*_{2}, we can safely assume that the current through voltmeter *I*_{V} equals zero. Then the current through both resistors *I* and voltage on the second resistor and voltmeter *V*_{out} 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 *R*_{1}=10.0kΩ *R*_{2}=6.8kΩ (used by ADC Pi Plus) and *R*_{1}=6.8kΩ *R*_{2}=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 *R*_{1} and four of resistance*R*_{2}. 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.

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 *R*_{1}, while resistance of vertical resistors is *R*_{2}. Connections under *R*_{1} 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 *V*_{in}, while top right pins are connected to positive poles of four voltmeter voltages *V*_{out}. 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.