Tuesday, June 2, 2015

Mailbag Arrival !! ACS712 Current Sensor Board




   Because of the very cheap ACS712 Current Sensor Board modules available all over the place, I really think that everybody heard about ACS712 sensor from Allegro MicroSystems.

  As I was asked if "Can be used as a current sensor module for our ESP8266 Projects without too much hustle?", I ordered few of them and let's explore them for the answer :)

   The ACS712 device consists of a precise, low-offset, linear Hall circuit with a copper conduction path located near the surface of the die. That means that it is a isolated path device, a very nice thing if you want to monitor MAINS Current or any other High Voltage path that you want isolated from your device.

IMPORTANT NOTE !!  This device is a Hall Effect transducer.  It should not be used near significant magnetic fields.  If you have a magnetic noisy environment take a look at other solutions like isolation transformers, isolation OpAmps, linear isolation circuit, bus path isolation, etc.


 Theory of operation 

 Applied current flowing through the ACS712 copper conduction path generates a magnetic field which the Hall IC converts into a proportional voltage. Device accuracy is optimized through the close proximity of the magnetic signal to the Hall transducer.
A precise, proportional voltage is provided by the low-offset, chopper-stabilized BiCMOS Hall IC, which is programmed for accuracy after packaging.

  The ACS712 outputs an analog signal, VIOUT that varies linearly with the uni- or bi-directional AC or DC primary sampled current, IP (between IP+ e IP-) within the range specified.

  It requires a power supply of 5V (VCC) and two capacitors to filter power supply and output.
CF is recommended for noise management, with values that depend on the application.

Typical application from the Datasheet: 



   ACS712 Current Board comes in 3 different models of this integrated circuit, depending on the maximum measured current : 5A  20  or  30A

5A Module20A Module30A Module
Supply Voltage (VCC)     5VDC     5VDC        5VDC
Measurement Range   -5 to +5 A   -20 to +20 A        -30 to +30 A
Voltage at 0A   VCC/2     VCC/2      VCC/2
Scale Factor   185 mV/A   100 mV/A      66 mV/A
Variant  ACS712ELC-05A   ACS712ELC-10A     ACS712ELC-30A


   For our today experiment, I will use the one below, a 100mV/A one:




What we will need:
  •  ACS712 Current Board module (pick your desired choice -  5A, 20A, 30A )
  • CBDB Board ( or any other ESP8266 Board you may like but who has the same capabilities)
  •  USB adapter (take a look on Part 1 for details about the USB Adapter 
  •  2 x 10 Ω /10 W  - Load resistors
  • Connection wires - various colors
  • Breadboard
  • Bench Power Supply 
  • Voltage Level Shifter and dc amplifier module - VLSAM DC(see details below)


Voltage Level Shifter and amplifier module - VLSAM DC

  As our main goal is to explore the posibility to use the ACS712 module with ESP8266 devices, from the description above and datasheet we can identify very quick some problems that need to be solved to make ACS712 a "ESP Friendly" device:

ASC712: 
  •  5 Vdc power supply device
  •  measure positive and negative 5/20/30Amps, corresponding to the analog output 100mV/A BUT
  • "ZERO" point, means no test current through the output voltage is VCC / 2 =5v/2=2.5V !

ESP8266:
  • 3V only device
  • ADC range  max: 0-1V

  What we will need is to "move" the "ZERO" point as low as we want to GND and in the same time to amplify the received analog signal to obtain a better resolution in the desired measuring range. (don't forget, for our experiment we have DC only voltage here and just one current flow direction)

   So, what can be done? 

Probably they are some other solutions to this problem, and if you know any of them, please feel free to share in the comments below, but the clasical one is to use a difference amplifier:





    This kind of amplifier uses both inverting and non-inverting inputs of a OPAmp with a gain of one to produce an output equal to the difference between the inputs. Actually if you take a closer look it is a special case of the differential amplifier.
   The good thing is that in the same time you can also choose the resistances values in a way to amplify the difference

    If all the resistor values are equal, this amplifier will have a differential voltage gain of 1. The analysis of this circuit is essentially the same as that of an inverting amplifier, except that the noninverting input (+) of the op-amp is at a voltage equal to a fraction of V2, rather than being connected directly to ground. As would stand to reason, V2 functions as the noninverting input and V1 functions as the inverting input of the final amplifier circuit. Therefore:

                  Vout = V2 - V1

    If we want to provide a differential gain of anything other than 1, we would have to adjust the resistances in both upper and lower voltage dividers, necessitating multiple resistor changes and balancing between the two dividers for symmetrical operation.

    A limitation of this simple amplifier design is the fact that its input impedances are rather low compared to that of some other op-amp configurations, most notably the noninverting (single-ended input) amplifier. Each input voltage source has to drive current through a resistance, which constitutes far less impedance than the bare input of an op-amp alone. It is a solution to this problem, fortunately, quite simple,  all we need to do is “buffer” each input voltage signal through a voltage follower.


   For our case, as we want to "substract" the ACS712 - 2.5Vdc to move the "ZERO" point near GND, we will have:
  • V1 = 2.5V - can be easy obtained from 5V with a buffered voltage divider
  • V2 = VIOUT - output voltage from ASC712 Module
  • Amplification:
    • IF R1=R2=R3=R4=10K 
      •  output for ADC input of 100mV/A
      • max range: 10A
      • resolution:  10mA
    • Changing range  R1=R2=10K, R3=R4=100k 
      • output for ADC input of 1V/A
      • max range: 1A
      • resolution: 1mA


VLSAM DC Schematic


And the simulation result for a 0-10A, 2.5-3.5 VIOut sweep:


  • GREEN      - Voltage divider output  : 2.5Vdc
  • FUCHSIA  -  ASC712 VIOut            : 2.5 -> 3.5Vdc
  • RED           -  ADC input                   : 0 -> 1Vdc


So far so good, let's move it on a breadboard for a quick test:




21 comments:

IISFAQ said...

Hi

I am wanting to also use an ESP8266 and ACS712 but i have a problem.

I am using a NodeMCU board.

But a simple sketch

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}

void loop() {
// put your main code here, to run repeatedly:
Serial.println(analogRead(A0));
delay(50);
}

Shows the following values

0.0v = 709
0.1v = 714
0.2v = 720
0.3v = 725
0.4v = 730
0.5v = 738
1.0v = 764
1.5v = 796
2.0v = 827

Removed power = 702
Floating = 747

The power is provided by a Bench Supply with Positive connected to A0 and GND connected to GND on NodeMCU

Any thoughts?

Unknown said...

You should take a look at that speficic board schematic if is not a voltage divider or something on the ADC Input. The problem is with Arduino IDE only or also with NodeMCU LUA?

Also a little bit of filtering near close of the ADC IN pin might help to remove noise from the signal that you want to read.

In case of ASC712, if you have a noisy environment, reducing the filter bandwidth with a proper adjust of the Cf cap can help a lot.

Other commons mistakes:
- drive more than the specified 10 nF maximum capacitance with the output of the device.
- drive less than the specified 4.7 kΩ minimum resistance with the output of the device.

See ACS712 datasheet for more details.

Might worth to take a look at the related articles from below:

- http://www.esp8266-projects.com/2015/03/internal-adc-esp8266.html
- http://www.esp8266-projects.com/2015/06/mailbag-arrival-acs712-current-sensor.html
- http://www.esp8266-projects.com/2015/06/part-2-acs712-current-sensor-board.html

1zu said...

Why not do you use a voltage divider with 2 resistors? This way you convert from 0-5v to 0-1v
I am a newbie in electronics.

Unknown said...

Where exactly do you want to put that voltage divider?

Don't forget about:
-> "ZERO" point, means no test current through the output voltage is VCC / 2 =5V/2=2.5V
-> 100mV/A output for ACS712-20

Give it a try and share the results with us.

1zu said...

I was thinking just theorically. If we have a sensor output from 0 to 5v and the range of the ADC is only 0 to 1v, using a 1K and a 4K resistors at the sensor output, we would get 0 to 1v in the middle of the pair resistors. Is this correct?
And the zero point should be at 0.5v
Unfortunatelly I don't have these hardware yet to test. It's somewhere between far east and Europe :-)
Anyway, congratulations for this wonderful blog. I'm learning a lot.

Unknown said...

Hi everyone,

Check out the ACS711. it runs on 3.3V.

might be a better solution than the 5V ACS712.

what do you guys think?

Unknown said...

I don't see ACS711 as a direct drop-in replacement for ACS712, datasheet quote: "The Allegro™ ACS711 provides economical and precise solutions for AC or DC current sensing in <100 V audio, communications systems, and white goods."

If your needs are covered by the ACS711 working domain, might be.

mrq said...

Thank you for sharing.
The setup you described surely works for measuring DC voltage.
Is it possible to adopt it to measure AC voltage?
Is ESP8266 speed enough? (even without checking out Nyquist theorem, I guess you need long more than 50 samples per second to measure a 50Hz AC voltage)

Unknown said...

ACS712 is for measuring Current not Voltage. Do you mean about measuring AC RMS values or somenthing else?

Unknown said...

...for AC you can base it on the fact that ACS712 is measuring Current in both directions. Means is that if we sample fast enough and long enough, will find the peak in one direction and the peak in another direction.

With both peaks known, it is a matter of knowing the shape of the waveform to calculate the Current. In the case of MAINS power, we know that waveform to be a SINE wave, 50/60HZ. Knowing that allows us to find the desired result with a decent accuracy.

mrq said...

Yes, I mean AC RMS current (Irms), sorry.
I red some other tutorial proposing the same strategy (and I believe it works) but I am looking for a method which substitute things like "fast and long enough" and "decent accuracy" with quantitative and argumented values.
My feeling is that this components are not fast enough to take a lot of samples within a single oscillation of the signal.

Unknown said...

As I said above, probably is working with decent accuracy. If I would need to measure AC Current I will use a some extra hardware for a proper AC RMS converter.

Unknown said...

I am a newbie. While measuring AC current, will AC712 Viout also be AC? If not can I use simple voltage divider in AC712 Viout for measuring AC ? I am trying to use AC712 to measure AC current and want to hook up to ESP8266.
Appreciate your help

Unknown said...

Please see comments above. For AC Current you need to calculate RMS values

Unknown said...

Thanks Tracker. So for AC current measurement if I hook up a capacitor (say like 47uf) to the scaled down output, can I connect it to 8266's ADC?

Unknown said...

For AC current measurements I will suggest you to use a RMS-to-DC converter. It's the easiest way to do it, and way more precise.

Otherlese, you can play with the ADC, you need as many samples necessary to have the proper wave form reconstrunction, peak value, etc and calculate your RMS value based on that. As we are talking about 50/60Hz, ESP8266 ADC might be quick and reliable ennough for something like that. You need many many many samples, obtain the peak value, calculate RMS, and so on.

Have also another idea to try out: You could use a simple external full wave rectifier diode and filter circuit -> read the DC voltage and multiply by some factor to read a some sort of "peak" value. You need a good DMM true-RMS to obtain that factor and some linearity.

Unknown said...

Hey nice project!
But is there a more detailed way of building it on my own?
I already have ESP8266 and some other parts.
Is there no easier way with bought components? Like "I2C Logic Level Converter Bi-Directional Module 5V to 3.3V"

Thank you in advance

Unknown said...

Hi Tracker J very nice project.

Could you maybe give us more details about the connection on the breadboard? Maybe another better picture? Or is it possible to get a design in FRITZING? Or can you draw a circuit? I would love to rebuilt the project but at the moment I have problems to understand! I want to built a measureable power strip...

Unknown said...

on the Breadboard is just the above VLSAM DC Schematic.

Unknown said...

I couldn't find OPA2344 to my local supplier and after some headaches with some classic operational amplifier I arrived to a conclusion:
The OPAmp needs to have rail to rail capabilities with very low voltage swing. I used a MCP6004

TechieLocuras said...

Hello!

I know that maybe I'm asking much, but I have to do a proyect that includes a ESP8266, ArduinoMega 2560 and an ASC712. The ASC712 has to send its lectures to the arduino and then to the ESP8266 (who will send it to internet). I don´t know how to start, and a I have no one who can show (I'm the new girl).
If you have a tutorial o something I'll be forever grateful.

Thanks!

Post a Comment