0
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ _"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? \$\endgroup\$ Dec 1, 2020 at 4:04
  • \$\begingroup\$ the load is a panel of around 200 LEDs running at 230V. The ammeter is the AC ammeter of my multimeter. \$\endgroup\$ Dec 1, 2020 at 6:40
  • \$\begingroup\$ 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? \$\endgroup\$ Dec 1, 2020 at 7:01
  • \$\begingroup\$ at the moment 1000, I am going to change it to a time based condition later. \$\endgroup\$ Dec 1, 2020 at 7:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.