Shop OBEX P1 Docs P2 Docs Learn Events
ACS 712 calibration — Parallax Forums

ACS 712 calibration

ajit.nayak87ajit.nayak87 Posts: 76
edited 2014-09-08 08:20 in General Discussion
Dear all,

I am trying to measure the current through 2 fans. Here i am attaching my code and I need to know how can i calibrate it.
I am using below 2 fans
http://www.mouser.in/ProductDetail/ADDA/AD0612HX-A71GL-LF/?qs=hTx6WCxFMbgcZc/FmemT9A==

http://www.mouser.in/ProductDetail/ADDA/AD0812XB-A73GL-LF/?qs=PieNiMrGZlqvWjV0xsttzA==

Using arduino UNo board for programming.

[COLOR=#000000][FONT=monospace]void CS_Output()[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]{[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]  float average = 0;[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]  for(int i = 0; i < 1000; i++) {[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]    average = average + (.0264 * analogRead(A0) -13.51) / 1000;[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]    delay(1);[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]  }[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]  Serial.print("before calibration:");[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]  Serial.println(average);[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]  average=average+0.07;[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]    Serial.print("after calibration:");[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]  Serial.println(average);  [/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]}[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]void setup() {[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]Serial.begin(9600);[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]}[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]void loop()[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]{[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]CS_Output();[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]delay(1000);[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]}[/FONT][/COLOR]

Results
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.42A
Let know how can offset value to meet exact or close to actual_DC load current showing value

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2014-09-06 05:06
    [COLOR=#000000][FONT=monospace]    average = average + (.0264 * analogRead(A0) -13.51) / 1000;[/FONT][/COLOR]
    
    is an obscure way to say
    [COLOR=#000000][FONT=monospace]    average += 0.0264 * (analogRead(A0) - 512) / 1000;[/FONT][/COLOR]
    

    To calibrate you would normally take a batch of readings at start up, and store their average, then
    subtract from the actual reading:
    [COLOR=#000000][FONT=monospace]    average += 0.0264 * (analogRead(A0) - 512 - calibration) / 1000;[/FONT][/COLOR]
    
  • ajit.nayak87ajit.nayak87 Posts: 76
    edited 2014-09-07 22:05
    But still not calibrating properly.still there is difference of 0.3~0.4A w.r.t actual reading
    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(sum);
      }
      
      
      // wait 1000/num_readings ms for next reading
      delay(int(1000/num_readings));
    }
    
    
  • Mark_TMark_T Posts: 1,981
    edited 2014-09-08 08:20
    1) You have to ensure no current during calibration
    2) A hall sensor is much noisier than a shunt sensor, but is isolated.
Sign In or Register to comment.