How to use analogReference

Hello Everyone, I just bought a Arduino Uno and I've been creating small simple projects/following tutorials.

For one of my projects, I have voltages ranging from 3-4.2V only. I know that the AnalogRead function assigns integer values from 0-1023 for 0-5V, but is there a way of adjusting it to 3-4.2V?

I believe I should use the analogReference function, but couldn't find any good tutorials in the forums and after a google search.

Below is my sample code to read a potentiometer value (one of the arduino tutorials!).

void setup() {

void loop() {
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue, DEC);

but is there a way of adjusting it to 3-4.2V?

Short answer: No.

Longer answer: You can, by applying a voltage to the AREF pin, make the top scale of the A/D converter (1023 counts) be anything less then 5vdc, however there is no way to establish 3vdc as zero counts. One way I could see doing what you want is using an external dual op-amp.

One op-amp to remove the 3vdc offset resulting in a 0-1.2vdc span, and then the other op-amp to amplify with a gain set to X 4.166 which then would result in a output range of 0-5vdc that could be measured to full resolution with the standard A/D configuration.