Arduino incorrect readings from analog pin
I was running into the same issue, I tried reading voltage input on A0 and A1 (just to see if A0 was bad) and I was getting values higher than expected.

3.6 instead of 3.4

so the line

voltage = sensorValue * (5.0 / 1023.0);


wasn't outputting the correct value

My Arduino mega 2560 was being powered by rasberry pi via USB

Solution:

Supply your arduino board with regulated dc input and don't rely on USB power for your 5v or 3.3v boards.