🛠 Lire un capteur analogique sur l'ADC 12 bits

Particle Photon · debutant · Schéma : IMG-particle-photon-debutant-3-photon-capteur-adc.svg — potentiomètre relié à A0 du Photon (3,3 V, broche centrale sur A0, GND) pour lecture ADC

Objectives

Use the Photon's ADC: the board has 8 12-bit ADC inputs (A0 to A7). You will read a potentiometer wired as a voltage divider on A0 and convert the raw value (0 to 4095) into voltage.

Hardware

Complete code

// photon-capteur-adc.ino — lecture ADC 12 bits sur A0
const int CAPTEUR = A0;      // 8 entrées ADC 12 bits : A0..A7

void setup {
  Serial.begin(9600);
}

void loop {
  int brut = analogRead(CAPTEUR);          // 0..4095
  float tension = brut * 3.3f / 4095.0f;   // conversion en volts
  Serial.print("brut=");
  Serial.print(brut);
  Serial.print("  tension=");
  Serial.print(tension);
  Serial.println(" V");
  delay(200);
}

Expected verification

When turning the potentiometer, the raw value follows the wiper between 0 and 4095, and the calculated voltage remains between 0 and 3.3 V. Voltage divider schematic: potentiometer pin 1 to 3V3, pin 3 to GND, wiper to A0.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials