Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » How to use ADC in Raspberry Pi Pico | ADC Example Code
Raspberry Pi Raspberry Pi Pico Projects

How to use ADC in Raspberry Pi Pico | ADC Example Code

Mamtaz AlamBy Mamtaz AlamUpdated:November 28, 202410 Comments5 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
ADC Example Raspberry Pi Pico
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this tutorial, we will learn how to use ADC in Raspberry Pi Pico with ADC Example Code using MicroPython. An analog to digital converter (ADC) is a circuit that converts a continuous voltage value (analog) to a binary value (digital) that can be understood by a digital device which could then be used for digital computation.

The Raspberry Pi Pico is built using an RP2040 microcontroller. The board exposes 26 multi-function GPIO pins from a total of 36 GPIO pins. Out of 36 GPIO Pins, there are 4 ADC pins but only 3 are usable.

The ADC in Raspberry Pi Pico is 12bits, which is 4 times better than the 10 bits ADC of the Arduino. We will write a MicroPython code to learn how we can use the ADC pin value with any analog sensors. A potentiometer is the best tool to vary the input Analog Voltage. But before jumping directly into the ADC guide, it is recommended to go through Raspberry Pi Pico Getting Started Tutorial.



What is Analog to Digital Converter (ADC)?

An Analog to Digital Converter (ADC) is a very useful feature that converts an analog voltage on a pin to a digital number. By converting from the analog world to the digital world, we can begin to use electronics to interface with the analog world around us.

In real-life applications, ADC is a system that converts an analog signal, such as a sound picked up by a microphone or light entering a digital camera, into a digital signal. An ADC may also provide an isolated measurement such as an electronic device that converts an input analog voltage or current to a digital number representing the magnitude of the voltage or current.

The ADC is perfect for these sensors. With the ADC, you can sense environmental parameters like light, sound, distance, gravity, acceleration, rotation, smell, gases, other particles.


How does an ADC work in a Microcontroller?

Most microcontrollers nowadays have built-in ADC converters. It is also possible to connect an external ADC converter to any type of microcontroller. ADC converters are usually 10 or 12 bits, having 1024 to 4096 quantization levels. A 16 bits ADC has 65536 quantization levels. A Raspberry Pi Pico has 12 Bits ADC with a quantization level of 4096.


The ADC conversion process must be started by the user program and it may take several hundreds of microseconds for a conversion to complete. ADC converters usually generate interrupts when a conversion is complete so that the user program can read the converted data as quickly as possible.


ADC in Raspberry Pi Pico

RPI Pico Pins

The Raspberry Pi Pico supports four 12-bit SAR based analog to digital converters. Out of the 4, you can only use 3 analog channels. The 4th analog channel is internally connected to the internal temperature sensor. You can measure the temperature using build-in temperature by reading the analog value of ADC4. The following table shows that the input signal for ADC0, ADC1, and ADC2 can be connected with GP26, GP27 & GP28 pins respectively.

ADC Module GPIO Pins
ADC0 GP26
ADC1 GP27
ADC2 GP28

 

You can perform the A/D conversion in polling, interrupt & FIFO with DMA mode. The ADC conversion speed per sample is 2μs that is 500kS/s. The RP2040 microcontroller operates on a 48MHZ clock frequency which comes from USB PLL. So, its ADC takes a 96 CPU clock cycle to perform one conversion. Therefore, the sampling frequency is (96 x 1 / 48MHz) = 2 μs per sample (500kS/s).

You may use a ADC Calculator to manually calculate the ADC Value.



Raspberry Pi Pico ADC Example Code

Now let us learn how to use ADC of Raspberry Pi Pico. We will use a 10K Potentiometer to vary the Analog input voltage. We will map the analog voltage from 0 to 3.3V with 12 Bit or 16 Bit ADC. The connection diagram is given below.

Raspberry Pi Pico ADC Example

Connect Pin 1 & Pin 3 of Potentiometer to 3.3V Pin & GND Pin of the Raspberry Pi Pico. Connect the Pin 2 of the Potentiometer to GP28 of Raspberry Pie Pico.

Now it’s time to write a code and check the Analog Reading. To do that you can use Thonny IDE or go with uPyCraft IDE. Copy the following code and hit ‘Download & Run Button‘.

1
2
3
4
5
6
7
8
9
import machine
import utime
 
analog_value = machine.ADC(28)
 
while True:
    reading = analog_value.read_u16()    
    print("ADC: ",reading)
    utime.sleep(0.2)


In this code part, I define the ADC input connected at pin 28. Then to create an infinite loop I make a while true. then I read the ADC value with the read u16 function. Then using print I can show the value on the shell monitor.

When you rotate the potentiometer and the value goes from 0 to 65536 and that’s weird because the value should go from 0 to 4096. This is supposed to be a 12bit ADC and not 16bit. Anyway, that’s how we can read analog values with the ADC on the raspberry Pi Pico.

If you want to add more analog pins to the Raspberry Pi Pico and read the ADC value more precisely, you may use the ADS1115 16-Bit ADC Module for your projects. You can follow the following Guide here:

ADS1115 16-Bit ADC Module with Raspberry Pi Pico


Video Tutorial & Guide

Raspberry Pi Pico Complete Guide| Pinout+Features+ADC+I2C+OLED+Internal Temperature Sensor+DHT11
Watch this video on YouTube.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleHow to use I2C Pins in Raspberry Pi Pico | I2C Scanner Code
Next Article Interfacing SSD1306 OLED Display with Raspberry Pi Pico

Related Posts

ADXL375 Accelerometer with Raspberry Pi Pico & MicroPython

ADXL375 Accelerometer with Raspberry Pi Pico & MicroPython

Updated:July 24, 2025
Interface BMI160 with Raspberry Pi Pico & MicroPython

Interface BMI160 with Raspberry Pi Pico & MicroPython

Updated:February 2, 20253K
Shift Register 74HC595 with Raspberry Pi Pico & MicroPython

Shift Register 74HC595 with Raspberry Pi Pico & MicroPython

Updated:February 2, 202513K
Interfacing XBee Module with Raspberry Pi Pico & MicroPython

Interfacing XBee Module with Raspberry Pi Pico & MicroPython

Updated:February 2, 20253K
Modbus RTU with Raspberry Pi Pico & Micropython

Modbus RTU with Raspberry Pi Pico & MicroPython

Updated:February 2, 20258K
Fever Detector with MLX90640 & OpenCV Raspberry Pi

Thermal Fever Detector with MLX90640 & OpenCV Raspberry Pi

Updated:February 2, 20256K
View 10 Comments

10 Comments

  1. D on May 5, 2021 7:05 PM

    Haven’t tested it yet, but documentation is describing ADC3 input as a monitor of VSYS divider.

    Citation:
    VSYS is the main system ‘input voltage’ and feeds the RT6150 buck-boost SMPS, which generates a fixed 3.3V outputfor the RP2040 device and its IO (and can be used to power external circuitry). VSYS is R-C filtered and divided by 3 (byR5, R6 and C3 in the Pico schematic) and can be monitored on ADC channel 3. This can be used for example as a crudebattery voltage monitor.

    Reply
  2. Lyle on May 21, 2021 10:53 AM

    From the resistor make a watering kit with capacitive moisture sensor (using adc) and output to pump (3-5v). Could also incorporate the temp sensor reading. Could you do this, would you use a relay or mofset, to drive the pump?

    Reply
  3. Dave on July 16, 2021 5:29 PM

    Why do you go through an in depth explanation of the ADC down to the clock cycle level and then completely blow off the 16 bit result in your program example?

    Reply
  4. MaffooClock on October 12, 2021 2:00 AM

    👆🏻 THIS

    Reply
  5. MihaiT on February 22, 2022 7:45 PM

    Agreed, it’s a bit lazy on his part. Anyway, from https://docs.micropython.org/en/latest/library/machine.ADC.html is seems it’s the analog_value.read_u16() that does a conversion internally.

    STATIC uint16_t adc_config_and_read_u16(uint32_t channel) {
    adc_select_input(channel);
    uint32_t raw = adc_read();
    const uint32_t bits = 12;
    // Scale raw reading to 16 bit value using a Taylor expansion (for 8
    return raw > (2 * bits – 16);
    }

    Reply
  6. Alexander on October 31, 2022 3:45 AM

    “The Raspberry Pi Pico supports four 12-bit SAR based analog to digital converters.”

    NO, the RPi Pico has one ADC, with five channels that can be connected and read in a round robin fashion. Channels 3 and 4 (that is, the fourth and fifth cannels, channel 0 being the first) are reserved for the VSYS (Pi Pico specific) and the internal temperature sensor (fixed on the RP2040 chip)

    Reply
  7. f on January 29, 2023 7:18 PM

    because he doesn’t know what he’s talking about
    ADC is useless if you don’t map digital readings to voltage values, it’s not really a step you can skip in a guide

    Reply
    • Jim on February 16, 2024 1:04 PM

      ADC is NOT useless if you don’t map digital readings to voltage values, especially, when all you care about is the voltage as a percentage of the max voltage available. This is the case with linear actuators – after calibrating by getting the min/max readings from the feedback line, you can then map any input value to a percent of extension. Not knowing the voltage is an advantage because … you don’t need to know the voltage.

      Reply
  8. Rick Sanchez on April 22, 2023 9:15 AM

    That was very important information for my purpose. Thank you!

    Reply
  9. Jim on February 16, 2024 12:57 PM

    Specifically: “scaled such that the minimum value is 0 and the maximum value is 65535′

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • MAX30102 & Arduino: Heart Rate + Blood Oxygen Monitoring
    MAX30102 & Arduino: Heart Rate + Blood Oxygen Monitoring
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.