Code: Select all
void setup() {
Serial.begin(115200); //Start Serial Monitor to display current read value on Serial monitor
}
void loop() {
int sampSize = 500;
float AcsValue = 0.0, Samples = 0.0, AvgAcs = 0.0, AcsValueF = 0.0;
for (int x = 0; x < sampSize; x++) { //Get 150 samples
AcsValue = analogRead(A0); //Read current sensor values
Serial.println(AcsValue);
Samples += AcsValue; //Add samples together
// delay(3); // let ADC settle before following sample 3ms
}
AvgAcs = Samples / sampSize; //Taking Average of SampleMs
AcsValueF = (((AvgAcs / 1023.0) * 4096)) / 185;
// AcsValueF = (((AvgAcs / 1023.0) * 4.096) - 2.048) * 0.100;
// Serial.println(AcsValueF); //Print the read current on Serial monitor
}