Skip to content

Reading Analog Sensors - the ESP32 ADC

Beginning of the lesson

Reading Analog Sensors - the ESP32 ADC

So far your ESP32 has only asked the world yes-or-no questions: is the button pressed or not? Is the pin HIGH or LOW? But most of the real world is not yes-or-no. Light is not simply "on" or "off" - it is dim, medium, or blindingly bright. Temperature is not "hot or cold" - it is 19.4 degrees, or 23.1, or 31.7. A knob is not just "left or right" - it is turned exactly 37% of the way round.

To measure these smooth, in-between quantities, the ESP32 uses a special piece of hardware called an ADC - an Analog-to-Digital Converter. This one lesson turns your board from a switch-reader into a genuine measuring instrument. By the end you will build a working automatic night-light that turns an LED on by itself when the room goes dark.

The big idea: A sensor turns some physical thing (light, heat, force) into a voltage. The ADC turns that voltage into a number your program can use. Master that chain and you can read almost any analog sensor on Earth.

What you will learn

  • What an ADC actually does: turning a continuous voltage into a whole number.
  • The ESP32's 12-bit ADC, its 0-4095 range, and how analogRead() works.
  • How the ESP32 compares with the older Arduino Uno (10-bit, 0-1023).
  • Attenuation, the usable voltage range, and why readings go strange at the very top and bottom.
  • The two ADC blocks (ADC1 and ADC2) and the golden rule: ADC2 breaks when WiFi is on.
  • How a photoresistor (LDR) plus one fixed resistor forms a voltage divider - with the real formula and real numbers.
  • Turning raw readings into useful values: mapping, calibration, and smoothing out noise.
  • Building a complete, self-adjusting night-light, and fixing jumpy readings.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers