Calculating RMS current from AC712 chip (AC system)

I have read several articles with code examples on how to calculate the actual current with a ACS712 chip with AC involved. I understand what RMS is and I feel like I am able to implement it myself. However I first started with copying code that was supposed be usable with a 5A ACS712 chip. The results were really disappointing and the values returned were far from what my Ammeter returned. Ultimately I decided to implement it myself and I ended up with the following code:

values.emplace_back(std::pow(value - 512.0f, 2.0));
if (values.size() == UPDATE_RATE) {
const auto n = values.size();
const auto sum = std::accumulate(values.begin(), values.end(), 0.0f, [&n](const auto& cur, const auto& next) { return cur + next / (float) n; });
values.clear();

const auto rms = std::sqrt(sum);
std::cout << "RMS: " << ((rms / 1024.0f) * 2500.0f) / 185 << std::endl;
}


The values are read from an Arduino and value is essentially the result of analogRead(A5) where the ACS712 is attached to. I am using an ACS712 chip that supports -5A to 5A therefore the / 185 as the 5A chip has a resolution of 185 mvA. I divide by /1024 because analogRead returns values between 0 and 1024 and I multiply by 2500 because the ACS712 has a range of 5000mV - thus mapped to [-1, 1] it has to be multiplied by 2500.

I was wondering, is what I am doing reasonable to measure AC current with an ACS712 chip? My results are reasonable, I get values around 130mA for an utility that according to the Ammeter uses 130-140mA.

• _"My results are reasonable, I get values around 130mA for an utility that according to the Ammeter uses 130-140mA."- what ammeter, and what is the load? Dec 1, 2020 at 4:04
• the load is a panel of around 200 LEDs running at 230V. The ammeter is the AC ammeter of my multimeter. Dec 1, 2020 at 6:40
• If the results match your meter then that suggests your calculations are good. Try measuring loads that should have sine wave current, eg. incandescent lamp. Just one more question:- what value is UPDATE_RATE? Dec 1, 2020 at 7:01
• at the moment 1000, I am going to change it to a time based condition later. Dec 1, 2020 at 7:08