Aref is by default internally connected to VCC of the processor,
which is about 5volt for a Mega.
You can change that by setting Aref to external, and connecting a wire between the Aref pin and the 3.3volt pin.
Warning: you must do both.
Just connecting a wire between Aref and 3.3volt will damage the processor.
The essential lines...
Leo..
void setup() {
analogReference(EXTERNAL); // switch Aref to an external stable voltage
}
void loop() {
float voltage = (sensor * 3.30) / 1024; // calibrate by changing the last digit(s) of 3.30.
}