{"id":175829,"date":"2025-12-18T14:03:06","date_gmt":"2025-12-18T14:03:06","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=175829"},"modified":"2026-01-15T16:41:40","modified_gmt":"2026-01-15T16:41:40","slug":"esp-idf-esp32-gpio-analog-adc","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp-idf-esp32-gpio-analog-adc\/","title":{"rendered":"ESP-IDF: ESP32 GPIO &#8211; Read Analog Input (ADC &#8211; Analog to Digital Converter)"},"content":{"rendered":"\n<p>In this guide, you&#8217;ll learn how to set and read the ESP32 board&#8217;s GPIO pins as ADC (Analog to Digital Converter) with ESP-IDF (Espressif IoT Development Framework).<\/p>\n\n\n\n<p>The ESP32 is a microcontroller that offers several General Purpose Input\/Output (GPIO) pins that can be configured as either inputs or outputs. With the GPIOs set as analog inputs, you can read the analog voltage of devices like potentiometers, sensors, or other peripherals by reading the pin&#8217;s voltage from 0 to 3.3V (any value in between).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-GPIO-Read-Analog-Input-ADC-Analog-to-Digital-Converter.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-IDF ESP32 GPIO Read Analog Input ADC Analog to Digital Converter\" class=\"wp-image-177115\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-GPIO-Read-Analog-Input-ADC-Analog-to-Digital-Converter.jpg?w=1920&amp;quality=100&amp;strip=all&amp;ssl=1 1920w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-GPIO-Read-Analog-Input-ADC-Analog-to-Digital-Converter.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-GPIO-Read-Analog-Input-ADC-Analog-to-Digital-Converter.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-GPIO-Read-Analog-Input-ADC-Analog-to-Digital-Converter.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-GPIO-Read-Analog-Input-ADC-Analog-to-Digital-Converter.jpg?resize=1536%2C864&amp;quality=100&amp;strip=all&amp;ssl=1 1536w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>Before following this guide, you need to install the ESP-IDF extension on VS Code IDE (Microsoft Visual Studio Code). Follow the next guide to install it, if you haven&#8217;t already:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/programming-esp32-esp-idf-vs-code\/\"><strong>Getting Started Guide:<\/strong> Programming ESP32 with ESP-IDF using VS Code<\/a><\/li>\n<\/ul>\n\n\n\n<p>You will also need an <a href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\" rel=\"noopener\" title=\"\">ESP32 development board<\/a> model of your choice.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ESP32 ADC (Analog to Digital Converter) Modes<\/h2>\n\n\n\n<p>In ESP-IDF, you can use the ESP32 GPIOs as ADC (Analog to Digital Converter) in three different modes: One-Shot mode, Continuous Mode or Calibration Mode. In the following table, we break down the different ADC Modes and their corresponding features.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>ADC Mode<\/strong><\/td><td><strong>One-Shot Mode<\/strong><\/td><td><strong>Continuous Mode<\/strong><\/td><td>Reads the ADC continuously at high speed<\/td><\/tr><tr><td><strong>How It Works<\/strong><\/td><td>Returns a single reading<\/td><td>Reads the ADC contiguously at high speed<\/td><td>Calibrates the pins for higher accuracy<\/td><\/tr><tr><td><strong>Application<\/strong><\/td><td>Occasional measurements (battery level check, basic sensor reading, etc&#8230;)<\/td><td>Real-time fast analog readings (audio sampling)<\/td><td>Accurate voltage measurements (fix sensor readings)<\/td><\/tr><tr><td><strong>Implementation<\/strong><\/td><td>Easy to implement<\/td><td>Slightly more complex to implement, it requires DMA configuration<\/td><td>Moderate to implement<\/td><\/tr><tr><td><strong>ADC GPIOs<\/strong><\/td><td>Compatible with ADC1 and ADC2<\/td><td>Compatible only with ADC1<\/td><td>Compatible with ADC1 and ADC2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">ESP32 ADC Range<\/h3>\n\n\n\n<p>Reading an analog value with the ESP32 means you can measure varying voltage levels between 0V and 3.3V.<\/p>\n\n\n\n<p>The voltage measured is then assigned to a value between 0 and 4095 (using a 12-bit resolution), in which 0V corresponds to 0, and 3.3V corresponds to 4095. Any voltage between 0V and 3.3V will be given the corresponding value in between.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"218\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP32-ADC-Range-12-bit-Resolution.png?resize=750%2C218&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ADC Range 12 bit Resolution\" class=\"wp-image-177114\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP32-ADC-Range-12-bit-Resolution.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP32-ADC-Range-12-bit-Resolution.png?resize=300%2C87&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">ESP32 ADC is Non-linear<\/h3>\n\n\n\n<p>Ideally, you would expect a linear behavior when using the ESP32 ADC pins. However, that doesn\u2019t happen. What you\u2019ll get is a behavior as shown in the following chart:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"768\" height=\"474\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ADC-non-linear-ESP32.png?resize=768%2C474&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP32 ADC Analog Read Inputs Range Value behavior\" class=\"wp-image-85753\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ADC-non-linear-ESP32.png?w=768&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ADC-non-linear-ESP32.png?resize=300%2C185&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><figcaption class=\"wp-element-caption\"><a href=\"https:\/\/github.com\/espressif\/arduino-esp32\/issues\/92\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">View source<\/a><\/figcaption><\/figure><\/div>\n\n\n<p>This behavior means that your ESP32 is not able to distinguish 3.3V from 3.2V. You\u2019ll get the same value for both voltages: 4095 (if you are using a 12-bit resolution). The same happens for very low voltage values: for 0V and 0.1V you\u2019ll get the same value: 0. You need to keep this in mind when using the ESP32 ADC pins.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ESP32 ADC GPIOs<\/h3>\n\n\n\n<p>The ESP32 supports measurements in 18 different channels. Only 15 are available in the <a aria-label=\"DEVKIT V1 DOIT (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\" rel=\"noreferrer noopener\">DEVKIT V1 DOIT<\/a> board (version with 30 GPIOs). Grab your ESP32 board pinout and locate the ADC pins. These are highlighted with a red border in the figure below.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/randomnerdtutorials.com\/adc-pins-esp32-f\/\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"471\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/adc-pins-esp32-f.jpg?resize=700%2C471&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ADC GPIOs Pins\" class=\"wp-image-85829\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/adc-pins-esp32-f.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/adc-pins-esp32-f.jpg?resize=300%2C202&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/a><\/figure><\/div>\n\n\n<p class=\"rntbox rntclblue\">Learn more about the ESP32 GPIOs: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-pinout-reference-gpios\/\">ESP32 Pinout Reference<\/a>.<\/p>\n\n\n\n<p>In case of the ESP32-S3 boards, the ADC GPIOs are highlighted in purple color and labelled as ADCX_X.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/randomnerdtutorials.com\/esp32-s3-devkitc-pinout-guide\/esp32-s3-pinout\/#main\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"818\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/ESP32-S3-pinout.jpg?resize=1200%2C818&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-162320\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/ESP32-S3-pinout.jpg?w=1584&amp;quality=100&amp;strip=all&amp;ssl=1 1584w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/ESP32-S3-pinout.jpg?resize=300%2C205&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/ESP32-S3-pinout.jpg?resize=1024%2C698&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/ESP32-S3-pinout.jpg?resize=768%2C524&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/ESP32-S3-pinout.jpg?resize=1536%2C1047&amp;quality=100&amp;strip=all&amp;ssl=1 1536w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/a><\/figure><\/div>\n\n\n<p class=\"rntbox rntclblue\">Learn more about the ESP32-S3 GPIOs: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-s3-devkitc-pinout-guide\/\" title=\"\">ESP32-S3 GPIO Reference Guide<\/a>.<\/p>\n\n\n\n<p class=\"rntbox rntclblue\"><strong>Note: <\/strong> ADC2 pins cannot be used when Wi-Fi is used. So, if you\u2019re using Wi-Fi and you\u2019re having trouble getting the value from an ADC2 GPIO, you may consider using an ADC1 GPIO instead, that should solve your problem.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating an ESP-IDF Template App Project for the ESP32<\/h2>\n\n\n\n<p>The ESP-IDF extension provides an easy way to create a project from scratch with all the required files and configurations generated automatically.<\/p>\n\n\n\n<p>To create a new ESP-IDF project on VS Code, follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the ESP-IDF Espressif extension<\/li>\n\n\n\n<li>Expand the &#8220;<strong>Advanced<\/strong>&#8221; menu<\/li>\n\n\n\n<li>Click the &#8220;<strong>New Project Wizard<\/strong>&#8221; option<\/li>\n\n\n\n<li>Choose the &#8220;<strong>Use ESP-IDF v5.4.1<\/strong>&#8221; to select the framework version<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"937\" height=\"742\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Create-Open-New-Project-Wizard-Menu.png?resize=937%2C742&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-IDF ESP32 Create Open New Project Wizard Menu\" class=\"wp-image-170511\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Create-Open-New-Project-Wizard-Menu.png?w=937&amp;quality=100&amp;strip=all&amp;ssl=1 937w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Create-Open-New-Project-Wizard-Menu.png?resize=300%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Create-Open-New-Project-Wizard-Menu.png?resize=768%2C608&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 937px) 100vw, 937px\" \/><\/figure><\/div>\n\n\n<p>A new window opens, you need to fill in these fields:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Project Name:<\/strong> type the desired project name;<\/li>\n\n\n\n<li><strong>Enter Project Directory:<\/strong> click the folder icon and select the target folder to save all your project files. You can use any directory. <strong>Note:<\/strong> <u>do NOT use a Google Drive \/ One Drive \/ Dropbox folder<\/u>, because it will write\/create many files during the building process\u2014if it&#8217;s on a cloud folder, this process might be extremely slow;<\/li>\n\n\n\n<li><strong>ESP-IDF Target:<\/strong> select the target device chip, I&#8217;m using an ESP32 with the <strong>esp32s3<\/strong> chip;<\/li>\n\n\n\n<li><strong>ESP-IDF Board:<\/strong> for the esp32s3 chip, I also need to select the configuration: ESP32-S chip (via builtin USB-JTAG);<\/li>\n\n\n\n<li><strong>Serial Port:<\/strong> while having your ESP32 board connected to your computer, select the correct COM port number that refers to your ESP32;<\/li>\n\n\n\n<li><strong>Choose Template:<\/strong> click the blue button to create a new project using a template.<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"983\" height=\"856\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Create-Open-New-Project-Wizard-Menu-Select-Directory-Board-Template.png?resize=983%2C856&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-IDF ESP32 Create Open New Project Wizard Menu Select Directory Board Template\" class=\"wp-image-170512\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Create-Open-New-Project-Wizard-Menu-Select-Directory-Board-Template.png?w=983&amp;quality=100&amp;strip=all&amp;ssl=1 983w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Create-Open-New-Project-Wizard-Menu-Select-Directory-Board-Template.png?resize=300%2C261&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Create-Open-New-Project-Wizard-Menu-Select-Directory-Board-Template.png?resize=768%2C669&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 983px) 100vw, 983px\" \/><\/figure><\/div>\n\n\n<p>In the menu, select the &#8220;<strong>ESP-IDF Templates<\/strong>&#8221; sample project and press the &#8220;<strong>Create project using template sample project<\/strong>&#8221; button.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1178\" height=\"744\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/ESP-IDF-ESP32-Create-New-Sample-Project-using-IDF-Template.png?resize=1178%2C744&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-IDF ESP32 Create New Sample Project using IDF Template\" class=\"wp-image-187415\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/ESP-IDF-ESP32-Create-New-Sample-Project-using-IDF-Template.png?w=1178&amp;quality=100&amp;strip=all&amp;ssl=1 1178w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/ESP-IDF-ESP32-Create-New-Sample-Project-using-IDF-Template.png?resize=300%2C189&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/ESP-IDF-ESP32-Create-New-Sample-Project-using-IDF-Template.png?resize=1024%2C647&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/ESP-IDF-ESP32-Create-New-Sample-Project-using-IDF-Template.png?resize=768%2C485&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1178px) 100vw, 1178px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Opening the ESP-IDF Project on VS Code<\/h3>\n\n\n\n<p>After a few seconds, a notification will appear on a new window on VS Code. You can click &#8220;<strong>Open Project<\/strong>&#8221; to open the newly created ESP-IDF sample project template.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"503\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/ESP-IDF-ESP32-Open-New-Project-Sample.png?resize=1024%2C503&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-IDF ESP32 Open New Project Sample\" class=\"wp-image-187416\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/ESP-IDF-ESP32-Open-New-Project-Sample.png?resize=1024%2C503&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/ESP-IDF-ESP32-Open-New-Project-Sample.png?resize=300%2C147&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/ESP-IDF-ESP32-Open-New-Project-Sample.png?resize=768%2C377&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/ESP-IDF-ESP32-Open-New-Project-Sample.png?w=1231&amp;quality=100&amp;strip=all&amp;ssl=1 1231w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>IMPORTANT:<\/strong> if you didn&#8217;t see the notification that allows you to automatically open the ESP-IDF project on VS Code, you can easily do it by following these instructions:<\/p>\n\n\n\n<p>Go to <strong>File <\/strong>&gt; <strong>Open Folder&#8230;<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"396\" height=\"315\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Open-Project-Folder-VS-Code-File-Menu.png?resize=396%2C315&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-IDF ESP32 Open Project Folder VS Code File Menu\" class=\"wp-image-170518\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Open-Project-Folder-VS-Code-File-Menu.png?w=396&amp;quality=100&amp;strip=all&amp;ssl=1 396w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Open-Project-Folder-VS-Code-File-Menu.png?resize=300%2C239&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 396px) 100vw, 396px\" \/><\/figure><\/div>\n\n\n<p>Browse on your computer for the <em>esp-idf-project folder<\/em> (your project folder name that you&#8217;ve previously defined) and &#8220;<strong>Select Folder<\/strong>&#8220;.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"667\" height=\"366\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Open-Project-VS-Code-Select-Folder.png?resize=667%2C366&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-IDF ESP32 Open Project VS Code Select Folder\" class=\"wp-image-170517\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Open-Project-VS-Code-Select-Folder.png?w=667&amp;quality=100&amp;strip=all&amp;ssl=1 667w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Open-Project-VS-Code-Select-Folder.png?resize=300%2C165&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 667px) 100vw, 667px\" \/><\/figure><\/div>\n\n\n<p>That&#8217;s it! Your new ESP-IDF project template has been successfully created and opened.<\/p>\n\n\n\n<p>ESP-IDF generates many files, folders, and subfolders for your project. For this guide, I recommend keeping all the default files unchanged; we will only modify the <em>main.c<\/em> file.<\/p>\n\n\n\n<p>The example codes will be written in the <em>main.c<\/em> file. To open it, follow these instructions:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the project explorer by clicking the first icon on the left sidebar.<\/li>\n\n\n\n<li>Select your project folder name, in my case it&#8217;s &#8220;<strong>ESP-IDF-PROJECT<\/strong>&#8220;.<\/li>\n\n\n\n<li>Expand the &#8220;<strong>main<\/strong>&#8221; folder.<\/li>\n\n\n\n<li>Click the &#8220;<strong><em>main.c<\/em><\/strong>&#8221; file.<\/li>\n\n\n\n<li>The default <em>main.c<\/em> template file loads in the code window.<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"907\" height=\"571\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Open-Project-in-a-VS-Code-Browse-to-Main-C-File.png?resize=907%2C571&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-IDF ESP32 Open Project in a VS Code Browse to Main C File\" class=\"wp-image-170514\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Open-Project-in-a-VS-Code-Browse-to-Main-C-File.png?w=907&amp;quality=100&amp;strip=all&amp;ssl=1 907w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Open-Project-in-a-VS-Code-Browse-to-Main-C-File.png?resize=300%2C189&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/ESP-IDF-ESP32-Open-Project-in-a-VS-Code-Browse-to-Main-C-File.png?resize=768%2C483&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 907px) 100vw, 907px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Example #1: Read ESP32 Analog Inputs with ESP-IDF &#8211; One-Shot Mode<\/h2>\n\n\n\n<p>Copy the following code to the <em>main.c<\/em> file. This code takes a reading of a potentiometer connected to ESP32 <span class=\"rnthl rntliteral\">ADC1<\/span> on <span class=\"rnthl rntliteral\">Channel 7<\/span> using the <span class=\"rnthl rntliteral\">adc_oneshot_read()<\/span> function:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*  \n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  https:\/\/RandomNerdTutorials.com\/esp-idf-esp32-gpio-analog-adc\/\n*\/\n\n#include &lt;freertos\/FreeRTOS.h&gt;\n#include &lt;freertos\/task.h&gt;\n#include &lt;esp_adc\/adc_oneshot.h&gt;\n#include &lt;esp_log.h&gt;\n#include &quot;sdkconfig.h&quot;\n\n#define ADC_PIN       ADC_CHANNEL_7     \/\/ Channel 7 - Check ESP32 Pinout for the GPIO Number\n#define ADC_UNIT      ADC_UNIT_1        \/\/ ADC1\n#define ADC_BITWIDTH  ADC_BITWIDTH_12   \/\/ 12-bit resolution (0-4095)\n#define ADC_ATTEN     ADC_ATTEN_DB_12   \/\/ ~3.3V full-scale voltage\n\nvoid app_main(void)\n{\n    int adc_value;\n    adc_oneshot_unit_handle_t adc_handle;\n\n    \/\/ Initialize ADC Oneshot Mode Driver on the ADC Unit\n    adc_oneshot_unit_init_cfg_t init_config = {\n        .unit_id = ADC_UNIT,\n        .clk_src = ADC_RTC_CLK_SRC_DEFAULT,\n    };\n    ESP_ERROR_CHECK(adc_oneshot_new_unit(&amp;init_config, &amp;adc_handle));\n\n    \/\/ Configure ADC channel\n    adc_oneshot_chan_cfg_t config = {\n        .bitwidth = ADC_BITWIDTH,\n        .atten = ADC_ATTEN,\n    };\n    ESP_ERROR_CHECK(adc_oneshot_config_channel(adc_handle, ADC_PIN, &amp;config));\n\n    \/\/ ADC Oneshot Analog Read loop\n    while (1) {\n        \/\/ Read ADC value with Oneshot\n        ESP_ERROR_CHECK(adc_oneshot_read(adc_handle, ADC_PIN, &amp;adc_value));\n        \/\/ Print ADC value\n        ESP_LOGI(&quot;ADC Value&quot;, &quot;%d&quot;, adc_value);\n        \/\/ Delay 1 second\n        vTaskDelay(1000 \/ portTICK_PERIOD_MS); \n    }\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP-IDF\/analog_input\/analog_input_adc_oneshot.c\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How the Code Works<\/h3>\n\n\n\n<p>In this section, we&#8217;ll take a look at the code to see how it works.<\/p>\n\n\n\n<p><strong>Libraries<\/strong><\/p>\n\n\n\n<p>We start by including the required libraries:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">FreeRTOS.h<\/span> &#8211; provides the core FreeRTOS types and functions;<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">task.h<\/span> &#8211; allows to use of the non-blocking delay function <span class=\"rnthl rntliteral\">vTaskDelay<\/span>;<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">esp_adc\/adc_oneshot.h<\/span> &#8211; includes the functions required to configure the ESP32&#8217;s ADC in One-Shot mode to take analog readings from specific channels;<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">esp_log.h<\/span> &#8211; offers a framework to format log messages in the serial monitor for debugging;<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">sdkconfig.h<\/span> &#8211; includes the project&#8217;s configuration file.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;freertos\/FreeRTOS.h&gt;\n#include &lt;freertos\/task.h&gt;\n#include &lt;esp_adc\/adc_oneshot.h&gt;\n#include &lt;esp_log.h&gt;\n#include \"sdkconfig.h\"<\/code><\/pre>\n\n\n\n<p><strong>Definitions<\/strong><\/p>\n\n\n\n<p>These lines define the ADC channel, ADC unit, set the 12-bit resolution (values between 0-4095) and set the attenuation.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define ADC_PIN       ADC_CHANNEL_7    \/\/ Channel 7 - Check ESP32 Pinout for the GPIO Number\n#define ADC_UNIT      ADC_UNIT_1        \/\/ ADC1\n#define ADC_BITWIDTH  ADC_BITWIDTH_12   \/\/ 12-bit resolution (0-4095)\n#define ADC_ATTEN     ADC_ATTEN_DB_12    \/\/ ~3.3V full-scale voltage<\/code><\/pre>\n\n\n\n<p><strong>app_main(void)<\/strong><\/p>\n\n\n\n<p>When creating an ESP-IDF project, this function will always be called to run. This function is where you need to write your code for any ESP-IDF applications; it is the equivalent of the <span class=\"rnthl rntliteral\">setup()<\/span> in Arduino programming. When the ESP32 boots, the ESP-IDF framework calls <span class=\"rnthl rntliteral\">app_main<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void app_main(void)\n{\n    \/\/ your code goes here\n}<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">app_main(void)<\/span> function, you start by initializing the <span class=\"rnthl rntliteral\">adc_value<\/span> and the <span class=\"rnthl rntliteral\">adc_handle<\/span> variables<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int adc_value;\nadc_oneshot_unit_handle_t adc_handle;<\/code><\/pre>\n\n\n\n<p>Then, initialize the <span class=\"rnthl rntliteral\">adc_oneshot<\/span> driver with the <span class=\"rnthl rntliteral\">ADC_UNIT<\/span> and <span class=\"rnthl rntliteral\">CLK<\/span>:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>adc_oneshot_unit_init_cfg_t init_config = {\n    .unit_id = ADC_UNIT,\n    .clk_src = ADC_RTC_CLK_SRC_DEFAULT,\n};\nESP_ERROR_CHECK(adc_oneshot_new_unit(&amp;init_config, &amp;adc_handle));<\/code><\/pre>\n\n\n\n<p>Configure the ADC channel with the <span class=\"rnthl rntliteral\">ADC_BITWIDTH<\/span> and <span class=\"rnthl rntliteral\">ADC_ATTEN<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>adc_oneshot_chan_cfg_t config = {\n    .bitwidth = ADC_BITWIDTH,\n    .atten = ADC_ATTEN,\n};\nESP_ERROR_CHECK(adc_oneshot_config_channel(adc_handle, ADC_PIN, &amp;config));<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">while(1)<\/span> runs an infinite loop that ensures that you are constantly checking the current GPIO voltage value.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>while (1) {\n    \/\/ Read ADC value with Oneshot\n    ESP_ERROR_CHECK(adc_oneshot_read(adc_handle, ADC_PIN, &amp;adc_value));\n    \/\/ Print ADC value\n    ESP_LOGI(\"ADC Value\", \"%d\", adc_value);\n    \/\/ Delay 1 second\n    vTaskDelay(1000 \/ portTICK_PERIOD_MS); \n}<\/code><\/pre>\n\n\n\n<p>Inside the infinite loop, you read the current GPIO voltage using the <span class=\"rnthl rntliteral\">adc_oneshot_read()<\/span> function and store it in the <span class=\"rnthl rntliteral\">adc_value<\/span> variable.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>ESP_ERROR_CHECK(adc_oneshot_read(adc_handle, ADC_PIN, &amp;adc_value));<\/code><\/pre>\n\n\n\n<p>You can print the ADC value returned in the Serial Monitor using the <span class=\"rnthl rntliteral\">ESP_LOGI()<\/span> function.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>ESP_LOGI(\"ADC Value\", \"%d\", adc_value);<\/code><\/pre>\n\n\n\n<p>Finally, add a 1 second delay:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>vTaskDelay(1000 \/ portTICK_PERIOD_MS); <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Build and Flash Code to the ESP32 Board<\/h2>\n\n\n\n<p>To build and flash ESP-IDF code to the ESP32, you always need to follow this procedure. You need to select the flash method (UART), the COM port number, the target device (ESP32), build the code, and finally, flash it to the board. All these commands are available in the bottom menu bar of VS Code.<\/p>\n\n\n\n<p>Make sure all your options are correct (they may already be properly configured if you used the project wizard).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"498\" height=\"28\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Check-All-the-Configured-Settings-UART-COM-Port-Target-Board.png?resize=498%2C28&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"VS Code ESP-IDF Check All the Configured Settings UART COM Port Target Board\" class=\"wp-image-170147\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Check-All-the-Configured-Settings-UART-COM-Port-Target-Board.png?w=498&amp;quality=100&amp;strip=all&amp;ssl=1 498w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Check-All-the-Configured-Settings-UART-COM-Port-Target-Board.png?resize=300%2C17&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 498px) 100vw, 498px\" \/><\/figure><\/div>\n\n\n<p>However, if your setup is not correct, follow the next instructions to ensure everything is set up correctly. First, click the &#8220;<strong>Star<\/strong>&#8221; icon and select the flash method as <strong>UART<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"584\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Select-Flash-UART-Option-to-Program-Flash-ESP32-1024x584.png?resize=1024%2C584&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"VS Code ESP-IDF Select Flash UART Option to Program Flash ESP32\" class=\"wp-image-170161\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Select-Flash-UART-Option-to-Program-Flash-ESP32.png?resize=1024%2C584&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Select-Flash-UART-Option-to-Program-Flash-ESP32.png?resize=300%2C171&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Select-Flash-UART-Option-to-Program-Flash-ESP32.png?resize=768%2C438&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Select-Flash-UART-Option-to-Program-Flash-ESP32.png?w=1030&amp;quality=100&amp;strip=all&amp;ssl=1 1030w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>While the ESP32 board is connected to your computer, click the COM Port (plug icon) and select the correct port number that refers to your ESP32.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"582\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Programming-ESP32-Board-Select-Correct-COM-Port-Number.png?resize=1024%2C582&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"VS Code ESP-IDF Programming ESP32 Board Select Correct COM Port Number\" class=\"wp-image-170160\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Programming-ESP32-Board-Select-Correct-COM-Port-Number.png?resize=1024%2C582&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Programming-ESP32-Board-Select-Correct-COM-Port-Number.png?resize=300%2C171&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Programming-ESP32-Board-Select-Correct-COM-Port-Number.png?resize=768%2C437&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Programming-ESP32-Board-Select-Correct-COM-Port-Number.png?w=1032&amp;quality=100&amp;strip=all&amp;ssl=1 1032w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>You also need to select the target device. Click on the chip icon at the bottom bar. In my case, I have an ESP32 with the <strong>esp32s3<\/strong> chip.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"579\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Select-the-ESP32-S3-or-Correct-Target-Device.png?resize=1024%2C579&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"VS Code Select the ESP32 S3 or Correct Target Device ESP-IDF\" class=\"wp-image-170163\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Select-the-ESP32-S3-or-Correct-Target-Device.png?resize=1024%2C579&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Select-the-ESP32-S3-or-Correct-Target-Device.png?resize=300%2C170&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Select-the-ESP32-S3-or-Correct-Target-Device.png?resize=768%2C434&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Select-the-ESP32-S3-or-Correct-Target-Device.png?w=1031&amp;quality=100&amp;strip=all&amp;ssl=1 1031w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>For this board, I also need to select the configuration: <strong>ESP32-S3 chip (via builtin USB-JTAG)<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"757\" height=\"579\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Select-the-ESP32-S3-chip-via-built-in-USB-JTAG-Target-Device.png?resize=757%2C579&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"VS Code ESP-IDF Select the ESP32 S3 chip via built in USB JTAG Target Device\" class=\"wp-image-170162\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Select-the-ESP32-S3-chip-via-built-in-USB-JTAG-Target-Device.png?w=757&amp;quality=100&amp;strip=all&amp;ssl=1 757w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Select-the-ESP32-S3-chip-via-built-in-USB-JTAG-Target-Device.png?resize=300%2C229&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 757px) 100vw, 757px\" \/><\/figure><\/div>\n\n\n<p>Finally, your command bar at the bottom of VS Code should have similar options selected.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"498\" height=\"28\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Check-All-the-Configured-Settings-UART-COM-Port-Target-Board.png?resize=498%2C28&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"VS Code ESP-IDF Check All the Configured Settings UART COM Port Target Board\" class=\"wp-image-170147\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Check-All-the-Configured-Settings-UART-COM-Port-Target-Board.png?w=498&amp;quality=100&amp;strip=all&amp;ssl=1 498w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Check-All-the-Configured-Settings-UART-COM-Port-Target-Board.png?resize=300%2C17&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 498px) 100vw, 498px\" \/><\/figure><\/div>\n\n\n<p>Now, you can build the project by clicking the wrench icon (<strong>Build Project<\/strong>) as shown in the image below.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"581\" height=\"359\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/06\/VS-Code-Build-Project-Example-Code-ESP32-ESP-IDF.png?resize=581%2C359&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"VS Code Build Project Example Code ESP32 ESP-IDF\" class=\"wp-image-170743\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/06\/VS-Code-Build-Project-Example-Code-ESP32-ESP-IDF.png?w=581&amp;quality=100&amp;strip=all&amp;ssl=1 581w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/06\/VS-Code-Build-Project-Example-Code-ESP32-ESP-IDF.png?resize=300%2C185&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 581px) 100vw, 581px\" \/><\/figure><\/div>\n\n\n<p>The first time you build a project, it usually takes a bit more time. Once completed, it should print a similar message in the <strong>Terminal<\/strong> menu and show a &#8220;<strong>Build Successfully<\/strong>&#8221; message.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"648\" height=\"468\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/06\/VS-Code-Build-Example-Project-ESP32-ESP-IDF-Success-Message.jpg?resize=648%2C468&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"VS Code Build Example Project ESP32 ESP-IDF Success Message\" class=\"wp-image-170742\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/06\/VS-Code-Build-Example-Project-ESP32-ESP-IDF-Success-Message.jpg?w=648&amp;quality=100&amp;strip=all&amp;ssl=1 648w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/06\/VS-Code-Build-Example-Project-ESP32-ESP-IDF-Success-Message.jpg?resize=300%2C217&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 648px) 100vw, 648px\" \/><\/figure><\/div>\n\n\n<p>This is the final step. You can now flash the ESP-IDF project to the ESP32 by clicking the &#8220;<strong>Flash Device<\/strong>&#8221; button (thunder icon).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"848\" height=\"170\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Flash-Hello-World-Code-Project-to-ESP32-ESP-IDF.png?resize=848%2C170&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"VS Code Flash Hello World Code Project to ESP32 ESP-IDF\" class=\"wp-image-170294\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Flash-Hello-World-Code-Project-to-ESP32-ESP-IDF.png?w=848&amp;quality=100&amp;strip=all&amp;ssl=1 848w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Flash-Hello-World-Code-Project-to-ESP32-ESP-IDF.png?resize=300%2C60&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Flash-Hello-World-Code-Project-to-ESP32-ESP-IDF.png?resize=768%2C154&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 848px) 100vw, 848px\" \/><\/figure><\/div>\n\n\n<p>Depending on your board, you might need to hold down the on-board BOOT button on your ESP32 to put it into flashing mode. Once the process is completed, it will pop-up a info message saying &#8220;<strong>Flash Done<\/strong>&#8220;.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"575\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Flash-Hello-Wolrd-Project-to-ESP32-ESP-IDF-Done-Success-Message.png?resize=1024%2C575&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"VS Code Flash Hello World Project to ESP32 ESP-IDF Done Success Message\" class=\"wp-image-170155\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Flash-Hello-Wolrd-Project-to-ESP32-ESP-IDF-Done-Success-Message.png?resize=1024%2C575&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Flash-Hello-Wolrd-Project-to-ESP32-ESP-IDF-Done-Success-Message.png?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Flash-Hello-Wolrd-Project-to-ESP32-ESP-IDF-Done-Success-Message.png?resize=768%2C431&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Flash-Hello-Wolrd-Project-to-ESP32-ESP-IDF-Done-Success-Message.png?w=1039&amp;quality=100&amp;strip=all&amp;ssl=1 1039w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Schematic Diagram<\/h3>\n\n\n\n<p>Here\u2019s a list of the parts you need to build the circuit:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\" rel=\"noreferrer noopener\">ESP32<\/a>&nbsp;(read&nbsp;<a href=\"https:\/\/makeradvisor.com\/esp32-development-boards-review-comparison\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best ESP32 Dev Boards<\/a>)<\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/potentiometer-assortment-kit\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Potentiometer<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noreferrer noopener\">Breadboard<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noreferrer noopener\">Jumper wires<\/a><\/li>\n<\/ul>\n\n\n\n<p>Connect a potentiometer to <span class=\"rnthl rntcblue\">ADC1 Channel 7<\/span> (in this case, it corresponds to GPIO 8) as shown in the schematic diagram below for a board with <a href=\"https:\/\/randomnerdtutorials.com\/esp32-s3-devkitc-pinout-guide\/\">ESP32-S3 chip<\/a>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"774\" height=\"870\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP32-S3-Potentiometer-Circuit-Analog-Input-ADC.jpg?resize=774%2C870&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-S3 Potentiometer Circuit Analog Input ADC\" class=\"wp-image-177116\" style=\"width:585px;height:auto\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP32-S3-Potentiometer-Circuit-Analog-Input-ADC.jpg?w=774&amp;quality=100&amp;strip=all&amp;ssl=1 774w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP32-S3-Potentiometer-Circuit-Analog-Input-ADC.jpg?resize=267%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 267w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP32-S3-Potentiometer-Circuit-Analog-Input-ADC.jpg?resize=768%2C863&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 774px) 100vw, 774px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>If you followed all the steps, the example should be running successfully on your board. Open your Terminal window \u2014 click the &#8220;<strong>Monitor Device<\/strong>&#8221; tool that is illustrated with a screen icon.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"780\" height=\"77\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Open-Terminal-Window-Monitor-Device-ESP32-ESP-IDF.png?resize=780%2C77&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"VS Code Open Terminal Window Monitor Device ESP32 ESP-IDF\" class=\"wp-image-170157\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Open-Terminal-Window-Monitor-Device-ESP32-ESP-IDF.png?w=780&amp;quality=100&amp;strip=all&amp;ssl=1 780w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Open-Terminal-Window-Monitor-Device-ESP32-ESP-IDF.png?resize=300%2C30&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Open-Terminal-Window-Monitor-Device-ESP32-ESP-IDF.png?resize=768%2C76&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 780px) 100vw, 780px\" \/><\/figure><\/div>\n\n\n<p>Rotate the potentiometer knob from one side to the other:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-Read-Potentiometer-adc_oneshot.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-IDF ESP32 Read Potentiometer adc_oneshot\" class=\"wp-image-177127\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-Read-Potentiometer-adc_oneshot.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-Read-Potentiometer-adc_oneshot.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>The terminal should be printing a message saying &#8220;<strong>ADC Value: 0<\/strong>&#8220;, &#8220;<strong>ADC Value: 407<\/strong>&#8220;, &#8220;<strong>ADC Value: 4095<\/strong>&#8221; according to the current position of the potentiometer knob:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"607\" height=\"441\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-Analog-Read-Potentiometer-Value-adc_oneshot-Demonstration.png?resize=607%2C441&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-IDF ESP32 Analog Read Potentiometer Value adc_oneshot Demonstration\" class=\"wp-image-177128\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-Analog-Read-Potentiometer-Value-adc_oneshot-Demonstration.png?w=607&amp;quality=100&amp;strip=all&amp;ssl=1 607w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-Analog-Read-Potentiometer-Value-adc_oneshot-Demonstration.png?resize=300%2C218&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 607px) 100vw, 607px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Example #2: Read ESP32 Analog Inputs with ESP-IDF &#8211; ADC Continuous Mode<\/h2>\n\n\n\n<p>Our example is based on the original <a href=\"https:\/\/raw.githubusercontent.com\/espressif\/esp-idf\/refs\/heads\/master\/examples\/peripherals\/adc\/continuous_read\/main\/continuous_read_main.c\" target=\"_blank\" rel=\"noopener\" title=\"\">documentation<\/a> provided by ESP-IDF. You need to copy the code below to the <em>main.c<\/em> file.<\/p>\n\n\n\n<p>This code is constantly taking new readings of 2 ADC pins that have potentiometers attached to them and prints the values using the continuous mode using the <span class=\"rnthl rntliteral\">adc_continuous_read()<\/span> function:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*  \n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  https:\/\/RandomNerdTutorials.com\/esp-idf-esp32-gpio-analog-adc\/\n  \n  Based on this example: https:\/\/raw.githubusercontent.com\/espressif\/esp-idf\/refs\/heads\/master\/examples\/peripherals\/adc\/continuous_read\/main\/continuous_read_main.c\n*\/\n\n#include &lt;string.h&gt;\n#include &lt;stdio.h&gt;\n#include &lt;esp_log.h&gt;\n#include &lt;freertos\/FreeRTOS.h&gt;\n#include &lt;freertos\/task.h&gt;\n#include &lt;freertos\/semphr.h&gt;\n#include &lt;esp_adc\/adc_continuous.h&gt;\n#include &quot;sdkconfig.h&quot;\n\n\n#define EXAMPLE_ADC_UNIT                    ADC_UNIT_1\n#define _EXAMPLE_ADC_UNIT_STR(unit)         #unit\n#define EXAMPLE_ADC_UNIT_STR(unit)          _EXAMPLE_ADC_UNIT_STR(unit)\n#define EXAMPLE_ADC_CONV_MODE               ADC_CONV_SINGLE_UNIT_1\n#define EXAMPLE_ADC_ATTEN                   ADC_ATTEN_DB_0\n#define EXAMPLE_ADC_BIT_WIDTH               SOC_ADC_DIGI_MAX_BITWIDTH\n\n#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2\n#define EXAMPLE_ADC_OUTPUT_TYPE             ADC_DIGI_OUTPUT_FORMAT_TYPE1\n#define EXAMPLE_ADC_GET_CHANNEL(p_data)     ((p_data)-&gt;type1.channel)\n#define EXAMPLE_ADC_GET_DATA(p_data)        ((p_data)-&gt;type1.data)\n#else\n#define EXAMPLE_ADC_OUTPUT_TYPE             ADC_DIGI_OUTPUT_FORMAT_TYPE2\n#define EXAMPLE_ADC_GET_CHANNEL(p_data)     ((p_data)-&gt;type2.channel)\n#define EXAMPLE_ADC_GET_DATA(p_data)        ((p_data)-&gt;type2.data)\n#endif\n\n#define EXAMPLE_READ_LEN                    256\n\nstatic adc_channel_t channel[2] = {ADC_CHANNEL_7, ADC_CHANNEL_4};\n\nstatic TaskHandle_t s_task_handle;\nstatic const char *TAG = &quot;POTENTIOMETER&quot;;\n\nstatic bool IRAM_ATTR s_conv_done_cb(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data)\n{\n    BaseType_t mustYield = pdFALSE;\n    \/\/ Notify that ADC continuous driver has done enough number of conversions\n    vTaskNotifyGiveFromISR(s_task_handle, &amp;mustYield);\n\n    return (mustYield == pdTRUE);\n}\n\nstatic void continuous_adc_init(adc_channel_t *channel, uint8_t channel_num, adc_continuous_handle_t *out_handle)\n{\n    adc_continuous_handle_t handle = NULL;\n\n    adc_continuous_handle_cfg_t adc_config = {\n        .max_store_buf_size = 1024,\n        .conv_frame_size = EXAMPLE_READ_LEN,\n    };\n    ESP_ERROR_CHECK(adc_continuous_new_handle(&amp;adc_config, &amp;handle));\n\n    adc_continuous_config_t dig_cfg = {\n        .sample_freq_hz = 20 * 1000,\n        .conv_mode = EXAMPLE_ADC_CONV_MODE,\n        .format = EXAMPLE_ADC_OUTPUT_TYPE,\n    };\n\n    adc_digi_pattern_config_t adc_pattern[SOC_ADC_PATT_LEN_MAX] = {0};\n    dig_cfg.pattern_num = channel_num;\n    for (int i = 0; i &lt; channel_num; i++) {\n        adc_pattern[i].atten = ADC_ATTEN_DB_12;\n        adc_pattern[i].channel = channel[i] &amp; 0x7;\n        adc_pattern[i].unit = EXAMPLE_ADC_UNIT;\n        adc_pattern[i].bit_width = ADC_BITWIDTH_12;\n\n        ESP_LOGI(TAG, &quot;adc_pattern[%d].atten is :%&quot;PRIx8, i, adc_pattern[i].atten);\n        ESP_LOGI(TAG, &quot;adc_pattern[%d].channel is :%&quot;PRIx8, i, adc_pattern[i].channel);\n        ESP_LOGI(TAG, &quot;adc_pattern[%d].unit is :%&quot;PRIx8, i, adc_pattern[i].unit);\n    }\n    dig_cfg.adc_pattern = adc_pattern;\n    ESP_ERROR_CHECK(adc_continuous_config(handle, &amp;dig_cfg));\n\n    *out_handle = handle;\n}\n\nvoid app_main(void)\n{\n    esp_err_t ret;\n    uint32_t ret_num = 0;\n    uint8_t result[EXAMPLE_READ_LEN] = {0};\n    memset(result, 0xcc, EXAMPLE_READ_LEN);\n\n    s_task_handle = xTaskGetCurrentTaskHandle();\n\n    adc_continuous_handle_t handle = NULL;\n    continuous_adc_init(channel, sizeof(channel) \/ sizeof(adc_channel_t), &amp;handle);\n\n    adc_continuous_evt_cbs_t cbs = {\n        .on_conv_done = s_conv_done_cb,\n    };\n    ESP_ERROR_CHECK(adc_continuous_register_event_callbacks(handle, &amp;cbs, NULL));\n    ESP_ERROR_CHECK(adc_continuous_start(handle));\n\n    while (1) {\n\n         \/\/ This is to show you the way to use the ADC continuous mode driver event callback.\n         \/\/ This `ulTaskNotifyTake` will block when the data processing in the task is fast.\n         \/\/ However in this example, the data processing (print) is slow, so you barely block here.\n         \/\/ Without using this event callback (to notify this task), you can still just call\n         \/\/ adc_continuous_read() here in a loop, with\/without a certain block timeout.\n        ulTaskNotifyTake(pdTRUE, portMAX_DELAY);\n\n        char unit[] = EXAMPLE_ADC_UNIT_STR(EXAMPLE_ADC_UNIT);\n\n        while (1) {\n            ret = adc_continuous_read(handle, result, EXAMPLE_READ_LEN, &amp;ret_num, 0);\n            if (ret == ESP_OK) {\n                ESP_LOGI(&quot;TASK&quot;, &quot;ret is %x, ret_num is %&quot;PRIu32&quot; bytes&quot;, ret, ret_num);\n                for (int i = 0; i &lt; ret_num; i += SOC_ADC_DIGI_RESULT_BYTES) {\n                    adc_digi_output_data_t *p = (adc_digi_output_data_t*)&amp;result[i];\n                    uint32_t chan_num = EXAMPLE_ADC_GET_CHANNEL(p);\n                    uint32_t data = EXAMPLE_ADC_GET_DATA(p);\n                    \/\/ Check the channel number validation, the data is invalid if the channel num exceed the maximum channel \n                    if (chan_num &lt; SOC_ADC_CHANNEL_NUM(EXAMPLE_ADC_UNIT)) {\n                        \/\/ESP_LOGI(TAG, &quot;Unit: %s, Channel: %&quot;PRIu32&quot;, Value: %&quot;PRIx32, unit, chan_num, data);\n                        ESP_LOGI(TAG, &quot;Unit: %s, Channel: %&quot;PRIu32&quot;, Value: %lu&quot;, unit, chan_num, data);\n                    } else {\n                        ESP_LOGW(TAG, &quot;Invalid data [%s_%&quot;PRIu32&quot;_%&quot;PRIx32&quot;]&quot;, unit, chan_num, data);\n                    }\n                }\n                \/\/  Because printing is slow, so every time you call `ulTaskNotifyTake`, it will immediately return.\n                \/\/  To avoid a task watchdog timeout, add a delay here. When you replace the way you process the data,\n                \/\/  usually you don't need this delay (as this task will block for a while).\n                \n                vTaskDelay(1);\n            } else if (ret == ESP_ERR_TIMEOUT) {\n                \/\/ We try to read `EXAMPLE_READ_LEN` until API returns timeout, which means there's no available data\n                break;\n            }\n        }\n    }\n    ESP_ERROR_CHECK(adc_continuous_stop(handle));\n    ESP_ERROR_CHECK(adc_continuous_deinit(handle));\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP-IDF\/analog_input\/adc_continuous.c\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Code Overview<\/h3>\n\n\n\n<p>This ESP-IDF code sets up an ESP32 to continuously read analog signals from two ADC channels using the ADC in continuous mode (with <span class=\"rnthl rntliteral\">adc_continuous_read()<\/span> function).<\/p>\n\n\n\n<p>In this section, we&#8217;ll take a look quick overview of how the code works, but we won&#8217;t explain it line by line.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Start by configuring the ADC in continuous mode to sample analog signals from two ADC channels on the ADC1 unit at 20 kHz;<\/li>\n\n\n\n<li>The ADC driver in continuous mode stores results in an internal buffer;<\/li>\n\n\n\n<li>When you collect the readings, it uses FreeRTOS tasks and notifications to handle ADC data;<\/li>\n\n\n\n<li>The process of sampling and logging ADC readings in the Terminal repeats indefinitely.<\/li>\n<\/ul>\n\n\n\n<p>This code is only compatible with ADC1 pins. It&#8217;s slightly more complex to implement compared to the One-Shot mode, because it requires DMA configuration. This code can be used in an application that requires real-time fast continuous analog readings (like audio sampling).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematic Diagram<\/h3>\n\n\n\n<p>Here\u2019s a list of the parts you need to build the circuit:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\" rel=\"noreferrer noopener\">ESP32<\/a>&nbsp;(read&nbsp;<a href=\"https:\/\/makeradvisor.com\/esp32-development-boards-review-comparison\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best ESP32 Dev Boards<\/a>)<\/li>\n\n\n\n<li>2x <a href=\"https:\/\/makeradvisor.com\/tools\/potentiometer-assortment-kit\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Potentiometers<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noreferrer noopener\">Breadboard<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noreferrer noopener\">Jumper wires<\/a><\/li>\n<\/ul>\n\n\n\n<p>Connect one potentiometer to <span class=\"rnthl rntcblue\">ADC1 Channel 7<\/span> and the other potentiometer to <span class=\"rnthl rntcgreen\">ADC1 Channel 4<\/span> as shown in the schematic diagram below for a board with <a href=\"https:\/\/randomnerdtutorials.com\/esp32-s3-devkitc-pinout-guide\/\">ESP32-S3 chip<\/a>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"813\" height=\"897\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP32-S3-Two-Potentiometers-Wiring-Circuit-Analog-Input-ADC.jpg?resize=813%2C897&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-S3 Two Potentiometers Wiring Circuit Analog Input ADC\" class=\"wp-image-177117\" style=\"width:584px;height:auto\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP32-S3-Two-Potentiometers-Wiring-Circuit-Analog-Input-ADC.jpg?w=813&amp;quality=100&amp;strip=all&amp;ssl=1 813w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP32-S3-Two-Potentiometers-Wiring-Circuit-Analog-Input-ADC.jpg?resize=272%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 272w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP32-S3-Two-Potentiometers-Wiring-Circuit-Analog-Input-ADC.jpg?resize=768%2C847&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 813px) 100vw, 813px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>If you followed all the steps, the example should be running successfully on your board. Open your Terminal window \u2014 click the &#8220;<strong>Monitor Device<\/strong>&#8221; tool that is illustrated with a screen icon.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"780\" height=\"77\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Open-Terminal-Window-Monitor-Device-ESP32-ESP-IDF.png?resize=780%2C77&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"VS Code Open Terminal Window Monitor Device ESP32 ESP-IDF\" class=\"wp-image-170157\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Open-Terminal-Window-Monitor-Device-ESP32-ESP-IDF.png?w=780&amp;quality=100&amp;strip=all&amp;ssl=1 780w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Open-Terminal-Window-Monitor-Device-ESP32-ESP-IDF.png?resize=300%2C30&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/05\/VS-Code-Open-Terminal-Window-Monitor-Device-ESP32-ESP-IDF.png?resize=768%2C76&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 780px) 100vw, 780px\" \/><\/figure><\/div>\n\n\n<p>Rotate the two potentiometer knobs from one side to the other side:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-Read-Potentiometer-adc_continuous.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-IDF ESP32 Read Potentiometer adc_continuous\" class=\"wp-image-177126\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-Read-Potentiometer-adc_continuous.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-Read-Potentiometer-adc_continuous.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>The terminal window should be printing a similar message saying &#8220;<strong>POTENTIOMETER: Unit: ADC_Unit_1, Channel 7, Value: 4095<\/strong>&#8221; according to the current position of the potentiometer knob:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"682\" height=\"439\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-Analog-Read-Two-Potentiometers-Values-with-adc_continuous-Demonstration.png?resize=682%2C439&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-IDF ESP32 Analog Read Two Potentiometers Values with adc_continuous Demonstration\" class=\"wp-image-177125\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-Analog-Read-Two-Potentiometers-Values-with-adc_continuous-Demonstration.png?w=682&amp;quality=100&amp;strip=all&amp;ssl=1 682w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-Analog-Read-Two-Potentiometers-Values-with-adc_continuous-Demonstration.png?resize=300%2C193&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 682px) 100vw, 682px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you learned how to program the ESP32 with the ESP-IDF framework using VS Code to read the voltage of the GPIO using the ADC. In the next guide, we&#8217;ll cover ESP-IDF GPIO Interrupts.<\/p>\n\n\n\n<p>Other ESP-IDF guides:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/programming-esp32-esp-idf-vs-code\/\">Programming ESP32 with ESP-IDF using VS Code \u2013 Getting Started Guide<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp-idf-esp32-blink-led\/\">ESP-IDF: ESP32 Blink LED Example (VS Code)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp-idf-esp32-gpio-pwm-ledc\/\">ESP-IDF: ESP32 GPIO PWM with LEDC (Control LED Brightness)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp-idf-esp32-gpio-inputs\/\">ESP-IDF: ESP32 GPIO \u2013 Read Digital Inputs<\/a><\/li>\n<\/ul>\n\n\n\n<p>Meanwhile, you can check our ESP32 resources (with Arduino IDE) to learn more about the ESP32 board:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-cam-projects-ebook\/\">Learn ESP32 with Arduino IDE (eBook)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">More ESP32 Projects and Tutorials\u2026<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, you&#8217;ll learn how to set and read the ESP32 board&#8217;s GPIO pins as ADC (Analog to Digital Converter) with ESP-IDF (Espressif IoT Development Framework). The ESP32 is &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP-IDF: ESP32 GPIO &#8211; Read Analog Input (ADC &#8211; Analog to Digital Converter)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp-idf-esp32-gpio-analog-adc\/#more-175829\" aria-label=\"Read more about ESP-IDF: ESP32 GPIO &#8211; Read Analog Input (ADC &#8211; Analog to Digital Converter)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":177115,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[327,328,264],"tags":[],"class_list":["post-175829","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp-idf","category-esp32-esp-idf","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/09\/ESP-IDF-ESP32-GPIO-Read-Analog-Input-ADC-Analog-to-Digital-Converter.jpg?fit=1920%2C1080&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/175829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=175829"}],"version-history":[{"count":13,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/175829\/revisions"}],"predecessor-version":[{"id":187424,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/175829\/revisions\/187424"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/177115"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=175829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=175829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=175829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}