My ACS712 5A is not working

I want to use the ACS712 5A to measure the current, power and power consumption of a 9K DC power supply with 1KΩ.
However, the measured voltage and current values are not in accordance with the theoretical calculations.
And when I remove the sensor I can just as easily read the same value via ARDUINO and the computer
I would like to ask what causes my ACS712 5A cannot measure the value

P.S: Switch to ACS712 30A and set int mVperAmp = 66; also get the same conclusion

this is my code

const int sensorIn = A0;
int mVperAmp = 185; // use 185 for 5A Module and 66 for 30A Module

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;
double Power = 0;
double Phr = 0;
double P = 0;
double R = 0;

unsigned long t;

void setup(){
Serial.begin(9600);
//adjustRealTime();
}

void loop(){
Voltage = getVPP();
VRMS = (Voltage/2.0) 0.707;
AmpsRMS = (VRMS * 1000)/mVperAmp;
Power = VRMS
AmpsRMS/1000;
P = P + Power;
t = millis();
Phr = P/t36001000;
R=(Voltage/AmpsRMS)*1000 ;

Serial.print(VRMS,3);
Serial.print(" V “);
Serial.print(AmpsRMS,3);
Serial.print(” mA “);
Serial.print(Power,3);
Serial.print(” watt “);
Serial.print(Phr,3);
Serial.print(” watt/hr “);
Serial.print(R,3);
Serial.println(” Ω");
}

float getVPP()
{
float result;

int readValue; //value read from the sensor
int maxValue = 0; // store max value here
int minValue = 1023; // store min value here

uint32_t start_time = millis();
while((millis()-start_time) < 1000) //sample for 1 Sec
{
readValue = analogRead(sensorIn);
// see if you have a new maxValue
if (readValue > maxValue)
{
/record the maximum sensor value/
maxValue = readValue;
}
if (readValue < minValue)
{
/record the maximum sensor value/
minValue = readValue;
}
}

// Subtract min from max
result = ((maxValue - minValue) * 5.0)/1024.0;

return result;
}

@U0421011, please do not cross-post. Other thread removed.

Is the problem with your program or the sensor? With the Arduino analog not connected to the ACS712, what does the ACS712 output read on the voltmeter?

U0421011:
I want to use the ACS712 5A to measure the current, power and power consumption of a 9K DC power supply with 1KΩ.

Mains/AC side or DC side.
A sketch for AC to measure DC won't work.
The AC component of DC is usually zero.
Leo..

This is my simulation result,without ACS712 sensor.

0.088 V 0.476 mA 0.000 watt 3.546 watt/hr 523.338 Ω
0.090 V 0.485 mA 0.000 watt 2.698 watt/hr 523.338 Ω
0.088 V 0.476 mA 0.000 watt 2.188 watt/hr 523.338 Ω
0.088 V 0.476 mA 0.000 watt 1.848 watt/hr 523.338 Ω

After some more Googling, I guess you're talking about a 950watt computer power supply.
Leo..

U0421011:
This is my simulation result,without ACS712 sensor.

0.088 V 0.476 mA 0.000 watt 3.546 watt/hr 523.338 Ω
0.090 V 0.485 mA 0.000 watt 2.698 watt/hr 523.338 Ω
0.088 V 0.476 mA 0.000 watt 2.188 watt/hr 523.338 Ω
0.088 V 0.476 mA 0.000 watt 1.848 watt/hr 523.338 Ω

What is that information from? The Arduino with nothing connected? If so, then it is meaningless. See my previous post and reply with the results.