how to measure dc current through device

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
I want to measure DC current (0.2 A to 30 A) through device. I did the research on internet and found some information that I can use ACS712 to measure current and mcp3008 ADC

current through load --> ACS712---->ADC---->Microcontroller ---> LCD

I have doubt in two questions

1. Do I need any other part to measure DC current (0.2 A to 30 A) through device?
2. ADC give output value. It gives voltage value or current value ?
 

nsaspook

Joined Aug 27, 2009
13,087
1. You just need the correct range module and power but a precision 5vdc voltage source for the module and ADC reference will improve measurement accuracy and repeatability when scaling the results.
2. You measure a voltage that scales to the current depending on the module.

Sensor Specifications
5A Module 20A Module 30A Module
Supply Voltage (VCC) 5Vdc Nominal
Measurement Range -5 to +5 Amps -20 to +20 Amps -30 to +30 Amps
Voltage at 0A VCC/2 (nominally 2.5Vdc)
Scale Factor 185 mV per Amp, 100 mV per Amp, 66 mV per Amp
Chip ACS712ELC-05A ACS712ELC-10A ACS712ELC-30A
 

LesJones

Joined Jan 8, 2017
4,174
I have not used any of the ACS712 range of current sensors or the MCP3008 so I have just been looking at the data sheets. (ACS712 Data sheet MCP3008 Data sheet) I think the scaling of the ACS712 output is proportional to the supply voltage so if the reference voltage for the ADC is derived from this supply I think it would compensate for small variations in this supply voltage. You will need to read the data sheets carfully to confirm to confirm if I am correct.
The output of the ADC is a 10 bit binary number (0 to 1023 decimal 0 to 03FF hex) This will represent the input voltage to the ADC. The current will be calculated from this voltage reading and the scaling factor of the version of ACS712 that you are using. (I think you will be using the 30 amp version so I think the scaling factor will be 66 mV per amp. ) You will read the output value from the ADC via it's SPI interface.

Les.
 

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
2. You measure a voltage that scales to the current depending on the module.
The output of the ADC is a 10 bit binary number (0 to 1023 decimal 0 to 03FF hex) This will represent the input voltage to the ADC. The current will be calculated from this voltage reading and the scaling factor of the version of ACS712 that you are using. (I think you will be using the 30 amp version so I think the scaling factor will be 66 mV per amp. ) You will read the output value from the ADC via it's SPI interface.
Measurement Range - -30 to +30 Amps
Voltage at 0A VCC/2 (nominally 2.5Vdc)
Scale Factor 66 mV per Amp

I don't understand how they calculate current

I got formula one formula in this link https://www.microcontroller-project.com/acs712-current-sensor-with-arduino.html

Current = (AcsOffset - (Arduino measured analog reading)) / Sensitivity

How to calculate dc current value ?
 

-live wire-

Joined Dec 22, 2017
959
I think you just did. For the 30A unit I would recommend a 12-bit ADC voltage result for sufficient resolution of fractional Amp values.
It is very important to have a good op amp before any ADC. That will allow much greater accuracy. So get a shunt like this.
https://www.ebay.com/itm/LA-Series-...186498?hash=item23a088f8c2:g:ocYAAOSwWqNa9GW3
You will want a higher voltage, within reason, for more accuracy. You will want it to be able to handle more current than you expect, as operating components at the max leads to much shorter lifespans.

So 100mV/50A means every amp is 2mV. I assume you want to be accurate within 20-50mA. So that means you need to be accurate down to 40-100uV on the shunt. You will need a good op amp and op amp circuit to get that level of accuracy. Don't listen to those who say you can get that with a good ADC. You absolutely need an op amp.

You can use a higher resistance. So let's say you multiply the resistance by 25 to multiply the voltage by 25. 50 mOhm instead of 2 mOhm. Now it's 1-2.5mV. Much easier to find an op amp with that input offset and low enough noise. But now you have to dissipate 45 watts, as opposed to 1-2W! So you need to use a lower resistance if you don't want to significantly affect your circuit and waste power.
 

nsaspook

Joined Aug 27, 2009
13,087
It is very important to have a good op amp before any ADC. That will allow much greater accuracy. So get a shunt like this.
https://www.ebay.com/itm/LA-Series-...186498?hash=item23a088f8c2:g:ocYAAOSwWqNa9GW3
You will want a higher voltage, within reason, for more accuracy. You will want it to be able to handle more current than you expect, as operating components at the max leads to much shorter lifespans.

So 100mV/50A means every amp is 2mV. I assume you want to be accurate within 20-50mA. So that means you need to be accurate down to 40-100uV on the shunt. You will need a good op amp and op amp circuit to get that level of accuracy. Don't listen to those who say you can get that with a good ADC. You absolutely need an op amp.

You can use a higher resistance. So let's say you multiply the resistance by 25 to multiply the voltage by 25. 50 mOhm instead of 2 mOhm. Now it's 1-2.5mV. Much easier to find an op amp with that input offset and low enough noise. But now you have to dissipate 45 watts, as opposed to 1-2W! So you need to use a lower resistance if you don't want to significantly affect your circuit and waste power.
Good points but the OP spec'd a Hall current sensor circuit so there is no shunt.
 

Reloadron

Joined Jan 15, 2015
7,501
Measurement Range - -30 to +30 Amps
Voltage at 0A VCC/2 (nominally 2.5Vdc)
Scale Factor 66 mV per Amp

I don't understand how they calculate current

I got formula one formula in this link https://www.microcontroller-project.com/acs712-current-sensor-with-arduino.html

Current = (AcsOffset - (Arduino measured analog reading)) / Sensitivity

How to calculate dc current value ?
OK before you overly pursue the ACS712 you may want to view a current manufacturer's data sheet. They do mention:
Recommended Substitutions:
For existing customer transition, and for new customers or new applications,
use ACS723.
Fully Integrated, Hall Effect-Based Linear Current Sensor IC
with 2.1 kVRMS Isolation and a Low-Resistance Current Conductor
ACS712
Date of status change: June 5, 2017
These parts are in production but have been determined to be
NOT FOR NEW DESIGN
. This classification indicates that sale of
this device is currently restricted to existing customer applications.
The device should not be purchased for new design applications
because obsolescence in the near future is probable. Samples are no
longer available.
This is a link to the ACS712 Data Sheet and this is a link to the new suggested replacement ACS723 Data Sheet and the new version offers a good number of feature changes.

With all of that said the ACS723 is designed to measure AC or DC current. When measuring AC current the output is an AC voltage which is proportional to the AC current being measured. This is why the chip has a 2.5 VDC offset on the output. Since the chip uses a single supply an AC output can't swing above and below zero. So they take a VCC of 5 volts and offset the output 5 / 2 = 2.5. Next depending on full scale range we have the sensitivity which for -30 to 30 amp range is 0.066 volts per amp. With 30 amps applied you get 30 * 0.066 = 1.980 Volts plus the 2.5 volt baseline so the actual out for +30 amps will be 4.48 volts. Since the 30 amps can be bi directional if the current was -30 amps then we would subtract 1.98 from the 2.5 and get 0.52 volts. The end result of all of this is that your current sensor senses a current and outputs a voltage proportional to the current it measures.

That voltage can be passed to an A/D (Analog to Digital) converter and the input converted to an engineering unit such as current expressed in amps. We use some software to apply the needed math functions. So if we take our voltage out from the ACS712 and run that voltage into the A/D conversion and we also subtract the 2.5 Volt offset reference. The math can be done in several ways. A 10 bit A/D will take a 0 to 5 volt input and convert it to 2^10 bits or offer up 0 to 1023 bits or quantization levels. That assumes a 5 volt reference is used on the Arduino or other A/D converter. There are several ways to go about this and your first thread linking to Arduino uses samples to get an average which helps eliminate errors. Keeping in mind you stated DC current.

Ron
 

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
I have this wiring

load --> ACS712---->MCP3008---->Pi ---> LCD

I am getting ADC value 856 How to calculate current through load ?
 

Reloadron

Joined Jan 15, 2015
7,501
I have this wiring

load --> ACS712---->MCP3008---->Pi ---> LCD

I am getting ADC value 856 How to calculate current through load ?
OK, the MCP 3008 is a 10 bit ADC converter. Assuming a 5 Volt reference 0 to 5 VDC in is 0 to 1024 bit count. Your ACS 712 at -30 to +30 Amps has a sensitivity of 66 mV / amp. Remember the 2.5 Volt offset when powered with 5 Volts (Vcc/2). You mention a value of 856 so subtract 512 (the offset) and you get 344. The 512 is equal to the 2.5 volt offset. It is also equal to 2,500 mv since 1024 = 5,000 mV. The best resolution using a 10 bit counter is 5 Volts / 1024 Bits = 4.88 mV.

So Amps = ((Voltage - Offset) / mVperAmp) and you know you get 66 mV / Amp.

You take your analog reading in bits and convert it to a voltage 844 / 1024 = 0.8242 * 5 = 4.121 Volts minus the 2.5 Volt offset = 1.621 Volts / 0.066 mV Amp = 24.56 Amps.

A simple Google of "acs712 raspberry pi" should get you a dozen code samples for using the ACS 712 with a Raspberry Pi. The ACS712 gets ADC from the MCP3008. Unlike the Arduino the Raspberry Pi doesn't have analog inputs so you use the Pi to read your A/D converter. You write the code for the Pi to convert the bit count to amps.

I should also point out you may want to look at taking multiple samples and then getting the average. I have never done it with a Pi but it works well using an Arduino. I simply have never written code for a Pi.

<Edit> I have to fix my math. </EDIT>

Ron
 
Last edited:

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
Can i measure dc current by connecting load directly to output of adc ?

Do I need acs712 sensor to measure dc current?
 

Reloadron

Joined Jan 15, 2015
7,501
You obviously need some form of current transducer of your choosing. Depending on that choice you will need some form of signal conditioning.

I want to measure DC current (0.2 A to 30 A) through device. I did the research on internet and found some information that I can use ACS712 to measure current and mcp3008 ADC

current through load --> ACS712---->ADC---->Microcontroller ---> LCD

I have doubt in two questions

1. Do I need any other part to measure DC current (0.2 A to 30 A) through device?
2. ADC give output value. It gives voltage value or current value ?
Your choice how you do it and it has been well explained. So what exactly are you wanting to do? You want purely to measure DC? I gave you a link to the ACS723 which is replacing the ACS712 and if you are measuring only DC the ACS723LLCTR-40AU-T2 is a 0 to 40 Amp version well suited for what you seem to want to do.

There are other ways and methods but you need to decide what it is exactly you want to do.

1. Do I need any other part to measure DC current (0.2 A to 30 A) through device?
2. ADC give output value. It gives voltage value or current value ?

1. Yes
2.Neither, it gives you a bit count proportional to the voltage input.

Ron
 

Travm

Joined Aug 16, 2016
363
Can i measure dc current by connecting load directly to output of adc ?

Do I need acs712 sensor to measure dc current?
1. No But,
2. Yes, But.

If your looking for other cheaper/fewer component methods. You can use a low value shunt resistor and an opamp circuit (some PIC MCU's have opamps built in) to connect to your ADC and read the voltage drop, which is proportional to the current thanks to ohms law.

This method requires a broader understanding of electronics, and math.

Generally using some kind of module will be easier and faster, and more expensive.

As with most things there are 500 different ways to do it, and 200 of them will work. It helps if you explain more about what exactly your trying to do, and sometimes it just confuses people.
 

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
I am trying to figure out problem when I connect load at the output of acs712 it show the output value 756 and when I remove the load it show the same value 756 but it should be show zero value why it show value it doesn't show zero because if no load connected means no current will flow device
 
Last edited:

Reloadron

Joined Jan 15, 2015
7,501
Why would it be zero? The ACS712 provides a voltage out which is proportional to the current it measures. The ACS712 also outputs a DC Offset and the reason for that DC Offset was explained earlier. So if you are powering the ACS712 on 5 VDC the offset at the output will be VCC/2 which is 2.5 VDC.This is the data sheet for the ACS712. Using the 30 Amp version the sensitivity is 66 mV per Amp. The current range is -30 to 30 Amps. So considering the 2.5 VDC offset the Vout will be -30 Amps = 0.52 Volts and 30 Amps = 4.48 Volts.

You apparently decided to use a Raspberry Pi which unlike an Arduino for example does not have an ADC Converter so you need to add an ADC. You mentioned using a MCP3008 which is a successive approximation 10-bit Analogto-Digital (A/D) converters with on-board sample and hold circuitry. So it is a 10 bit A/D converter which means using a 5 Volt reference connected to pin 15 of the chip that a DC input between 0 and 5 VDC is converted into 1024 quantization levels. You are wiring the chip correctly I assume and that Vref is 5.0 VDC correct? You have read the MCP 3008 data sheet correct?

You are using the Rasberry Pi to read the serial data from your MCP3008 which is the bit count out of the A/D conversion. You write your code accordingly remembering to subtract the 2.5 volt (512 bit) offset you started with from your current sensor. A simple Google of "mcp3008 raspberry pi" will give you a dozen examples. If your bit count doesn't change with and without current you have something wrong be it your setup or your code. You may want to post your code?

<EDIT> Also note that I am basing most of this on you using 5.0 Volts. Obviously if you are using 3.3 volts the numbers will be different. You also need to post your code and a good schematic of what you have. </EDIT>

Ron
 
Last edited:

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
This is block diagram only.

I want to measure DC current through load and load is connected at output of mobile charger

output of ADC goes to pi and Pi GPIO runs at 3V3 so I need to run mcp3008 at 3 v DC

upload_2018-9-7_22-1-10.png

Edit mcp3208 used just for connection originally I am using mcp3008
 

Reloadron

Joined Jan 15, 2015
7,501
You have R2 & R3 as a divider and I see no reason for R1? So Vout of the ACS712 will be Vout/2. That means the 2.5 volt offset will be 1.25 volts plus whatever it is measuring at .066 volt/amp. You are not showing what you are using for Vref on your A/D converter pin 15? I also assume everything labeled Ground is ground? You also are not showing what VDD is on your A/D converter?

Ron
 
Top