Go back

Read Analog Sensors on Raspberry Pi Pico with Velxio

Introduction

Welcome to another hands-on tutorial on the Velxio blog! Today, we’re diving into the Raspberry Pi Pico’s ADC (Analog-to-Digital Converter). The Pico is a powerful little board, and one of its coolest features is the ability to read analog voltages—perfect for sensors, potentiometers, and more. In this example, we’ll read three external analog signals from potentiometers and also grab the internal temperature sensor value. All of this runs right in your browser with Velxio’s SPICE-accurate simulation.

Circuit diagram of pico-adc-read on the Velxio simulator canvas

Circuit Walkthrough

Let’s look at the circuit. We have a Raspberry Pi Pico (the Nano RP2040 variant in Velxio) connected to two potentiometers and an LED.

Components

Wiring Details

Note: The Pico’s ADC pins are 3.3V tolerant, so we use the 3.3V supply. The potentiometers act as voltage dividers, giving a variable voltage from 0 to 3.3V at their wiper.

Code Walkthrough

Now let’s examine the code. It’s written in Arduino-style C++ for the Raspberry Pi Pico.

// Raspberry Pi Pico — ADC Read Test
// Reads analog values from A0-A2 (GPIO26-28) and the internal temp sensor

void setup() {
  Serial.begin(115200);
  delay(500);
  Serial.println("=== Pico ADC Read ===");
  Serial.println("A0=GP26  A1=GP27  A2=GP28  Temp=internal");
  Serial.println("12-bit resolution (0-4095), 3.3V ref");
  Serial.println();

  analogReadResolution(12);
}

void loop() {
  int a0 = analogRead(A0);
  int a1 = analogRead(A1);
  int a2 = analogRead(A2);

  // Internal temperature sensor on channel 4
  // T = 27 - (V - 0.706) / 0.001721
  int tempRaw = analogRead(A3); // Channel 4 mapped to A3 by Pico core
  float voltage = tempRaw * 3.3f / 4095.0f;
  float tempC = 27.0f - (voltage - 0.706f) / 0.001721f;

  Serial.print("A0: "); Serial.print(a0);
  Serial.print("  A1: "); Serial.print(a1);
  Serial.print("  A2: "); Serial.print(a2);
  Serial.print("  Temp: "); Serial.print(tempC, 1); Serial.println(" C");

  delay(1000);
}

Key Points

Key Concepts

Common Pitfalls & Debugging Tips

Suggested Extensions

Try It Yourself!

Ready to experiment? Open the live example in Velxio and start tweaking the circuit or code. Click the link below to launch the simulation right in your browser.

Launch the Pico ADC Read Example on Velxio

Happy tinkering!


Share this post on:
David Montero

Written by

David Montero

Creator of Velxio, the open-source circuit and Arduino simulator.

GitHub velxio.dev

Related posts


Previous Post
Pico Multi-Protocol Demo: Serial, I2C, SPI & ADC on RP2040
Next Post
Pico SPI Loopback: Test Your RP2040's Serial Communication