By shanksxiii8
#7604
I am working on ACS758 current sensor which I bought from dfrobot. There is a simple code for this current sensor in dfrobot. I want to make sure that Could I use this code to measure the current of an AC load by arduino UNO?, or it works just for DC loads? What changes I have to do in this code for AC loads? please help me

/*
50A Current Sensor(AC/DC)(SKU:SEN0098) Sample Code
This code shows you how to get raw datas from the sensor through Arduino and convert the raw datas to the value of the current according to the datasheet;
Smoothing algorithm (http://www.arduino.cc/en/Tutorial/Smoothing) is used to make the outputting current value more reliable;
Created 27 December 2011
By Barry Machine
www.dfrobot.com
Version:0.2

*/

const int numReadings = 30;
float readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
float total = 0; // the running total
float average = 0; // the average

float currentValue = 0;

void setup()
{
Serial.begin(57600);
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
}
void loop()
{
total= total - readings[index];
readings[index] = analogRead(0); //Raw data reading
readings[index] = (readings[index]-510)*5/1024/0.04-0.04;//Data processing:510-raw data from analogRead when the input is 0; 5-5v; the first 0.04-0.04V/A(sensitivity); the second 0.04-offset val;
total= total + readings[index];
index = index + 1;
if (index >= numReadings)
index = 0;
average = total/numReadings; //Smoothing algorithm (http://www.arduino.cc/en/Tutorial/Smoothing)
currentValue= average;
Serial.println(currentValue);
delay(30);
}
By Leff
#7605
I want to make sure that Could I use this code to measure the current of an AC load by arduino UNO?

Yes, you can use this code to measure the AC load.
By shanksxiii8
#7609
I use it, for measure motor 1 phasa, the current of that motor is 1 Amp.
and I get the data output like this Image
By Leff
#7611
Sorry I cannot see your attached picture.

the reading was not stable or not accurate?
By Leff
#7620
Hi,

I tested on my side. It's ok~ I tested with a 3A DC voltage, it shows around 3A correctly. But pity that I don't have a chance to use AC power ~ But it's not a problem whether the voltage is AC or DC.

could you show me your wiring diagram? Is it possible that the wire is not correct? Or could you test with an DC power?
By shanksxiii8
#7642
I use it like this

Image

but in the dfrobot wiki, they said "Yes, it can be applied to detect of the current of DC as well as AC load, but remember please connect this module into the target circuit in Series Connection but not Parallel Connection as shown in diagram above."

am I wrong ?
By Leff
#7651
Hello again,

Your wiring is very correct!

Besides, I found a 40W lamp and had a test with 220V AC. Here is what I found:

(80.75 KiB) Downloaded 2150 times


First of all, I found the original sketch could NOT be applied to detect AC current. The readings is supprisingly 0A like there was no power supply, but actually my lamp is very very normal bright. Then I revise the sketch to read the original data :
Code: Select all
float reading = 0;        
float currentValue = 0;

void setup(){
  Serial.begin(115200);
}
void loop() {
  reading = analogRead(*); //Raw data reading
  currentValue = (reading - 510) * 5 / 1024 / 0.04 - 0.34; //Data processing:510-raw data from analogRead when the input is 0; 5-5v; the first 0.04-0.04V/A(sensitivity); the second 0.04-offset val;
  Serial.println(currentValue);
}

And I got the result:
(8.47 KiB) Downloaded 2152 times


It's like a Sine wave data of the AC current, but surely its NOT accurate because the maxmum value 0.27 is less than the absolute minimum value -0.34, they should be equal, I checked so many groups of data, they are all the same, it proves that the readings might be not very reliable.

So then, I think why, except the current is only <1A, while the sensor range is 50A, I think it's a big problem, but I have no other devices in my office.
(20.15 KiB) Downloaded 2152 times

And when I resaw your wiring in your last reply, I guess something! we have already build a low pass filter circuit in the pcb design, and then you add another in your wiring circuit, it seems very rigorous, but it would trim the peak value of the sin data. so it explained why the readings 0.27 is always less than | - 0.34|.

Now, on the one hand, you can try my sketch above to read the sin values_AC current data to see if its acceptable, Ps: remove your low pass filter please.

On the other hand, I will contact the engineer who designed the current sensor module to look for more suggestion.

Pls have a try and update me. Thanks!

shanksxiii8 wrote:I use it like this

Image

but in the dfrobot wiki, they said "Yes, it can be applied to detect of the current of DC as well as AC load, but remember please connect this module into the target circuit in Series Connection but not Parallel Connection as shown in diagram above."

am I wrong ?