🛠 Régler la référence de mesure avec AREF et analogReference
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
- 1 Arduino Duemilanove
- 1 10 kΩ potentiometer powered at 3V3 (reminder: the 3V3 pin comes from the FTDI chip, max 50 mA — a potentiometer consumes almost nothing)
- 1 wire to connect AREF to 3V3, mini-USB cable
- Multimeter useful for checking the actual 3V3 voltage
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
- Calling
analogReference(EXTERNAL)without connecting anything to AREF: the ADC measures a floating reference, resulting in garbage; always power AREF first. - Forgetting that the reference change only takes effect after an
analogRead: perform a warm-up read. - Sending more than 5 V to AREF or misaligning the reference and the sensor: the reference must be lower than AVCC (5 V) and cover the sensor's range.
- Relying on the 3V3 pin to power the sensor AND serve as a reference for a power-hungry setup: the 3V3 pin is limited to 50 mA (produced by the FTDI chip); beyond that, power the sensor separately and only draw a reference signal from AREF (negligible consumption).
- In EXTERNAL reference mode, forgetting that the displayed voltage assumes exactly 3.3 V: measure the actual 3V3 with a multimeter (often 3.2–3.4 V) and correct the constant.
- Not adding a
delay(100)after changing the reference: the first readings are skewed while the reference capacitor stabilizes.
Other tutorials for this board
- Faire clignoter la LED 13 d'une Duemilanove (et choisir le bon ATmega)
- Bouton poussoir et moniteur série sur la Duemilanove (avec ses 0,5 s de silence)
- Potentiomètre et variation LED : l'ADC 10 bits et le PWM 8 bits version AVR
- Ajouter un deuxième port série avec SoftwareSerial (GPS sur broches 10/11)
- Persister une calibration dans l'EEPROM de l'ATmega (512 octets ou 1 Ko)
- Convertir la Duemilanove en programmateur AVR (ArduinoISP) pour graver des puces nues
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinopwm-respiration.inoArduinopotentiometre-plotter.inoArduinoservo-balayage.inoArduinobuzzer-melodie.inoArduino