2021-12-01 08:20:22 -05:00
|
|
|
//
|
|
|
|
// FILE: ACS712_detectFrequency.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
2022-08-28 03:44:41 -04:00
|
|
|
// PURPOSE: demo detect frequency + timing indication.
|
2022-08-12 04:47:41 -04:00
|
|
|
// URL: https://github.com/RobTillaart/ACS712
|
2021-12-01 08:20:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
#include "ACS712.h"
|
|
|
|
|
2022-08-12 04:47:41 -04:00
|
|
|
|
|
|
|
// 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
|
2021-12-01 08:20:22 -05:00
|
|
|
ACS712 ACS(A0, 5.0, 1023, 100);
|
2022-08-12 04:47:41 -04:00
|
|
|
// ESP 32 example (might requires resistors to step down the logic voltage)
|
|
|
|
// ACS712 ACS(25, 3.3, 4095, 185);
|
|
|
|
|
2021-12-01 08:20:22 -05:00
|
|
|
|
|
|
|
uint32_t start, stop;
|
|
|
|
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
2022-08-28 03:44:41 -04:00
|
|
|
while (!Serial);
|
2021-12-01 08:20:22 -05:00
|
|
|
Serial.println(__FILE__);
|
2022-08-28 03:44:41 -04:00
|
|
|
Serial.print("ACS712_LIB_VERSION: ");
|
|
|
|
Serial.println(ACS712_LIB_VERSION);
|
2021-12-01 08:20:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
// e.g. detect 50 or 60 Hz sinus signal
|
|
|
|
// blocks on bad signals.
|
|
|
|
start = micros();
|
|
|
|
float frequency = ACS.detectFrequency(45);
|
|
|
|
stop = micros();
|
|
|
|
|
|
|
|
Serial.print(stop - start);
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.println(frequency, 1);
|
2022-08-28 03:44:41 -04:00
|
|
|
delay(100);
|
2021-12-01 08:20:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -- END OF FILE --
|
2022-08-12 04:47:41 -04:00
|
|
|
|