yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
ESP32 Core Board📖
1. ESP32 Introduction
  • 1. ESP32S3 Overview
  • 2. Environment Setup Introduction
  • 3. Dev Board Introduction
2. ESP-IDF Development Tutorial
1. Before Development
  • 1. Environment Setup (Windows)
  • 2. Environment Setup (Linux)
  • 3. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. DMA
  • 8. ADC
  • 9. PWM Breathing LED
  • 10. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. PSRAM External Memory Experiment
  • 5. Flash Read and Write Experiment
  • 6. USB Emulated Mass Storage Experiment
4. FreeRTOS operating system
  • 1.FreeRTOS Core Concepts Theory
  • 2.Task Creation and Management
  • 3.Queue
  • 4.Binary Semaphore
  • 5.Mutex
  • 6.Event Groups
  • 7.Software Timer
  • 8.Task Scheduler
  • 9.Low Power Mode
  • 10.Deadlock
  • 11.Priority Inversion
5. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. Socket Programming Basics
  • 9. HTTP Client Experiment
  • 10. HTTP Server Experiment
  • 11. MQTT IoT Communication Protocol
  • 12. WIFI OTA Upgrade
  • 13. Bluetooth Fundamentals
  • 14. Bluetooth Slave Mode
  • 15. Bluetooth Master Mode
6. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
7. Xiaozhi AI Voice
  • 1. Burn Xiaozhi Firmware
  • 2. Network and Configuration
  • 3. AI Agent Settings
  • 4. Program Analysis
  • 5. Free Chat
3. Arduino Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. ADC
  • 8. PWM Breathing LED
  • 9. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication
  • 2. I2C OLED Display
  • 3. SPI Bus Communication
  • 4. Flash Read and Write
  • 5. USB Emulated Mass Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Server Experiment
  • 5. UDP Client Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT IoT Communication Protocol
  • 11. WIFI OTA Upgrade
  • 12. Bluetooth Fundamentals
  • 13. Bluetooth Slave Mode
  • 14. Bluetooth Master Mode
5. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
4. MicroPython Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
  • 3. Thonny IDE
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. TIMER_IT
  • 5. Watchdog Timer
  • 6. ADC
  • 7. PWM Breathing LED
  • 8. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. Flash Read and Write Experiment
  • 5. Print Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT
  • 11. Bluetooth Fundamentals
  • 12. Bluetooth Slave Mode
  • 13. Bluetooth Master Mode
5. Audio Applications
  • 1. I2S Audio Playback Experiment
  • 2. Repeater Experiment
Download
  • Code
  • Hardware_Info
  • 3D_Model_File
  • Software_Tools
  • VMware
  • VM_File
Download ZIP

Welcome to ESP32 Core Board repository

7. ADC

ADC


ADC1. ADC Overview2. Core Concepts2.1 ADC Resolution and Reference Voltage2.2 analogRead() Internal Flow2.3 Input Precautions3. Hardware Dependencies4. Project Architecture and Flow5. Source Code5.1 Pin Macro Definition5.2 setup() — Initialization5.3 loop() — Sampling and Conversion6. Operation Flow6.1 Build and Flash6.2 Normal Behavior6.3 Verification Method7. Common Issues


1. ADC Overview

ADC (Analog-to-Digital Converter) converts analog voltage into digital values, allowing the MCU to sense the continuous physical world. This experiment reads analog voltage on GPIO4 and prints the ADC raw value (0~4095) and the calculated actual voltage via serial port. Simply use analogRead() to complete the entire process from sampling to quantization.

Typical Application Scenarios:

Application TypeExample
Power MonitoringBattery level detection, USB power voltage monitoring
Environmental SensingPhotoresistor, NTC temperature sensor, soil moisture
Human-Computer InteractionPotentiometer knob, joystick, touch slider
Industrial MeasurementCurrent sampling (shunt resistor), pressure sensor, liquid level detection

2. Core Concepts

2.1 ADC Resolution and Reference Voltage

ESP32-S3 SAR ADC has 12-bit resolution:

Output Range: 0 ~ 4095 (2^12 - 1)
Reference Voltage: 3.3V (Vref)

Voltage Conversion Formula:

​x
voltage = (ADC_value / 4095) × 3.3V

Example: ADC = 2047 → 2047/4095 × 3.3 ≈ 1.65V (half scale)

2.2 analogRead() Internal Flow

  1. Select ADC1 controller and corresponding channel

  2. Configure sampling time (default ~2.5μs)

  3. Start SAR (Successive Approximation Register) ADC conversion

  4. Wait for conversion to complete (blocking, ~tens of microseconds)

  5. Return 12-bit result from 0~4095

2.3 Input Precautions

  • Input range 0 ~ 3.3V, exceeding will damage the GPIO

  • To measure higher voltages (such as 5V, 12V), an external resistor divider circuit is required

  • Floating ADC pins read random noise - this is normal, not a bug


3. Hardware Dependencies

PinPeripheralConfigurationDescription
GPIO4Analog signal sourceINPUTADC1 channel 3, input range 0~3.3V

For testing, leave it floating to observe noise values, or use a Dupont wire to connect GPIO4 to 3.3V/GND to observe full scale/zero.

0值连线

3.3峰值连线


4. Project Architecture and Flow

xxxxxxxxxx
setup()
  ├─ Serial.begin(115200)      // Initialize serial port
  └─ pinMode(4, INPUT)         // Set GPIO4 as analog input

loop()
  ├─ adc_value = analogRead(4) // Read ADC value (0~4095)
  ├─ voltage = adc_value × 3.3 / 4095  // Calculate voltage
  ├─ Serial.printf(...)        // Print results
  └─ delay(1000)               // Sample once per second

5. Source Code

Complete source: Source Code → Arduino → 1.Basic Peripherals → 7.ADC → 7.ADC.ino

5.1 Pin Macro Definition

pinMode(ADC_PIN, INPUT) disables digital output driver and configures as high-impedance analog input.

xxxxxxxxxx
#define ADC_PIN 4

5.2 setup() — Initialization

Only need to initialize serial port and pin mode. ADC peripheral is automatically configured by analogRead.

xxxxxxxxxx
void setup() {
  Serial.begin(115200);
  pinMode(ADC_PIN, INPUT);
}

Arduino's analogRead automatically completes ADC clock, resolution, and reference voltage configuration on the first call, no manual initialization required.

5.3 loop() — Sampling and Conversion

Read the raw value first, then convert to voltage using the formula. The f suffix in 3.3f indicates float type, avoiding unnecessary double precision overhead.

xxxxxxxxxx
void loop() {
  int adc_value = analogRead(ADC_PIN);
  float voltage = (adc_value * 3.3f) / 4095.0f;

  Serial.printf("ADC Value: %4d | Voltage: %.2f V\n", adc_value, voltage);
  delay(1000);
}

%4d is 4-digit right-aligned formatting for neat numeric column alignment. %.2f keeps two decimal places.


6. Operation Flow

6.1 Build and Flash

Arduino flash process: See Arduino → 1. Before Development → 2. Build and Flash.

6.2 Normal Behavior

Open the Serial Monitor (115200 bps), one line printed per second:

xxxxxxxxxx
========================================
     ESP32-S3 ADC Experiment Started
========================================
ADC Value:  841 | Voltage: 0.68 V
ADC Value:  237 | Voltage: 0.19 V
ADC Value:  233 | Voltage: 0.19 V
ADC Value:  377 | Voltage: 0.30 V
ADC Value:  157 | Voltage: 0.13 V
ADC Value:  987 | Voltage: 0.80 V
ADC Value:    0 | Voltage: 0.00 V
ADC Value:    0 | Voltage: 0.00 V

Serial Output

Connected to GND state:

GND

Connected to 3V3 state:

3V3

Floating state:

Floating

6.3 Verification Method

OperationExpected Result
GPIO4 floatingReads random noise value (normal)
GPIO4 connected to 3.3VADC ≈ 4095, Voltage ≈ 3.30V
GPIO4 connected to GNDADC ≈ 0, Voltage ≈ 0.00V
Change delay(1000) to delay(100)10 samples per second, faster value update

7. Common Issues

SymptomCauseSolution
Readings jump randomly when floatingADC input is high impedance, pin acts like an antennaNormal behavior, just connect a signal source
Large voltage deviationUncalibrated or reference voltage fluctuationMeasure actual Vref with a multimeter and substitute into formula
Readings always close to 0 or 4095Pin shorted to GND/VDDCheck wiring
Watchdog Timer
PWM Breathing LED

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文