Mathematical Calculation of Current with ACS712 20A

Wawa:
Voltage = (RawValue / 1024.0) * 5000; // Gets you mV

int mVperAmp = 100; // use 100 for 20A Module and 66 for 30A Module

Both lines are wrong if the Arduino supply is not exactly 5.000volt (which it rarely is).

ACSxxx sensors are ratiometric, and should be read as ratiometric sensors.
But most sketches you find on the net read them as voltage sensors,
which introduces errors if VCC is not exactly 5.000volt.
Leo..

?

The following demonstrates that the OP's code should work fine (that is, it correctly deals with the ratiometric nature of the sensor):

At zero amps and 5v supply, Vout is 2.5v, which the ADC reads as 512, and the code correctly converts that to 2500 mV and 0 amps.

If the supply droops to 4.5v, Vout is 2.25v, which the ADC also reads as 512, since it is half of the reference voltage of 4.5v, and the code correctly converts that to 2500 mV and 0 amps.

At 20 amps and 5v supply, Vout is 4.5v, which the ADC reads as 922, and the code correctly converts that to 4500 mV and 20 amps.

If the supply droops to 4.5v, Vout is 4.05v (sense drops to 90 mV/A, so 0.09*20+2.25=4.05v), which the ADC also reads as 922 (since the ref voltage is lower by the same proportion), and the code correctly converts that to 4500 mV and 20 amps.