adc-12-bits.ino
The Due converts at 12 bits under 3.3 V: four times the steps of an AVR. A 16-sample moving average cleans the noise, and the voltage is returned in volts.
Hardware required
An Arduino Due (AT91SAM3X8E, ARM Cortex-M3 at 84 MHz) connected over USB to its « Programming » port. Caution: 3.3 V logic, never 5 V on the pins. 1 10 kΩ potentiometer (or 0-3.3 V analog sensor).
Wiring
Potentiometer ends on 3.3 V/GND — never 5 V on a Due —, wiper on A0.
How it works
analogReadResolution(12) raises the ADC to 4096 steps; a 16-value ring smooths the reading before the volt conversion. In the Arduino IDE, select « Arduino Due (Programming Port) » then Upload; the serial monitor runs at the speed set in the code.
Going further
Trigger acquisitions from a TC timer for regular sampling, or use a median filter against spikes.
adc-12-bits.ino
// ADC 12 bits (0..4095) sur A0, moyenne glissante sur 16 mesures.
const int N = 16;
long valeurs[N];
int idx = 0;
long somme = 0;
void setup() {
analogReadResolution(12); // 0..4095 au lieu de 0..1023
Serial.begin(115200);
}
void loop() {
somme -= valeurs[idx];
valeurs[idx] = analogRead(A0);
somme += valeurs[idx];
idx = (idx + 1) % N;
float tension = (somme / (float)N) * 3.3 / 4095.0;
Serial.print(somme / N);
Serial.print(F(" -> "));
Serial.println(tension, 3);
delay(100);
}