Hardware Reference
In-Depth Information
float avgSensor = 0;
int nb_measurements = 100;
for (int i = 0; i < nb_measurements; i++) {
sensorValue = analogRead(CURRENT_SENSOR);
avgSensor = avgSensor + float(sensorValue);
}
avgSensor = avgSensor/float(nb_measurements);
return avgSensor;
}
Inside the loop() function, we also measure the value that comes from the sensor using
the same function:
float sensor_value = getSensorValue();
Serial.print("Sensor value: ");
Serial.println(sensor_value);
We can then calculate the value of the effective current, which is given by the datasheet of
the ACS712 current sensor:
amplitude_current=(float)(sensor_value-zero_sensor)/1024*5/
185*1000000;
effective_value=amplitude_current/1.414;
After this, we print the value of the current, the effective current, and also calculate the ef-
fective power:
Serial.println("Current amplitude (in mA): ");
Serial.println(amplitude_current,1);
Serial.println("Current effective value (in mA)");
Serial.println(effective_value,1);
Serial.println("Effective power (in W): ");
Serial.println(abs(effective_value*effective_voltage/
1000),1);
Serial.println("");
We repeat this every 500 ms:
delay(500);
Search WWH ::




Custom Search