Anda di halaman 1dari 12

ACS758 Arduino Current Sensor Tutorial

Measuring Higher Current with your Arduino

The Allegro AC758 allows for high current measurements. Coupled with
the isolation benefits of a hall sensor, the power supply requirements and output values make it a
nice fit for an Arduino.

My bench tests show the module to be very functional. What’s not included in these tests is a
determination of whether the module is fit for long term continuous service at peak current. If your
intent is to create a permanent solution, I would do that analysis.

Otherwise I would consider it a nice proof of concept device.

Finding an ACS758
Given the current sensor range, I would consider these reasonably priced.

eBay Amazon

ACS758 Pin Outs


There are only three connections to your Arduino. The other two connections are to be placed in
series with your load. The ‘forward’ and ‘reverse’ labeling is relative to conventional current flow
theory.

ACS712 Arduino AC Current Tutorial


How to Measure AC Current with an Arduino and an
ASC712
The cool thing about an ACS712 is that current is measured is measured in two directions. What this
means is that if we sample fast enough and long enough, we sure to 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 line or mains power, we know that waveform to be a SINE wave. Knowing
that allows us to apply a basic electronic formula to yield a decent result.

This tutorial will show you how this is done.

Getting an ACS712
They are readily available at any of the following vendors:

ACS758 Current Sensor Scale Factors and Offsets


The ACS758 is offered in four ranges. Each offered range is available as either a uni-directional
sensor or a bi-directional sensor.
The bi-directional sensors will measure current in both directions and are useful when measuring
current flowing into or out of a battery.

The uni-directional sensors measure current in one direction only and thus allow for a larger scale
factor. This larger scale factor, when properly designed for, can offer better measurement resolution.

Successfully using this sensor requires applying the correct scale factor and offset. The table below
is derived from the ACS758 Datasheet.

Range Direction Scale Factor Offset

50 Amp Uni-directional 60 mV per Amp 0.6 Volts

50 Amp Bi-directional 40 mV per Amp 2.5 Volts

100 Amp Uni-directional 40 mV per Amp 0.6 Volts

100 Amp Bi-directional 20 mV per Amp 2.5 Volts

150 Amp Uni-directional 26.7 mV per Amp 0.6 Volts

150 Amp Bi-directional 13.3 mV per Amp 2.5 Volts

200 Amp Uni-directional 20 mV per Amp 0.6 Volts

200 Amp Bi-directional 10 mV per Amp 2.5 Volts

ACS758 Arduino Tutorial


Connect the ACS758 to your Arduino and Load

Key in the picture below is the reminder to make solid connections. Things heat and burn pretty
quickly if you don’t.
Upload the Arduino ACS758 Tutorial Sketch

The example code here should be modified to match your particular sensor. Either refer to the
comments in the code or in the table above.

/*

Henry's Bench

ACS758 Current Measurement Tutorial

*/

const int analogIn = A0;

// Set your scale factor


int mVperAmp = 40; // See Scale Factors Below

/* Scale Factors

50A bi-directional = 40

50A uni-directional = 60

100A bi-directional = 20

100A uni-directional = 40

150A bi-directional = 13.3

150A uni-directioal = 26.7

200A bi-directional = 10

200A uni-directional = 20

*/

// Set you Offset

int ACSoffset = 2500; // See offsets below

/* Offsets

If bi-directional = 2500

If uni- directional = 600

*/
int RawValue= 0;

double Voltage = 0;

double Amps = 0;

void setup(){

Serial.begin(9600);

void loop(){

RawValue = analogRead(analogIn);

Voltage = (RawValue / 1023.0) * 5000; // Gets you mV

Amps = ((Voltage - ACSoffset) / mVperAmp);

Serial.print("Raw Value = " ); // shows pre-scaled value

Serial.print(RawValue);

Serial.print("\t mV = "); // shows the voltage measured

Serial.print(Voltage,3); // the '3' after voltage allows you to


display 3 digits after decimal point

Serial.print("\t Amps = "); // shows the voltage measured


Serial.println(Amps,3); // the '3' after voltage allows you to
display 3 digits after decimal point

delay(2500);

Measuring AC Current with the ACS758


The ACS758 can be used to measure AC Current. To measure AC current of a clean sine wave,
you can refer to the tutorial for the ACS712.

How to Measure AC Current with an Arduino and an


ASC712

The cool thing about an ACS712 is that current is measured is measured in


two directions. What this means is that if we sample fast enough and long enough, we sure to 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 line or mains power, we know that waveform to be a SINE wave. Knowing
that allows us to apply a basic electronic formula to yield a decent result.

Discussion of the Basic Methology Applied


Finding the RMS Value

In most cases, an expression of AC current will be in a value known as RMS. In order to use the
ACS712 current sensor to measure AC current, it is important to understand how to calculate an
RMS current value from the device readings.

The formula that is applied here is very basic and is right out of any basic electricity or electronics
manual.
With an ACS712, current measurements are reported with a voltage output. In this tutorial, we will
calculate the RMS volts and apply the ACS712 scale factor.

Conversion for a sine wave with a zero volt offset (like your mains or line power) is performed as
follows…

1) Find the peak to peak voltage ( Volts Peak to Peak )

2) Divide the peak to peak voltage by two to get peak voltage (Volts Peak)

3) Multiply the peak voltage by 0.707 to yield rms volts (Volts RMS)

Having Calculated RMS voltage, is simply a matter of multiplying by the scale factor of the
particular ACS712 to yield the RMS value of the current being measured.

Arduino Sampling for the Peaks

The values out of the ACS712 are constantly changing when measuring AC Current. In order
ensure that you have come very close to finding the peaks, you need to sample fast enough and long
enough. Because mains or line power is at a frequency of 50 to 60 hz, the Arduino will be fast
enough provided it takes consecutive samples with little or no interruption.

In this tutorial, there is a function dedicated to doing just that.

Arduino ACS712 Current Measurement Tutorial


NOTE: This works for lower voltage measurements and perhaps experimentally at a higher line
voltage. This should not be used in a permanent line voltage application.

Arduino ACS712 AC Measurement Tutorial Setup

Fundamental to performing this tutorial safely is knowing what the current rating of your ACS712
and the amount of current that your load requires.
Connect the components as shown

below:

The ACS712 Arduino AC Current Tutorial Sketch

Copy, Paste and Upload the code below. Also take a look at how I make a call to the ‘getVPP‘
function from the main loop. In that function, I take interupted AC samples for one second while
recording the maximum and minimum values. From this I will calculate the peak to peak voltage
measured. I’ve found this to be extremely effective for line power frequencies.

Mind you, my power is pretty clean. If you’ve got a lot of spikes, getting a meaningful measurement
could be tough.

/*

Measuring AC Current Using ACS712

*/

const int sensorIn = A0;


int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module

double Voltage = 0;

double VRMS = 0;

double AmpsRMS = 0;

void setup(){

Serial.begin(9600);

void loop(){

Voltage = getVPP();

VRMS = (Voltage/2.0) *0.707;

AmpsRMS = (VRMS * 1000)/mVperAmp;

Serial.print(AmpsRMS);
Serial.println(" Amps RMS");

float getVPP()

float result;

int readValue; //value read from the sensor

int maxValue = 0; // store max value here

int minValue = 1024; // store min value here

uint32_t start_time = millis();

while((millis()-start_time) < 1000) //sample for 1 Sec

readValue = analogRead(sensorIn);

// see if you have a new maxValue

if (readValue > maxValue)

/*record the maximum sensor value*/


maxValue = readValue;

if (readValue < minValue)

/*record the maximum sensor value*/

minValue = readValue;

// Subtract min from max

result = ((maxValue - minValue) * 5.0)/1024.0;

return result;

Anda mungkin juga menyukai