[ASK] AREF problem

hi, first of all i'm new to interfacing

I use arduino mega and try to capture data from analog input here my code:

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

void loop() {
analogReference(EXTERNAL);
int sensorValue = analogRead(A0);
Serial.println(sensorValue, DEC);
delay(1000);
}

my problem is, I can't use the analogReference, even when I used
analogReference(INTERNAL1V1) the data i read from serial monitor is still 1023

except when I used the analogReference(DEFAULT) it's working but i just need more resolution but i don't don't what's wrong with my code?

thx for anyone help me... :smiley:

Try putting the analogReference in 'setup'

What is the range of the input voltage?

already tried that
here's my new code

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

void loop() {
//analogReference(DEFAULT);
delay(500);
int sensorValue = analogRead(A0);
Serial.println(sensorValue, DEC);
delay(1000);
}

and do nothing with the output i get...stil 1023...well, i'm confused now.

is my arduino broken or something? because before, i forgot to put analog reference and use the AREF. but nothing smell burned or something...and i can still upload the program to arduino...so i guess not.

thx...

the input range is 1v

even when i put to 5v with analogReference(EXTERNAL) i still can't get use the ARef

i've tried for analogReference(EXTERNAL) and use 5v it's work but below 5v it can't work.

any suggestion?

What voltage does your device output? Using analogReference only makes sense when the device outputs less than 5 volts.

The fact that you consistently get 1023 implies that the device is outputting at or above the reference voltage. Perhaps significantly above.

It's hard to follow exactly what you've connected to what and when, but note that if you are using an internal reference you should NOT have another voltage connected to the AREF pin. Any external voltage will be connected directly to the internal reference and 5v != 1.1v.


Rob

Since you've been trying so many different scenarios maybe you should take a step back and run some simple tests to make sure you didn't damage your Mega.

First, remove any power source you have connected to the AREF pin and change your code to DEFAULT for analogreference. Next put a volt meter on the Aref pin and verify it reads ~5 volts.

Next, repeat the same test above but using INTERNAL1V1 and INTERNAL2V56 and confirm you are reading both voltages on the volt meter.

If your voltages are correct then there's a good chance the Mega is working.

Next with the DEFAULT setting in place ground the A0 pin and confirm your code reads 0.

Repeat the same test but this time connect A0 to 5v and verify you read 1023. Repeat again using 3.3v and verify the correct reading.

If that works then repeat the same tests using the different INTERNAL settings but verify the voltage you put on A0 is within the voltage range of the reference.

If none of these work on A0 then try the other analog inputs.

If these all work then switch to the EXTERNAL reference but make sure your code sets the reference first in setup before issuing analogread or else you'll have two supplies connected together and could damage the Mega.

Good luck... :slight_smile: