Using the Raspberry Pi as a Simple Current and Power Meter

On a recent project I needed to fairly accurately measure current and power consumption of a handful of parts in real time. We needed to measure current in the range of micro amps, so this was actually somewhat tricky.

I could have just used a bunch of super expensive current meters, but I managed to find a much more convenient and cheap solution using a Raspberry Pi. We were already using a Pi to allow for remote debugging, so I went looking for something I could hook up to that.

They plug right into the GPIO headers on the Pi and even come with some python libraries for reading them.

Using a tiny shunt resister inline with Vdd, we can use those ADCs to measure the voltage drop across the shunt resister to get the current, and combine that with the voltage at Vdd to the power. We ended up with a circuit that looks like this:

The resulting circuit lets us measure currents from 1uA to 4.6mA with a precision of +-0.5uA, which is plenty good for our purposes. We can also adjust the gains on the ADCs in software to give us more range at the expense of precision.

And we can do it remotely! The Pi can be wired into our hardware, and we can just ssh into it to get live power measurements. And there are 8 channels on those boards so we can measure (and log!) the power consumption of 8 different components simultaneously. It’s super convenient.

Related Posts

Conversation
• James Kavanaugh says:

Can you give the code you used to get the measurements?

• I would like to use the raspberry pi to measure either voltage or current for a high power device with voltage of 12-24 volts and high current. I understand that the raspberry GPIO is limited to small voltage of about 3v and maximum current of a few mA. How can i overcome this problem please

• Martin says:

Hello!
I have a similar problem to yours. The only difference is that the device that I want to use, has a range of values between 0-12V.
I’ve thinked about using a voltage divider before each ADC. It might not be the best option but it might work. Do anybody have any other better suggestion?
Thanks

• James Siedle says:

Hi gents, I have two Pi’s sitting doing nothing and would like to use them as metering devices too. Metering of 8 different circuits 230 v or 380 v (3ph). Can you help with where I get what’s needed to set this up with the Pi? Job do I need you ADC’s to do this and am I right that you can also program the Pi too?

Much appreciated.

• Sanjeev says:

how to use rasp pi as an electricity meter???

• Jeffrey Clifford says:

I’m a bit late to this party but just curious if anyone knows the approximate ideal value of the shunt resistor?