calibrationg sensor value

Dear all,

some one help me how can calibrate the sensor output of ACS712.

int Sensor_Value=0;
float voltage;
float ARDUINO_ANALOG_SCALING = 0.00488758;
float Actual_voltage;
float Current_Sensor_Value;
void setup()
{
  Serial.begin(9600);
  pinMode(A0, INPUT) ;

}

void loop()
{

  CS_Output();
  Serial.println("........................");
  delay(1000);
}


void CS_Output()
{
  float average = 0;
  for(int i = 0; i < 1000; i++) {
    average = average + (.0264 * analogRead(A0) -13.51) / 1000;
    delay(1);
  }
  Serial.print("before calibration:");
  Serial.println(average);
  average=average+0.15;
  Serial.print("after calibration:");
  Serial.println(average);  
}

My result are as below

slno                   fans               Actual_dc load      Before_conversion    after_ conversion
1                    AD0612HX                        0.15A                      0.09A                                 0.15A
2                    ADO812XB                       0.40A                       0.25A                                  0.32A
3                  WHEN COMBINE             0.52A                         0.35A                                   0.41A

My output should be close to Actual_dc load. How i can correct my After_conversion alue to get close to it.

Unfortunately the ratio is not the same for those 3 readings:

15/9 = 1.7
40/25 = 1.6
52/35 = 1.5

.... so you'll have to do some interpolation between values. Or just call it 1.6 and multiply all your readings by that.

Personally I'd say that a ratio of 1.6 between sensor readings and actual isn't a calibration thing, it's an actual error and either your sensor or the actual reading is crap.

edit... how do you know which reading is right? What makes you think "actual" is "actual" and your sensor is wrong?

[how do you know which reading is right? What makes you think "actual" is "actual" and your sensor is wrong?](http://how do you know which reading is right? What makes you think "actual" is "actual" and your sensor is wrong?)
Dc load reading are accurate since i compare with multi meter.

  1. other 2 values before and after conversion from sensor. I wanted to know i am doing proper conversion or not. If not please let me know what need to do.

AMPS-N:
[how do you know which reading is right? What makes you think "actual" is "actual" and your sensor is wrong?](http://how do you know which reading is right? What makes you think "actual" is "actual" and your sensor is wrong?)
Dc load reading are accurate since i compare with multi meter.

So you have three readings and two agree? Or is the "actual" from the meter and you have only two readings?

If it's two readings you can't pick one as right and one as wrong, unless your meter is certified in the first place. Who says the meter is right.

That said, have you read the sensor datasheet and looked at all that info about accuracy and so on?

I think you not seeing my code itself. Kindly check conversion setup. You will undestand. What is meant by after conversion and before conversion.

actual_DCload is reading taking from DC_electronic load / say multimeter which is expected values

Other 2 value i got from code i.e after/before conversion these value coming from sensor ACS712.
My code is wrong then requested to correct it

I have tried almost all code associated with acs 712. But there is 0.3A diffrence. and the analog _sensor value are keep fluctuating
even through they are @ same ground potentional

Is anyone, if tried earlier code can share here.
method1:

void loop(){
    float currentValue(analogRead(A0));
    float amps = ((.0049 * currentValue) - 2.5)/.066;
    Serial.print("  Amps = ");
    Serial.print(amps);
    Serial.print(" mA");
    delay(100);
}

method 2:

void loop() {
 
  float average = 0;
  for(int i = 0; i < 1000; i++) {
    average = average + (.0264 * analogRead(A0) -13.51) / 1000;
    delay(1);
  }
  Serial.println(average);  
}

method 3
http://arduinosensors.com/index.php/interfacing-a-hall-effect-current-sensor-with-an-arduino/
please let me know any other process get read of this error

This is your 3rd thread dealing with your ACS712 module.
Staying on one thread is the way to go. You will get the most help that way.
The way your doing it is bound to erk a few people.
Here is a great link for calibrating the module.
The code I posted in the your other merged thread works great once the module is calibrated.
Did you try it?
I have accuracy down to 2mA - 3mA in certain ranges. Not really going to get much better, the ACS712 is a bit noisy.
No load readings can be 10mA+.

const int num_readings = 10;
float offSet = 2.44009;
const int mad = 2.24;
int readings[num_readings];
int index = 0;
float sample2SolCrnt = 0.0;
  float solar_crnt = 0.0; // Solar panel current variable
  float solarCrntVal = 0.0; // Current callibration variable
  
  
void setup() {
  // sets the serial port to 9600
  Serial.begin(9600);
}

int average() {
  int total = 0;
  for(int i=0; i<num_readings; i++)
    total = total + readings[i];
  return total/num_readings;
}

float standard_deviation(int avg) {
  int total = 0;
  for(int i=0; i<num_readings; i++)
    total = total + pow((avg - readings[i]), 2);
  return sqrt(total/num_readings);
}

void loop() {
  float sum=0.0;
  // read analog input pin 0
  int reading = analogRead(A0);
  readings[index] = reading;
  // incrementing the index
  index = index + 1;
  // if have already been done 10 readings...
  if (index >= num_readings) {
    // set the index to 0
    index = 0;
    // compute the average
    int avg = average();
    // compute the standard deviation
    float std = standard_deviation(avg);
    
    float madstd = mad * std;
    float lowlimit = avg - madstd;
    float highlimit = avg + madstd;
    
    int count = 0;
    int total = 0;
    for(int i=0; i<num_readings; i++) {
      // Check if the values of the readings are within the limits.
      if(readings[i] >= lowlimit && readings[i] <= highlimit) {
        total = total + readings[i];
        count = count + 1;
      }
      
    }
    // compute the new average
    int newaverage = total/count;
    // send it to the serial port (as ASCII digits)
    Serial.println(newaverage, DEC);
  //  sum=sum+(.0264 *newaverage -13.51);
    
    
    float current= 0.0264*(newaverage-512);
    
     
     Serial.print("current is :");
  Serial.println(current);
  }
  
  
  // wait 1000/num_readings ms for next reading
  delay(int(1000/num_readings));
}

Yes i have tried your code. The count value are stabliszed but problem is the actual current and desired current are not matching
With above device connected i am getting 0.3A difference with actual.

AMPS-N:
0.3A difference with actual.

In still don't understand: if you have 2 readings, the one from the sensor and the "actual", how do you know which one is right?

If you had 3 readings and 2 were essentially the same compared to the 3rd then yep I'd go with the 3rd one being wrong. But how do you know to trust the one you're calling "actual"?

My setup like this.
I have the two fans connected in series with DC electronic load.

My setup like this Where my resistance replace by 2 fans and load / voltage supply given by DC power supply.which is rated up to 24v , 10A. Whenever load connected in series it shows amount of current required for run the fans.SO this my actual reading

I consider DC power supply as reading as actual reading. Even i tested with multimeter . It showing almost same as dc power supply.

Now i interface the Arduino , keeping @ same potential.
I have attached output file before switching on and after switching on serial monitor window as show fig.

The code i uploaded as below.

const int num_readings = 10;
float offSet = 2.44009;
const int mad = 2.24;
int readings[num_readings];
int index = 0;
float sample2SolCrnt = 0.0;
  float solar_crnt = 0.0; // Solar panel current variable
  float solarCrntVal = 0.0; // Current callibration variable
  
  
void setup() {
  // sets the serial port to 9600
  Serial.begin(9600);
}

int average() {
  int total = 0;
  for(int i=0; i<num_readings; i++)
    total = total + readings[i];
  return total/num_readings;
}

float standard_deviation(int avg) {
  int total = 0;
  for(int i=0; i<num_readings; i++)
    total = total + pow((avg - readings[i]), 2);
  return sqrt(total/num_readings);
}

void loop() {
  float sum=0.0;
  // read analog input pin 0
  int reading = analogRead(A0);
  readings[index] = reading;
  // incrementing the index
  index = index + 1;
  // if have already been done 10 readings...
  if (index >= num_readings) {
    // set the index to 0
    index = 0;
    // compute the average
    int avg = average();
    // compute the standard deviation
    float std = standard_deviation(avg);
    
    float madstd = mad * std;
    float lowlimit = avg - madstd;
    float highlimit = avg + madstd;
    
    int count = 0;
    int total = 0;
    for(int i=0; i<num_readings; i++) {
      // Check if the values of the readings are within the limits.
      if(readings[i] >= lowlimit && readings[i] <= highlimit) {
        total = total + readings[i];
        count = count + 1;
      }
      
    }
    // compute the new average
    int newaverage = total/count;
    // send it to the serial port (as ASCII digits)
    Serial.println(newaverage, DEC);
   // sum=sum+(.0264 *newaverage -13.51);
    
    
   float current= 0.0264*(newaverage-512);
    
     
     Serial.print("current is :");
  Serial.println(current);
  }
  
  
  // wait 1000/num_readings ms for next reading
  delay(int(1000/num_readings));
}

When i turned on . my mutimeter and DC power supply shows 12.45V 0.85 A where as .

analog port reading shows 0.53A. SO can you let me know what mistake i am doing here

Motors inject electrical noise into the power supply leads. If you want to accurately calibrate the current sensor, use resistive loads.

Your best bet is to use a constant current source like this or this, set it to 100mA and calibrate the ACS712 board to that.
Then raise and lower the constant current source and test.
For reference:
Referring to the ACS712 schematic.
After calibration.
My no load voltage at the output of trimpot R4 is 2.529V - 2.53V, my no load voltage at the junction of R2 and trimpot R3 is 2.551V - 2.552V.
With the code I posted I get a 2mA - 3mA variance from my Mastech MS8268 multimeter.

Tips:
The code I posted keeps all the unused pins on the Arduino board from floating.
Also, place a .1uF cap from the AREF to the GND pin, cut the leads on the capacitor so that it fits snug with no part of the leads exposed beyond the pins.
Keep all wires from the Arduino board to the ACS712 board as short as possible, don't use the ground pin that is right next to the 5V pin use the one that is closest to the VIN pin.
Keep USB cord, mouse, PC power cord or any other power cords and anything that is magnetic or electromagnetic away from the ACS712 board.