ACS712 sensor values are not stable

Hi Everybody,

acs712 30A 12v 3w LED when connected , values are not fixed and wrong what could be the reason ?

#include <LCD5110_Basic.h>
LCD5110 myGLCD(8, 9, 10, 11, 12);
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];
extern uint8_t BigNumbers[];

dht11 DHT11;

const int analogIn = 0;
float mVperAmp = 66;
int RawValue = 0;
int ACSoffset = 2500;
double Voltage = 0;
double Amps = 0;


void setup()
{
  myGLCD.InitLCD();
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
}

void loop()
{
  RawValue = analogRead(analogIn);
  Voltage = (RawValue / 1023.0) * 5000;
  Amps = ((Voltage - ACSoffset) / mVperAmp);

  myGLCD.clrScr();
  myGLCD.setFont(SmallFont);
  myGLCD.print("Volt:", LEFT, 0);
  myGLCD.print("Amp:", LEFT, 16);
  myGLCD.print("Raw:", LEFT, 32);


  myGLCD.setFont(MediumNumbers);
  myGLCD.printNumI(Voltage, RIGHT, 0);
  myGLCD.printNumI(Amps, RIGHT, 16);
  myGLCD.printNumI(RawValue, RIGHT, 32);
  delay(500);
}

I'd say it's your code, or your wiring!

missdrew:
I'd say it's your code, or your wiring!

The code appears in the picture above
its connection is already very simple gnd 5v, the out pin is a0

yhackup:
…, values are not fixed and wrong what could be the reason ?

If I understand the setup correctly, you’re putting 30A through the device and it looks like you’re reading between 30.85 and 31.0A. I’d say 0.5% variation and about 3% error is pretty damn’ good! Note that the Allegro datasheet quotes the total output error as +/- 1.5%, and unless you are very careful, it’s easy to get 0.5% jitter (picking up the local radio station etc.).
(Please post your code and results using the </> code presentation facility which will mean we don’t have to squint through our magnifying glasses at your tiny screenshots).

johndg:
If I understand the setup correctly, you’re putting 30A through the device and it looks like you’re reading between 30.85 and 31.0A. I’d say 0.5% variation and about 3% error is pretty damn’ good! Note that the Allegro datasheet quotes the total output error as +/- 1.5%, and unless you are very careful, it’s easy to get 0.5% jitter (picking up the local radio station etc.).
(Please post your code and results using the </> code presentation facility which will mean we don’t have to squint through our magnifying glasses at your tiny screenshots).

It shows 400v when it needs to be 12V, this deviation is too much
I added the code first post

yhackup:
It shows 400v when it needs to be 12V, this deviation is too much
I added the code first post

It shows 400mV (not 400V) output from ASC712 chip. That chip measures a current so LED voltage is not applicable here. Only current matters.

yhackup:
RawValue = analogRead(analogIn);
Voltage = (RawValue / 1023.0) * 5000;

The output from the ACS712 is in the range 0 to 5V (12V has nothing to do with the output), so Rawvalue will be in the range 0 to 1023 (assuming a 10-bit ADC), and for full scale output from the sensor, will be a bit above 0V or a bit below 5V (depending on current direction), so reading could be say, 50 or 975.
(50/1023)*5000 = 244.4, (975/1023)*5000=4765.4. Your scaling for voltage is wrong. I suspect you are actually measuring about 0.45V, and the current through the device is negative.
12V is (presumably) the voltage applied to the Led?? But 12V at 30A is 360W, not 3W!
Your figures are all inconsistent. Please describe your circuit in detail. Presumably you copied the code from somewhere without fully understanding it?
(@alesam - you posted while I was writing & trying to make sense of the OP)

alesam:
It shows 400mV (not 400V) output from ASC712 chip. That chip measures a current so LED voltage is not applicable here. Only current matters.

I tried the motor but it's the same

johndg:
The output from the ACS712 is in the range 0 to 5V (12V has nothing to do with the output), so Rawvalue will be in the range 0 to 1023 (assuming a 10-bit ADC), and for full scale output from the sensor, will be a bit above 0V or a bit below 5V (depending on current direction), so reading could be say, 50 or 975.
(50/1023)*5000 = 244.4, (975/1023)*5000=4765.4. Your scaling for voltage is wrong. I suspect you are actually measuring about 0.45V, and the current through the device is negative.
12V is (presumably) the voltage applied to the Led?? But 12V at 30A is 360W, not 3W!
Your figures are all inconsistent. Please describe your circuit in detail. Presumably you copied the code from somewhere without fully understanding it?
(@alesam - you posted while I was writing & trying to make sense of the OP)

English is not good, I may have spelled it wrong , what i want to say is the adapter i use is 12v
I also tried to reverse the directions
I don't know your logic , I copied the code from somewhere this url
my acs712 circuit connection is this way

i am making cam ecu , with the car control, the windows raise and lower,

while this is happening,if the glass meets the obstacle, the amperage will rise,

I want to stop the process,understanding with this sensor

my project video https://youtu.be/p0Eiy5FOB6U

yhackup:
my acs712 circuit connection is this way

Your circuit is fine. This picture:
ACS712.JPG
is from the ACS712 datasheet. It shows that the current you are measuring, Ip, goes straight through the device, from (in your case) the battery to the motor. The voltage that goes to the Arduino is in the range 0 to 5V. For maximum negative current, the voltage is 0V. For no current the voltage is 2.5V and for maximum positive current, the voltage is 5V.

ACS712.JPG