Reading a Current Shunt with an Arduino

Share on facebook
Share on google
Share on twitter
Share on linkedin
A VPN is an essential component of IT security, whether you’re just starting a business or are already up and running. Most business interactions and transactions happen online and VPN

Current shunts are very popular with the Ham Radio, boating, electric vehicle and solar / wind off grid folks, as they allow them to monitor solar and wind power production, power consumption of devices, and the estimated amp hours left in the battery bank, sort of like a “gas gauge” for your batteries.

Previous ADS1115 Arduino / Raspberry Pi post!

Unlike the solid state hall effect types, current shunts drop a small voltage across a calibrated resistor, indicating the amps being passed through the shunt. This allows shunts to report massive amounts of current, in excess of a 1000 amps, depending on the design of the shunt.

Common shunts are rated at 50mv, 75mv, and 100mv output at maximum current (do not exceed 66% of name plate current). The Arduino has a few issues with these shunts. Since the maximum output is just 100 millivolts compared to the Arduino’s range of 0-5v, it’s like trying to read a 5 inch ruler from 10 miles away (worse with the 50mv and 75mv versions). The second issue is the Arduino has a 10 bit analog to digital converter (ADC), so a 100amp / 100mv shunt would have a 4.88 mv per step resolution, or about 5 amps per step (a total of 1024 steps).

We can solve this with a higher bit ADC with an onboard amplifier. We chose a 16 bit ADC that has over 64000 steps (+/- 32768), and up to 16x amplification. This matches a 100mv shunt very well.

The ADC we chose is the adafruit ADS1115. It has 4 single ended channels, or two differential channels. We chose to use differential mode, to eliminate electrical interference (the third issue) in the monitoring circuit, giving us very stable results. This means we can use two shunts per ADS1115. The ADS1115 can have 4 different user selectable I2C addresses, so with only 2 data lines (SCL & SDA), you can monitor up to 8 shunts.

Connections:

Connections are very simple. Adafruit gives a very comprehensive tutorial on connecting and using this sensor for a variety of different purposes, and you can read about it (and download the library) at https://learn.adafruit.com/adafruit-4-channel-adc-breakouts. For our purposes, this is what we needed:

VDD – Arduino +5v
GND to Arduino GND
SCL to Arduino A5
SDA to Arduino A4
ADDR to Arduino GND (one of 4 possible address combinations, see adafruit tutorial for the the others)
A0 to Current Shunt
A1 to Current Shunt

Code:

Although we are using a 100a / 100mv shunt, if you are using a 75mv or 50mv shunt, we added two additional lines in the code you can uncomment depending on which shunt you are using.

#include <Wire.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */

void setup(void)
{
  Serial.begin(9600);
  
  ads.setGain(GAIN_SIXTEEN);    // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
  
  ads.begin();
}

void loop(void)
{
  int16_t results;
  
  results = ads.readADC_Differential_0_1();  
  
  Serial.print("Amps: ");
  
  float amps = ((float)results * 256.0) / 32768.0;//100mv shunt
  //amps = amps * 1.333; //uncomment for 75mv shunt
  //amps = amps * 2; //uncomment for 50mv shunt
  
  Serial.println(amps);

  delay(5000);
}



Order a complete current sensor board with 100a / 100mv shunt for only $65




Steve Spence

Steve Spence

Leave a Reply

22 thoughts on “Reading a Current Shunt with an Arduino”

  1. In your solar system, how to you manage the grounds? Ie the shunt is presumably low side, and the battery and monitoring grounds in common, or at least the more negative side of the shunt as the common ground?

  2. I understand the circuit and how it works. My question is about having a common ground. If you were to power your circuit from the same power source being measured(in your picture it looks like a vehicle), you would be supplying 12+ volts to the analog input pins in reference to ground. I was not sure if this would be a safe condition. Where you are asking the board to only measure difference, I wasn't sure if this would keep the board safe or if it measured A0 to ground and A1 to ground and then determined the difference.

    If this would cause a problem, how could you power the Arduino from the same source safely?

    Last question, powering the Arduino from the same source, however it would have to be, could you then safely measure the source voltage through the appropriate divider on a third analog input? A divider would require a common ground wouldn't it?

    The short question if you will, how can I safely power a circuit from the same source it is measuring current and voltage?

  3. I am not delivering 12v to the analog pins. I am measuring the voltage across the two points of measurement. Not ground. There is no problem powering thew arduino from the same source you are measuring. Yes, you can measure voltage using a voltage divider, and have 12v on the top of the divider, and common ground on the bottom.

  4. Awesome!! thanks a lot this is super helpful as I already have a shunt with my battery monitor and the dc hall sensors are very expensive.

    what happened to your website? seems to be down. is there anywhere we can see your whole monitor setup?

    thanks again!

  5. Build it! Thanks! It will be in a Sailing boat for measuring the Amp for loading the battery banks.
    Great you added the diferent shunts. Makes it a lot easyer.

    Thanks for sharing!!!

  6. Hello dear friend
    Thank you so much for sharing
    but i can't understand how you calculate the current for each amount of shunt.
    can you explain the current formula in your sketch?
    Thank you

  7. Thank you for your tutorial. Can you please explain me the math of this line:
    float amps = ((float)results * 256.0) / 32768.0;
    I'm trying to use this script for a 300A 75mV shunt.
    Thanks a lot.

  8. Will this all work fine if it is bidirectional i.e. charging/discharging = (100A 75mV) -75mV/+75mV?
    Or would it need to be modified to point 2.5V = 0A?

  9. I'm using ADS 1115 and module I2C and sadly I2C and ADS1115 use the same analogic door (A4 and A5), Can I change it ? if I can, how? I'm waiting for your answer. thank you.

  10. The ADS1115 is I2C. I2C can handle many devices, as each have their own address. Just connect in parallel, and make sure each device has a different address. The ADS1115 address can be changed if it conflicts with another device.

  11. A pi does not have a analog input. Did you use a ads1115 ADC? That would have isolated the connections to the pi. Did you power the ADS1115 with 3.3v? That would give you the capability to measure a maximum differential voltage of 3.6v. If you powered with 5v, then you need a level shifter on the I2C lines.

  12. G'day. I can't seem to get any other read out other than .02amp. Any suggestions on where I can start to problem solve. I have had up to 50amps pulling thru my 100amp, 50mv shunt just to try and get a reading.

    Thanks in advance

  13. If you measure a negative current, you will have a negative voltage relative to your digital ground and even though your differential negative voltage will be fine, an absolutely negative voltage input to your ADS is not allowed according to the datasheet. Any solutions?

  14. I designed a simple solar lead acid battery charger & wanted to measure the current going in to (or out of) the battery bank via a 75mV/50A shunt.

    I tried putting the shunt on the high side & using a differential input to measure the voltage across the shunt as shown. Charger, battery bank & Arduino ground were all tied together/common. Charger positive output was put through the shunt before going to the battery bank positive terminal.

    Once power was applied the ADS1115 doing the differential reading immediately popped & let out the magic smoke. The other ADS1115 reading the voltages continued to work.

    So it appears as if I’m missing something when it comes to high side differential voltage measurement with a common ground. After some research I think I will go with a INA219 based circuit for my design.

  15. Felani Mohd Tauhed

    Hye Steve,

    Which means one ADS1115 can measure up to only 2 shunt resistor in a one time isn’t?
    Is it have a way how to get 4 shunt reading in one arduino?

    1. Felani Mohd Tauhed

      And now I get fluctuating result use your sketch above..even though i put RC Low Pass Filter before ADS..any Idea why?

Leave a Comment

Your email address will not be published. Required fields are marked *