Analogread fluctuation

Hello
i am trying to measure voltage of 12v battery using arduino
i have coded everything and is working fine
the only problem is the analogread value is fluctuating a lot
i am using a buck converter to power up the arduino mega (6v in at the vin pin)

Please suggest what to do

Says here:

If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may be unstable

Maybe you aren't getting a reliable 5V. But if you look around the forum you'll find the analog input does fluctuate at the best of times, and it's been suggested to use only every second reading.

Aref should always have a capacitor to ground. Something like 0.1uF should be fine.

You might also take 5 or 10 readings and average them.

I presume you are using a resistive voltage divider. Add a 0.01uF capacitor from the analog pin to ground.

If this is in a car, a car is an incredibly noisy place. You may have ground noise. If you want an actual accurate, smooth reading of battery voltage, you might want to put a small Arduino right near the battery.