Excessive fluctuating of ACS712 input to AO on UNO WiFi Rev2

I have AO of the UNO board tied to the analog output pin of the ACS712 current sensor.
A .1 uF cap is tied between the 5v UNO pin feeding the VCC current sensor input and GND as called for.
With no current input to the sensor the reading is rock solid at just a few hundreds above the 2500 mV baseline.
With a steady 2 amp current flowing through the sensor I get these consecutive values
on the serial monitor:
Amps..........mV ..............Raw
.422
-0.950
1.927...... 2856 ............ 585
-1.188
.581
-.055 ...... 2510 ............ 514
-0.44
1.18
-1.82 ...... 2163 ........... 438
1.53

With an open input: 6.6 amps/ 3730 mV/ 765 Raw
I have changed capacitance values to .2 uF and .5 uF with no effect.
The baseline is perfect but the values are wildly fluctuating above and below
the 2500 mV baseline with current flowing. The 2 amp current flow is roughly mid-scale
for the 0-5 volt version of the ACS712. Not sure if it matters but the current load test device
is a 110 volt hand grinder with a universal/commutator series-wound motor.
I verified the amp draw with an AMPROBE current meter.
So with nearly 700 millivolts of span the current sensor seems to be operational.
Except for the fact it is going below the baseline while sensing the current and not staying
in the upper range without fluctuating.

//   Measuring Current Using ACS712

const int analog_In = A0;
int mV_per_Amp = 185;     // use 100 for 20A Module and 66 for 30A Module
int Raw_Value = 0;
int ACS_offset = 2500;    // : it has an output of 2.5V w/ no input because it can measure the current in both directions.

double Voltage = 0;
double Amps = 0;

boolean blr_on_state = false;

void setup(){
Serial.begin(115200);
}

void loop()
{

Raw_Value = analogRead(analog_In);
Voltage = (Raw_Value / 1024.0) * 5000;       // Gets you mV
Amps = ((Voltage - ACS_offset) / mV_per_Amp);

Serial.print("Raw Value = " ); // shows pre-scaled value
Serial.print(Raw_Value);
Serial.print("\t mV = ");     // shows the voltage measured
Serial.print(Voltage,3);      // the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("\t Amps = ");   // shows the voltage measured
Serial.println(Amps,3);       // the '3' after voltage allows you to display 3 digits after decimal point
delay(2500);
}

Your code is set up for measuring DC.
Mains power is AC.
Leo..

In the code what signifies it is calculating for DC and not AC?
To be clear, this was code sourced from a website. Is some type of
conditioning circuit required between the sensor and Arduino
to convert the AC current signal?

An AC signal is forever changing.
You must read the sensor continuously for the duration of at least one sinewave.

Maybe someone else can point you to example code.
I never used one for AC mains power,
because the modules they come on seem to dangerous for 230volt AC.
Leo..

I am not monitoring a mains circuit, rather a 110 volt branch circuit feeding a boiler panel.

I think I found more of what I probably need:

I appreciate the heads up about the sensor not being able to directly read/interpret
the AC current sensor with my current code. :+1:

Some quickly written (untested) code to experiment with.
It will show you what I mean.
Leo..

const byte sensorPin = A0;
int rawValue;
unsigned long startMillis;
float current;

void setup() {
  Serial.begin(115200);
}

void loop() {
  int positivePeak = 0, negativePeak = 1023; // reset
  startMillis = millis(); // mark
  while (millis() - startMillis < 20) { // measure for 20 ms
    rawValue = analogRead(sensorPin);
    if (rawValue > positivePeak) positivePeak = rawValue;
    if (rawValue < negativePeak) negativePeak = rawValue;
  }
  rawValue = positivePeak - negativePeak; // difference
  Serial.println(rawValue);
  delay(500); // slow down prints
}

Thank you. I will check out your code and take it into consideration. :+1: