{"id":85752,"date":"2019-05-31T13:53:42","date_gmt":"2019-05-31T13:53:42","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=85752"},"modified":"2020-11-11T10:32:45","modified_gmt":"2020-11-11T10:32:45","slug":"esp32-adc-analog-read-arduino-ide","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-adc-analog-read-arduino-ide\/","title":{"rendered":"ESP32 ADC \u2013 Read Analog Values with Arduino IDE"},"content":{"rendered":"\n<p>This article shows how to read analog inputs with the ESP32 using Arduino IDE. Analog reading is useful to read values from variable resistors like potentiometers, or analog sensors.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ESP32-Analog-Read-Potentiometer-Arduino-IDE.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ADC Read Analog Values with Arduino IDE\" class=\"wp-image-85804\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ESP32-Analog-Read-Potentiometer-Arduino-IDE.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ESP32-Analog-Read-Potentiometer-Arduino-IDE.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ESP32-Analog-Read-Potentiometer-Arduino-IDE.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ESP32-Analog-Read-Potentiometer-Arduino-IDE.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<p class=\"rntbox rntclgreen\">Reading analog inputs with the ESP32 is as easy as using the <span class=\"rnthl rntliteral\">analogRead(GPIO)<\/span> function, that accepts as argument, the GPIO you want to read.<\/p>\n\n\n\n<p>We also have other tutorials on how to use analog pins with ESP board:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-adc-reading-analog-values-with-nodemcu\/\">ESP8266 ADC \u2013 Read Analog Values with Arduino IDE, MicroPython and Lua<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-analog-readings-micropython\/\">ESP32 Analog Readings with MicroPython<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Watch the Video <\/h2>\n\n\n\n<p>You can watch the video tutorial or keep reading this page for the written instructions. <\/p>\n\n\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/doEY6yi9src?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Analog Inputs (ADC)<\/h2>\n\n\n\n<p>Reading an analog value with the ESP32 means you can measure varying voltage levels between 0 V and 3.3 V. <\/p>\n\n\n\n<p>The voltage measured is then assigned to a value between 0 and 4095, in which 0 V corresponds to 0, and 3.3 V corresponds to 4095. Any voltage between 0 V and 3.3 V will be given the corresponding value in between.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"768\" height=\"284\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/voltage-levels-es32.jpg?resize=768%2C284&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ADC Analog Read Inputs Range Value\" class=\"wp-image-85758\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/voltage-levels-es32.jpg?w=768&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/voltage-levels-es32.jpg?resize=300%2C111&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">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\n<div class=\"wp-block-image\"><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><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\n<p>This behavior means that your ESP32 is not able to distinguish 3.3 V from 3.2 V. You\u2019ll get the same value for both voltages: 4095. <\/p>\n\n\n\n<p>The same happens for very low voltage values: for 0 V and 0.1 V 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<p>There\u2019s a&nbsp;discussion on <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/github.com\/espressif\/arduino-esp32\/issues\/92\" target=\"_blank\">GitHub<\/a> about this subject.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">analogRead() Function<\/h2>\n\n\n\n<p>Reading an analog input with the ESP32 using the Arduino IDE is as simple as using the&nbsp;<span class=\"rnthl rntliteral\">analogRead()<\/span> function. It accepts as argument, the GPIO you want to read:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>analogRead(GPIO);<\/code><\/pre>\n\n\n\n<p>The ESP32 supports measurements in 18 different channels. Only 15 are available in the <a href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"DEVKIT V1 DOIT (opens in a new tab)\">DEVKIT V1 DOIT<\/a> board (version with 30 GPIOs). <\/p>\n\n\n\n<p>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\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><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\" \/><\/figure><\/div>\n\n\n\n<p>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>These analog input pins have 12-bit resolution. This means that when you read an analog input, its range may vary from 0 to 4095.<\/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\">Other Useful Functions<\/h2>\n\n\n\n<p>There are other more advanced functions to use with the ADC pins that can be useful in other projects.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><span class=\"rnthl rntliteral\">analogReadResolution(resolution)<\/span>: set the sample bits and resolution. It can be a value between 9 (0 &#8211; 511) and 12 bits (0 &#8211; 4095). Default is 12-bit resolution.<\/li><li><span class=\"rnthl rntliteral\">analogSetWidth(width)<\/span>: set the sample bits and resolution. It can be a value between 9 (0 &#8211; 511) and 12 bits (0 &#8211; 4095). Default is 12-bit resolution. <\/li><li><span class=\"rnthl rntliteral\">analogSetCycles(cycles)<\/span>: set the number of cycles per sample. Default is 8. Range: 1 to 255.<\/li><li><span class=\"rnthl rntliteral\">analogSetSamples(samples)<\/span>: set the number of samples in the range. Default is 1 sample. It has an effect of increasing sensitivity.<\/li><li><span class=\"rnthl rntliteral\">analogSetClockDiv(attenuation)<\/span>: set the divider for the ADC clock. Default is 1. Range: 1 to 255.<\/li><li><span class=\"rnthl rntliteral\">analogSetAttenuation(attenuation)<\/span>: sets the input attenuation for all ADC pins. Default is <span class=\"rnthl rntliteral\">ADC_11db<\/span>. Accepted values:<ul><li><span class=\"rnthl rntliteral\">ADC_0db<\/span>: sets no attenuation. ADC can measure up to approximately 800 mV (1V input = ADC reading of 1088).  <\/li><li><span class=\"rnthl rntliteral\">ADC_2_5db<\/span>: The input voltage of ADC will be attenuated, extending the range of measurement to up to approx. 1100 mV. (1V input = ADC reading of 3722).  <\/li><li><span class=\"rnthl rntliteral\">ADC_6db<\/span>: The input voltage of ADC will be attenuated, extending the range of measurement to up to approx. 1350 mV. (1V input = ADC reading of 3033). <\/li><li><span class=\"rnthl rntliteral\">ADC_11db<\/span>: The input voltage of ADC will be attenuated, extending the range of measurement to up to approx. 2600 mV. (1V input = ADC reading of 1575).<\/li><\/ul><\/li><li><span class=\"rnthl rntliteral\">analogSetPinAttenuation(pin, attenuation)<\/span>: sets the input attenuation for the specified pin. The default is <span class=\"rnthl rntliteral\">ADC_11db<\/span>. Attenuation values are the same from previous function.<\/li><li><span class=\"rnthl rntliteral\">adcAttachPin(pin)<\/span>: Attach a pin to ADC (also clears any other analog mode that could be on). Returns TRUE or FALSE result.<\/li><li><span class=\"rnthl rntliteral\">adcStart(pin<\/span>), <span class=\"rnthl rntliteral\">adcBusy(pin)<\/span> and <span class=\"rnthl rntliteral\">resultadcEnd(pin)<\/span>: starts an ADC convertion on attached pin&#8217;s bus. Check if conversion on the pin&#8217;s ADC bus is currently running (returns TRUE or FALSE). Get the result of the conversion: returns 16-bit integer.<\/li><\/ul>\n\n\n\n<p>There is a very good video explaining these functions that you can <a rel=\"noreferrer noopener\" aria-label=\"watch here (opens in a new tab)\" href=\"https:\/\/www.youtube.com\/watch?v=RlKMJknsNpo&amp;t=145s\" target=\"_blank\">watch here<\/a>. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Read Analog Values from a Potentiometer with ESP32<\/h2>\n\n\n\n<p>To see how everything ties together, we&#8217;ll make a simple example to read an analog value from a potentiometer.<\/p>\n\n\n\n<p>For this example, you need the following parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\">ESP32 DOIT DEVKIT V1 Board<\/a> (read <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/esp32-development-boards-review-comparison\/\" target=\"_blank\">Best ESP32 development boards<\/a>)<\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/potentiometer-assortment-kit\/\" target=\"_blank\">Potentiometer<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\">Breadboard<\/a><\/li><li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Jumper wires<\/a><\/li><\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematic<\/h3>\n\n\n\n<p>Wire a potentiometer to your ESP32. The potentiometer middle  pin should be connected to GPIO 34. You can use the following schematic diagram as a reference.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/Analog_Input_Potentiometer-700px.jpg?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1146\" height=\"618\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/Analog_Input_Potentiometer-700px.jpg?resize=1146%2C618&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Read value from Potentiometer ESP32 Arduino IDE\" class=\"wp-image-85755\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/Analog_Input_Potentiometer-700px.jpg?w=1146&amp;quality=100&amp;strip=all&amp;ssl=1 1146w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/Analog_Input_Potentiometer-700px.jpg?resize=300%2C162&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/Analog_Input_Potentiometer-700px.jpg?resize=768%2C414&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/Analog_Input_Potentiometer-700px.jpg?resize=1024%2C552&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1146px) 100vw, 1146px\" \/><\/a><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Code<\/h3>\n\n\n\n<p>We\u2019ll program the ESP32 using Arduino IDE, so make sure you have the ESP32 add-on installed before proceeding:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><a rel=\"noreferrer noopener\" href=\"https:\/\/randomnerdtutorials.com\/installing-the-esp32-board-in-arduino-ide-windows-instructions\/\" target=\"_blank\">Windows<\/a><\/strong><a rel=\"noreferrer noopener\" href=\"https:\/\/randomnerdtutorials.com\/installing-the-esp32-board-in-arduino-ide-windows-instructions\/\" target=\"_blank\">&nbsp;instructions \u2013 ESP32 Board in Arduino IDE<\/a><\/li><li><strong><a rel=\"noreferrer noopener\" href=\"https:\/\/randomnerdtutorials.com\/installing-the-esp32-board-in-arduino-ide-mac-and-linux-instructions\/\" target=\"_blank\">Mac and Linux<\/a><\/strong><a rel=\"noreferrer noopener\" href=\"https:\/\/randomnerdtutorials.com\/installing-the-esp32-board-in-arduino-ide-mac-and-linux-instructions\/\" target=\"_blank\">&nbsp;instructions \u2013 ESP32 Board in Arduino IDE<\/a><\/li><\/ul>\n\n\n\n<p>Open your Arduino IDE and copy the following code.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/\/ Potentiometer is connected to GPIO 34 (Analog ADC1_CH6) \nconst int potPin = 34;\n\n\/\/ variable for storing the potentiometer value\nint potValue = 0;\n\nvoid setup() {\n  Serial.begin(115200);\n  delay(1000);\n}\n\nvoid loop() {\n  \/\/ Reading potentiometer value\n  potValue = analogRead(potPin);\n  Serial.println(potValue);\n  delay(500);\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/ESP32-Course\/raw\/master\/code\/Analog_Input_Pot\/Analog_Input_Pot.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>This code simply reads the values from the potentiometer and prints those values in the Serial Monitor.<\/p>\n\n\n\n<p>In the code, you start by defining the GPIO the potentiometer is connected to. In this example, <span class=\"rnthl rntcyellow\">GPIO 34<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const int potPin = 34;<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize a serial communication at a baud rate of 115200. <\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, use the <span class=\"rnthl rntliteral\">analogRead()<\/span>function to read the analog input from the <span class=\"rnthl rntliteral\">potPin<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>potValue = analogRead(potPin);<\/code><\/pre>\n\n\n\n<p>Finally, print the values read from the potentiometer in the serial monitor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.println(potValue);<\/code><\/pre>\n\n\n\n<p>Upload the code provided to your ESP32. Make sure you have the right board and COM port selected in the Tools menu.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Testing the Example<\/h3>\n\n\n\n<p>After uploading the code and pressing the ESP32 reset button, open the Serial Monitor at a baud rate of 115200. Rotate the potentiometer and see the values changing.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"552\" height=\"351\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/analog-input-rotate-pot.png?resize=552%2C351&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Read potentiometer ESP32 analogRead\" class=\"wp-image-85764\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/analog-input-rotate-pot.png?w=552&amp;quality=100&amp;strip=all&amp;ssl=1 552w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/analog-input-rotate-pot.png?resize=300%2C191&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 552px) 100vw, 552px\" \/><\/figure><\/div>\n\n\n\n<p>The maximum value you&#8217;ll get is 4095 and the minimum value is 0.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"609\" height=\"427\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/analog-input-serial-monitor.png?resize=609%2C427&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Read potentiometer ESP32 analogRead serial monitor Arduino IDE demonstration\" class=\"wp-image-85765\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/analog-input-serial-monitor.png?w=609&amp;quality=100&amp;strip=all&amp;ssl=1 609w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/analog-input-serial-monitor.png?resize=300%2C210&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 609px) 100vw, 609px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this article you&#8217;ve learned how to read analog inputs using the ESP32 with the Arduino IDE. In summary:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The ESP32 DEVKIT V1 DOIT board (version with 30 pins) has 15 ADC pins you can use to read analog inputs.<\/li><li>These pins have a resolution of 12 bits, which means you can get values from 0 to 4095.<\/li><li>To read a value in the Arduino IDE, you simply use the <span class=\"rnthl rntliteral\">analogRead()<\/span> function.<\/li><li>The ESP32 ADC pins don\u2019t have a linear behavior. You\u2019ll probably won\u2019t be able to distinguish between 0 and 0.1V, or between 3.2 and 3.3V. You need to keep that in mind when using the ADC pins.<\/li><\/ul>\n\n\n\n<p>We hope you&#8217;ve find this short guide useful. If you want to learn more about the ESP32, enroll in our course: <a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE<\/a>. <\/p>\n\n\n\n<p>Other ESP32 guides that you may also like:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-ssd1306-oled-display-arduino-ide\/\">ESP32 OLED Display with Arduino IDE<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-dht11-dht22-temperature-humidity-sensor-arduino-ide\/\">ESP32 with DHT Temperature and Humidity Sensor using Arduino IDE<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-dht11-dht22-temperature-humidity-web-server-arduino-ide\/\">ESP32 Web Server with DHT readings<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">20+ ESP32 Projects and Tutorials<\/a><\/li><\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article shows how to read analog inputs with the ESP32 using Arduino IDE. Analog reading is useful to read values from variable resistors like potentiometers, or analog sensors. Reading &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32 ADC \u2013 Read Analog Values with Arduino IDE\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-adc-analog-read-arduino-ide\/#more-85752\" aria-label=\"Read more about ESP32 ADC \u2013 Read Analog Values with Arduino IDE\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":85804,"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":[281,276,277,299,264],"tags":[],"class_list":["post-85752","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32-project","category-esp32","category-esp32-arduino-ide","category-0-esp32","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ESP32-Analog-Read-Potentiometer-Arduino-IDE.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/85752","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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=85752"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/85752\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/85804"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=85752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=85752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=85752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}