digitaleclab.com
Tutorials

Arduino current measurement using ACS758 and ADS1115 – 16 bit ADC

Introduction

In electronics there are a number of ways to measure current in a circuit. In this blog I will be discussing about one of the most popular type of current measurement technique. If you search on google about measuring current, you will find the ACS712 sensor. These sensors are quite hand and cheap. These comes in 5Amp, 20Amp and 30Amp versions. But do you know there is a bigger brother of this also?

Yes you read it right, the ACS758 family of sensors. These comes in 50Amp, 100Amp, 150Amp and 200 Amp versions. That means you can measure a whole lot of current using these ACS758 sensors. But these comes with a trade off in precision. As you go on increasing current measurement capabilities, you loose precision in measurement.

Download datasheet of ACS758 here.

digitalel ectronics circuits lab acs758 datasheet

If you look into the sensitivity column in the image above, you can notice that the sensitivity decreases from 40mV/A to 10mV/A as you go from 50A to 200A version. If you choose the unidirectional one, you may get a little more resolution but still it won’t be much helpful. I discuss the reason in the later part of this blog.

Another point to note is the amount of noise that each of these sensors introduce. Since this is hall effect base sensor which means it uses magnetic field to detect current flow, it is fairly easy to catch noise from some magnetic devices kept nearby. Here is the table which shows the amount of noise with change an voltage and with each variant.

So now if I consider the ACS758 50B which is bidirectional 50 ampere variant, you can clearly see there is a noise of 10mV. With a sensitivity of 40mV/A we have a noise of 10mV. To deal with this noise we have to implement this sensor in our circuit so that we can educe its effect to minimum.

Current measurement parameters

In this blog I will be discussing the parameters which we have to consider for ACS758 50B.

acs758 50b

This sensor will output analog voltage in the output pin when current flows though the current path. To calculate the current from voltage reading in our microcontroller, we have to convert the analog signal to digital using ADC. Now, Arduino has a 10 bit ADC in its port C pins. A 10-bit ADC has values from 0 to 1023. That means if we have a 5V supply to Arduino reference, it can measure 5/1024 = 0.00488 V = 4.88mV per ADC value.

Now our sensor has a sensitivity of 40mV/A which means there will be a change in 40mV at the output pin for every 1 amp of current. So with Arduino 10-bit ADC we will have 40/4.88 = 8.196 which implies 8 ADC values for every 1 amp current. So we can measure up to an accuracy of 125 mA. If this is okay for you, then you can use the simple code in the next section. But if you want more accuracy in measurement the continue reading this blog till end because I will be discussing how you can measure current up to an accuracy of 4.6 mA!

Code for direct measurement with Arduino’s internal 10-bit ADC

digitaleclab.com schematic
Schematic

Using ADS1115 16-bit ADC with Arduino

Now I will discuss about using an external 16-bit ADC to get more precise measurement. In this example I will be using ADS1115 to demonstrate and write the code for the same.

ADS1115 digital electronics circuits lab

This IC uses I2C bus to communicate and send data to the microcontroller. There is a library in Arduino to use this by Adafruit. Here is the link to the Adafruit ADS1X15 library in github. You can also search this library in the Arduino IDE in library manager.

Here is the link to ADS1115 datasheet.

The ADS1115 provides 16-bit precision at 860 samples/second over I2C. The chip can be configured as 4 single-ended input channels, or two differential channels. As a nice bonus, it even includes a programmable gain amplifier, up to x16, to help boost up smaller single/differential signals to the full range. We like this ADC because it can run from 2V to 5V power/logic, can measure a large range of signals and its super easy to use. It is a great general purpose 16 bit converter.

Calculating parameters for our use

This device can be powered from 0 to 7V maximum. But the programable gain amplifier can measure from ±256 mV to ±6.144 V. Since it is measuring bidirectionally, we can have ADC values from -32768 to +32768. By default, the internal programable gain amplifier is set to 2/3x gain which gives you and input analog voltage range of ±6.144 V. You change the gain by using any one of these line of code.

ads.setGain(GAIN_TWOTHIRDS);  // 2/3x gain +/- 6.144V  1 bit = 0.1875mV (default)
ads.setGain(GAIN_ONE);        // 1x gain   +/- 4.096V  1 bit = 0.125mV
ads.setGain(GAIN_TWO);        // 2x gain   +/- 2.048V  1 bit = 0.0625mV
ads.setGain(GAIN_FOUR);       // 4x gain   +/- 1.024V  1 bit = 0.03125mV
ads.setGain(GAIN_EIGHT);      // 8x gain   +/- 0.512V  1 bit = 0.015625mV
ads.setGain(GAIN_SIXTEEN);    // 16x gain  +/- 0.256V  1 bit = 0.0078125mV

Warning!!! Be careful before changing the gain settings. If your analog input voltage is more than the set amplifier gain, then it might destroy the chip completely. I recommend to keep it at default setting.

In this example I will power it with 5V supply. So I have no other option to change the PGA gain. So at 5V the maximum ADC value will be 26666.

We know that the quiescent output voltage of ACS758 when primary current is zero, is around VCC/2. When we power it with5V supply, its output will be 2.5 V at zero current flowing. So now this 2.5 V is equivalent to 13333 ADC value, which is out zero set point.

Code for measuring current using ADS1115 and ACS758

Here is the schematic to connect the three device:

digitaleclab.com schematic

For writing the code I will be using the Adafruit ADS1X15 library which I mentioned before. In order to get the ADC value of pin 0, we have to use:

adc0 = ads.readADC_SingleEnded(0);

To get the analog voltage input at pin 0, we will use this line of code:

volts0 = ads.computeVolts(adc0);

To calculate the current in amperes, we will use this this line of code:

current = ((adc0 - 13333) * 0.1875 / sensitivity);

Since I am using the default gain amplifier value (2/3x gain), I have to multiply the ADC value with 0.1875. If you change the PGA gain remember to change this value in the code as well.

You can download the complete code by clicking on the download button. After uploading you will get the measured current in serial monitor.

Video Link

If you have any issues or suggestion, you can comment below. Please subscribe to my YouTube channel for video tutorials and experiments. If you find this blog helpful, you can support me by any amount of donation in the Donate and Support section.

One thought on “Arduino current measurement using ACS758 and ADS1115 – 16 bit ADC

  1. This video and data has been very helpful..I am using a ESP 32 and its ADC is crap but it is much faster than the arduino and the ADS1115 doing extactly what you have done should solve this issue.

Leave a Reply

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