#include "ACS712.h"
// Arduino UNO has 5.0 volt with a max ADC value of 1023 steps
// ACS712 5A uses 185 mV per A
// ACS712 20A uses 100 mV per A
// ACS712 30A uses 66 mV per A
ACS712 ACS(14, 3.3, 4095, 185);
// ESP 32 example (might requires resistors to step down the logic voltage)
// ACS712 ACS(25, 3.3, 4095, 185);
uint32_t start, stop;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// use simulation
ACS.setADC(signal, 5, 1024);
ACS.autoMidPoint();
Serial.print("MidPoint: ");
Serial.print(ACS.getMidPoint());
Serial.print(". Noise mV: ");
Serial.println(ACS.getNoisemV());
}
void loop() {
delay(100);
start = micros();
// int mA = ACS.mA_AC();
int mA = ACS.mA_AC_sampling();
stop = micros();
Serial.print("mA: ");
Serial.print(mA);
Serial.print(". Form factor: ");
Serial.print(ACS.getFormFactor());
Serial.print(" time: ");
Serial.println(stop - start);
delay(5000);
}
// simulated 60 Hz signal
uint16_t signal(uint8_t p)
{
return 512 + 400 * sin((micros() % 1000000) * (TWO_PI * 60 / 1e6));
}