🛠 Lire un capteur analogique sur A0 (ADC 12 bits)

Arduino Nano ESP32 · debutant · Schéma : IMG-nano-esp32-debutant-3-nanoesp32-capteur-analogique.svg — Potentiomètre 10 kΩ câblé entre 3V3, A0 et GND avec échelle 0-3,3 V.

Objectives

Read an analog sensor (potentiometer or light sensor) on A0 using the ESP32-S3's 12-bit ADC (0-4095 for 0-3.3 V), convert the value to voltage, and understand the ADC2/Wi-Fi pitfall.

Hardware

Complete code

// A0..A7 : 8 entrées analogiques, ADC 12 bits, 3,3 V max (docs-db)
void setup {
  Serial.begin(115200);
}

void loop {
  int raw = analogRead(A0);                 // 0..4095
  float mv = raw * (3300.0 / 4095.0);       // tension en millivolts
  Serial.printf("A0 = %d (%.0f mV)\n", raw, mv);
  delay(200);
}

Expected verification

When turning the potentiometer, the raw value follows 0 → 4095 and the voltage 0 → approximately 3300 mV. At rest, the values remain stable (noise of only a few units).

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials