General

ACS758 050B

userHead shanksxiii8 2015-08-23 15:43:37 17579 Views10 Replies
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);
}
2015-09-20 21:37:58 the reading is correct when I use the maximum data. userHeadPic shanksxiii8
2015-09-12 21:20:33 ok, i'll try it

thank's a lot
userHeadPic shanksxiii8
2015-09-11 10:29:31 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:



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:


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.

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 ?
userHeadPic Leff
2015-08-28 18:22:14 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?
userHeadPic Leff
2015-08-28 18:22:14 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?
userHeadPic Leff
2015-08-27 10:12:59 yes, the reading was not stable. userHeadPic shanksxiii8
2015-08-27 10:12:59 yes, the reading was not stable. userHeadPic shanksxiii8
2015-08-25 13:59:40 Sorry I cannot see your attached picture.

the reading was not stable or not accurate?
userHeadPic Leff
2015-08-25 13:59:40 Sorry I cannot see your attached picture.

the reading was not stable or not accurate?
userHeadPic Leff
2015-08-24 14:20:25 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.
userHeadPic Leff