ACS712 5amp unstable

I recently bought a acs712 5 amp hall effect sensor. Connecting it to the arduino, and writting a simple code to check what its reading at a baseline, I get very unstable readings, it doesnt even stay at 512 counts on my serial monitor. Any suggestions? Below is the code and what I see on the monitor.

int analogInPin = A0;
int sensorValue = 0;
int timer = 0;

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

void loop() 
{
  (void) analogRead(analogInPin);
  sensorValue = analogRead(analogInPin);            
  Serial.print("sensor = " );                       
  Serial.print(sensorValue);      
  float voltage = sensorValue * (5.0 / 1023.0);
  Serial.print("\t voltage = ");
  Serial.print(voltage);
  Serial.print("\t time: ");
  Serial.println(timer);
  timer++;
  delay(300);                     
}

sensor = 507 voltage = 2.48 time: 0
sensor = 508 voltage = 2.48 time: 1
sensor = 514 voltage = 2.51 time: 2
sensor = 508 voltage = 2.48 time: 3
sensor = 518 voltage = 2.53 time: 4
sensor = 507 voltage = 2.48 time: 5
sensor = 510 voltage = 2.49 time: 6
sensor = 506 voltage = 2.47 time: 7
sensor = 510 voltage = 2.49 time: 8
sensor = 506 voltage = 2.47 time: 9
sensor = 509 voltage = 2.49 time: 10
sensor = 508 voltage = 2.48 time: 11
sensor = 507 voltage = 2.48 time: 12
sensor = 514 voltage = 2.51 time: 13
sensor = 512 voltage = 2.50 time: 14
sensor = 507 voltage = 2.48 time: 15
sensor = 506 voltage = 2.47 time: 16
sensor = 508 voltage = 2.48 time: 17
sensor = 511 voltage = 2.50 time: 18
sensor = 509 voltage = 2.49 time: 19
sensor = 508 voltage = 2.48 time: 20
sensor = 512 voltage = 2.50 time: 21
sensor = 505 voltage = 2.47 time: 22
sensor = 508 voltage = 2.48 time: 23
sensor = 513 voltage = 2.51 time: 24
sensor = 507 voltage = 2.48 time: 25
sensor = 507 voltage = 2.48 time: 26
sensor = 507 voltage = 2.48 time: 27
sensor = 514 voltage = 2.51 time: 28

That is actually pretty stable for a silly ACS712, it can be a lot worse.
Is something nearby that causes magnetic disturbance, like a transformer, or a computer, or a computer screen ?

I assume that you use the 5V pin of the Arduino (and GND and A0) to the ACS712 ? That is okay, when the 5V lowers a little, both the sensor and the Arduino will have that lower 5V and the result will still be the same.

Please remove that line with : (void) analogRead(analogInPin);

Can you make a function that returns the current. Something like getCurrent() or getAmps() and it could return the current in amperes as a float.
When that function is okay, you can try to use the average of 5 or 20 samples, that will make the result a lot more stable.

Thanks for the input. Yes, I was about 6 inches away from my computer. And yes, I am using the arduino 5v and ground.

Is there anything I could use to measure current more accurately? I am trying to measure a motor that typically runs around 100 ma, and when the motor stalls, it pulls about 450 ma.

Average multiple readings like this

int analogInPin = A0;
int sensorValue = 0;
int timer = 0;

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

void loop() 
{
  // MEASUREMENT
  uint16_t sum = 0;
  for (int i=0; i<16; i++)
  {
    sum += analogRead(analogInPin);
  }
  sensorValue = (sum + 8)/16;  // +8 is for rounding. using power of 2 gives fast divides.  
 
  // PROCESS 
  float voltage = sensorValue * (5.0 / 1023.0);

  // DISPLAY RESULTS
  Serial.print(millis() );                       
  Serial.print("\t sensor = \t" );                       
  Serial.print(sensorValue);      
  Serial.print("\t voltage = \t");
  Serial.print(voltage);
  Serial.print("\t time = \t");
  Serial.println(timer);
  timer++;
  delay(300);                     
}

your possible solution. Link