ACS_712__code.ino 807 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Code for current measurement by using a ACS712 (5A) hall effect current sensor
  2. // by deba168 on 17/03/15
  3. int temp=0;
  4. float sum =0;
  5. float AMPS_SCALE =0;
  6. float amps=0;
  7. void setup()
  8. {
  9. Serial.begin(9600);
  10. }
  11. void loop()
  12. {
  13. for(int i = 0; i < 100; i++) // loop through reading raw adc values 100 number of times
  14. {
  15. temp=analogRead(A1); // read the input pin
  16. sum += temp; // store sum for averaging
  17. delayMicroseconds(50);
  18. }
  19. sum=sum/100; // divide sum by 100 to get average
  20. // Calibration for current
  21. AMPS_SCALE= 0.00488/ 0.185; //5/1024 = 0.00488 // Sensitivity = 185mV
  22. amps = AMPS_SCALE* sum - 13.51; // 2.5/0.185 = 13.51
  23. Serial.print(amps);
  24. Serial.println("A");
  25. delay(500);
  26. }