🛠 Régler la référence de mesure avec AREF et analogReference

Arduino Duemilanove — Board Fiche · intermediaire · Schéma : IMG-duemilanove-intermediaire-2-reference-aref-mesure-precise.svg — Arduino Duemilanove avec potentiomètre alimenté en 3V3, broche AREF reliée au 3V3 via un interrupteur, fonction analogReference(EXTERNAL) annotée, comparaison de deux mesures 10 bits (réf 5 V vs réf 3,3 V).

Objectives

The 10-bit ADC on the Duemilanove does not measure "volts": it measures a proportion of its reference voltage, which defaults to the regulated 5 V. The official page documents the AREF pin and analogReference for changing this ceiling. This tutorial shows why powering a sensor at 3.3 V while measuring with a 5 V reference wastes 34% of the resolution, and how AREF recovers the full 1024 levels — a skill that becomes critical when connecting 3.3 V sensors to a 5 V board.

Hardware

Complete code

// Mesure d'un potentiomètre 0..3,3 V avec reference externe 3,3 V
// Fils : pot. entre 3V3 et GND, curseur -> A0 ; AREF -> 3V3

const byte POT = A0;

void setup {
  Serial.begin(9600);
  analogReference(EXTERNAL);   // la mesure sera proportionnelle a V(AREF)
  delay(100);                  // laisser la reference se stabiliser
  Serial.println("Ref externe 3,3 V activee");
}

void loop {
  int brut = analogRead(POT);                       // 0..1023 sur 0..3,3 V
  float tension = brut * 3.3 / 1023.0;
  Serial.print("brut="); Serial.print(brut);
  Serial.print("  U="); Serial.print(tension);
  Serial.println(" V");
  delay(100);
}

Expected verification

With AREF connected to 3V3, turning the potentiometer to its maximum gives a reading close to 1023 (and not ~675 as with the internal 5 V reference). The displayed voltage follows the multimeter connected to the wiper. Disconnecting AREF (returning to the default internal 5 V reference after reset) causes the maximum range to drop back to around 675: the gained resolution is measurable.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials