🛠 Lire un capteur avec l'ADC 12 bits du SAMD21

Arduino Tian (id: tian) · debutant · Schéma : IMG-tian-debutant-3-tian-lecture-analogique-12-bits.svg — potentiomètre 10 kΩ sur breadboard, curseur relié au picot A0 de l'Arduino Tian, alimentation du potentiomètre entre les rails 3,3 V et GND de la carte.

Objectives

Use the Tian's analog inputs: the board has 12 inputs, A0 to A11, all reusable as digital pins; A0–A5 are located in the same positions as on an UNO, while A6–A11 correspond to digital pins 4, 6, 8, 9, 10, and 12. Most importantly, the SAMD21 features a 12-bit analog-to-digital converter: unlike the UNO (10 bits, 0–1023), expect values ranging from 0 to 4095.

Hardware

Complete Code

// Lecture 12 bits : 0..4095 attendus, à vérifier au Traceur série.
const uint8_t POT = A0;

void setup {
  Serial.begin(115200);
}

void loop {
  int brut = analogRead(POT);        // ADC 12 bits du SAMD21 : 0..4095
  float tension = brut / 4095.0 * 3.3;  // à ajuster selon la référence réelle
  Serial.print(F("brut=")); Serial.print(brut);
  Serial.print(F(" ~")); Serial.print(tension, 2); Serial.println(F(" V"));
  delay(10);
}

Expected Verification

In the Serial Plotter, the value should follow the potentiometer continuously. Mentally estimate the amplitude: if you read approximately 0 to 4095, the 12-bit ADC is active; if you cap out at ~1023, your Arduino core is still mapping in 10 bits — adjust the conversion accordingly. This is THE major pitfall when porting from UNO → Tian.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials