Go Down

Topic: Current Sensing Problem with ACS712 ? (Read 3 times) previous topic - next topic

Dileesha

Apr 30, 2013, 01:59 pm Last Edit: Apr 30, 2013, 02:00 pm by Dileesha Reason: 1
Hellow Friends !

I connected ACS712-20A sensor to my home made arduino ( arduino uno ).
( for ACS712 sensor, i bought only the sensor and made the circuitry my self as mentioned in the datasheet )
* for Cf --- > i used 0.1uF instead of 1nF cap

Source connected is 230V AC / 50Hz
Load connected is a 230V AC / 1500W water heater

..........................................................

My problem is the voltage readings are not stable as I was expecting.


My code is below ...
Quote

// the setup routine runs once when you press reset:
void setup() {
 // initialize serial communication at 9600 bits per second:
 Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
 // read the input on analog pin 0:
 int sensorValue = analogRead(A3);
 delay(1);
 // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
 float voltage = sensorValue * (5.0 / 1023.0);
 // print out the value you read:
 Serial.println(voltage);
 delay(500);
}


Serial monitor outputs are as below

Quote
before connecting the load
2.48
2.48
2.48
2.48
2.51
2.50
2.50
2.50
2.51
2.52
2.53
2.48
after connecting the load
2.47
2.50
2.93
3.07
3.00
2.72
2.36
2.05
1.93
2.05
2.37
2.77
2.99
3.06
2.87
2.52
2.06
1.94
1.94
2.22
2.64


I also tried using the EmonLib from openenergymonitor.org . But it didn't work as well.

Your comments are highly appreciated.


Thanks,
Dileesha.
Dileesha Amarasena

Dileesha

#1
Apr 30, 2013, 04:07 pm Last Edit: Apr 30, 2013, 04:17 pm by Dileesha Reason: 1
Hi friends,

Then i tried EmonLib again . I didnt make any change, i just uploaded the EmonLib example ( emonLib > examples > voltage_and_current.ino ) into the arduino ic.

I get some output but it's fluctuating a lot . Please see the results i got in Serial Monitor .

Quote

WITHOUT LOAD
rmsVoltage : 267.22 rmsCurrent : 0.04
rmsVoltage : 268.10 rmsCurrent : 0.04
rmsVoltage : 266.13 rmsCurrent : 0.04 
rmsVoltage : 277.60 rmsCurrent : 0.04
rmsVoltage : 271.81 rmsCurrent : 0.04
rmsVoltage : 219.10 rmsCurrent : 0.03 ( voltage has dropped )
rmsVoltage : 271.05 rmsCurrent : 0.04
rmsVoltage : 259.77 rmsCurrent : 0.04
rmsVoltage : 267.94 rmsCurrent : 0.04


WITH LOAD

rmsVoltage : 254.26 rmsCurrent : 0.44
rmsVoltage : 253.22 rmsCurrent : 0.44
rmsVoltage : 202.97 rmsCurrent : 0.35  ( voltage has dropped )
rmsVoltage : 256.09 rmsCurrent : 0.43
rmsVoltage : 255.41 rmsCurrent : 0.45
rmsVoltage : 251.49 rmsCurrent : 0.43
rmsVoltage : 254.72 rmsCurrent : 0.43



Used arduino CODE is below

Quote
// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3

#include "EmonLib.h"             // Include Emon Library
EnergyMonitor emon1;             // Create an instance

void setup()

  Serial.begin(9600);
 
  emon1.voltage(2, 6340.26, 1.7);  // Voltage: input pin, calibration, phase_shift
  emon1.current(3, 1.1);       // Current: input pin, calibration.
}

void loop()
{
  emon1.calcVI(20,2000);         // Calculate all. No.of half wavelengths (crossings), time-out
  emon1.serialprint();           // Print out all variables
}



Your help will be highly appreciated .

Thanks,
Dileesha.
Dileesha Amarasena

Riva

You could try doing a average reading to smooth out glitches. Try either a rolling average (2 samples) or sample and add the value x times then divide by x to get average.

Dileesha

@Riva

Thanks for your comment.

Could you please show me how to make that change to the code ?

Im a newbie, so i don't know much coding work.

Thanks.
Dileesha Amarasena

Riva

#4
Apr 30, 2013, 05:52 pm Last Edit: Apr 30, 2013, 05:57 pm by Riva Reason: 1

Could you please show me how to make that change to the code ?


Untested rolling average code.
Code: [Select]
int sensorValue;
// the setup routine runs once when you press reset:
void setup() {
 // initialize serial communication at 9600 bits per second:
 Serial.begin(9600);
 sensorValue = analogRead(A3); // Prime rolling average
}

// the loop routine runs over and over again forever:
void loop() {
 // read the input on analog pin 3:
 sensorValue += (analogRead(A3) / 2); // get rolling average
 // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
 float voltage = sensorValue * (5.0 / 1023.0);
 // print out the value you read:
 Serial.println(voltage);
 delay(500);
}


Untested average of 20 readings code
Code: [Select]
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = 0;
  for (byte x = 0; x < 20; x++) {
    sensorValue += analogRead(A3);
  }
  sensorValue = sensorValue / 20;
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);
  delay(500);
}

Go Up