ESP32 reads up to 4095 but the code expects 1023

  • ESP32

Why it happens

  • The Uno measures 0 to 1023 at 5 V, the ESP32 0 to 4095 at about 3.3 V.

How to fix it

  1. Use 4095 in map() and in your thresholds.
  2. Or call analogReadResolution(10); in setup to get 0 to 1023.
  3. Keep the sensor's output at 3.3 V or less.

It worked if: The full range gives 0 to 100%.

From the official documentation. From the Arduino ESP32 ADC page. Sources: Arduino ESP32: ADC.

Didn't help? Search another error or ask us.