

// Measuring current using ACS712 - 5A, 20A and 30A modules
int rawData; // analog data read from sensor
double average = 0;
double scaleFactor = 185.0; // for 5A module = 185.0
// for 20A module = 100.0
// for 30A module = 66.0
double voltage = 0.0;
double current = 0.0;
void setup() {
Serial.begin(9600);
}
void loop() {
average = 0;
// for stable measurement we take 100 measurements
// and average it
for(int i = 0; i < 100; i++) {
average += analogRead(0);
delay(1);
}
average /= 100;
voltage = (average / 1023.0) * 5000.0; // in mV
// for calibration to determine number 2494 at 0A current
// Serial.println(voltage);
current = (voltage - 2494) / scaleFactor; // in A
// prints current in A
Serial.println(current);
delay(500);
}
acs712_-_5a_eng.pdf