The library provides two methods for AC current measurement depending on whether the signal's Form Factor (crest factor) is known.
1. Using known Form Factor with mA_AC()
This method multiplies the peak-to-peak value by a pre-set Form Factor.
Signature: float mA_AC(float frequency = 50, uint16_t cycles = 1)
2. Using unknown Form Factor with mA_AC_sampling()
This method samples a full period and calculates the current using the square root of the average sum of squares. This is intended for signals with an unknown Form Factor.
Signature: float mA_AC_sampling(float frequency = 50, uint16_t cycles = 1)
Performance Trick:
To reduce blocking time, you can set the frequency parameter to twice the actual frequency (e.g., 100 Hz for a 50 Hz signal). This samples only half a period. While this reduces blocking time to ~10 ms, it increases measurement variation by approximately 4x.
// If you know the form factor (e.g. Sinus)
ACS.setFormFactor(ACS712_FF_SINUS);
float currentAC = ACS.mA_AC(50, 1);
// If form factor is unknown
float currentAC_unknown = ACS.mA_AC_sampling(50, 1);