🛠 Lire un potentiomètre avec le vrai ADC 12 bits de la Due
Objectives
Leverage the analog side selling point of the Due: its analog-to-digital converter is 12 bits (0–4095), compared to 10 bits on AVR Arduinos. You will wire a potentiometer, read its position… and discover the core's documented pitfall: analogRead returns 10-bit values (0–1023) by default to maintain AVR compatibility. You must explicitly request 12-bit resolution using analogReadResolution(12).
Hardware
- 1 Arduino Due
- 1 10 kΩ potentiometer (3 pins: wiper in the middle)
- 3 male-to-male wires
- Micro-USB cable + serial monitor
Complete code
// Lecture 12 bits d'un potentiomètre sur A0
// Fils : potentiomètre broche gauche -> 3V3, curseur -> A0, broche droite -> GND
void setup {
analogReadResolution(12); // sans cette ligne : 0..1023 (défaut 10 bits !)
SerialUSB.begin(115200); // moniteur sur le port Native
}
void loop {
int brut = analogRead(A0); // 0..4095 en 12 bits
float tension = brut * 3.3f / 4095.0f; // base 3,3 V (Vref de la Due)
SerialUSB.printf("brut=%d soit %.3f V\n", brut, tension);
delay(50);
}
Expected verification
When turning the potentiometer to its limits, the raw value should sweep approximately from 0 to 4095, and the calculated voltage from 0 to 3.3 V. If you comment out analogReadResolution(12), the range drops back to 0–1023: this proves the core's 10-bit default. The voltage follows the wiper position linearly.
Common errors
- Forgetting
analogReadResolution(12)and then assuming (as in many tutorials) that the range is 0–4095: your voltage conversions will be off by a factor of 4. - Powering the potentiometer with 5 V: the Due's ADC reference is 3.3 V; applying more than 3.3 V to pin A0 puts you outside the measurable range — and remember, on digital pins, the absolute maximum is 3.3 V.
- Opening the wrong serial monitor (Serial vs SerialUSB, see the blinking tutorial).
- Swapping 3V3 and GND at the potentiometer's ends: the reading becomes inverted (no risk of destruction with a 10 kΩ potentiometer).
- Expecting zero noise: placing a finger on the potentiometer injects 50 Hz interference; average over multiple samples if needed.
Other tutorials for this board
- Faire clignoter la LED de l'Arduino Due et apprivoiser ses deux ports USB
- Allumer une LED externe en respectant les broches 3,3 V et 9 mA de la Due
- Générer une vraie tension analogique avec les DAC 12 bits (broches 66 et 67)
- Dialoguer avec un GPS (ou tout module TTL) sur Serial1 sans bloquer la boucle
- Scanner les deux bus I2C de la Due (Wire sur 20/21, Wire1 sur 70/71)
- Monter la Due sur un bus CAN 500 kbit/s avec un transceiver externe
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinodac-onde.inoArduinoadc-12-bits.inoArduinopwm-12-bits.inoArduinogps-serial1.inoArduino