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 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
- Raspberry Pi Pico (Nano RP2040): The brain of the operation.
- Potentiometer A0 (pot-a0): Connected to GPIO26 (A0). Its wiper (SIG) goes to A0, VCC to 3.3V, and GND to ground.
- Potentiometer A1 (pot-a1): Connected to GPIO27 (A1). Same wiring: SIG to A1, VCC to 3.3V, GND to ground.
- Red LED (led-temp): Connected to GPIO2 (D2) through a current-limiting resistor (internal to the LED component). The anode (A) goes to D2, cathode (C) to ground.
Wiring Details
- A0 (GP26) is connected to the SIG pin of pot-a0 via a blue wire (
#4488ff). - A1 (GP27) is connected to the SIG pin of pot-a1 via a green wire (
#44cc44). - D2 (GP2) is connected to the anode of the red LED via a red wire (
#ff4444). - Both potentiometers share the 3.3V rail (red wires) and ground (black wires) from the Pico.
- The LED’s cathode is connected to ground.
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
analogReadResolution(12): Sets the ADC to 12-bit resolution (0-4095). The Pico’s ADC is 12-bit by default, but it’s good practice to set it explicitly.analogRead(A0): Reads the voltage on GPIO26 (A0). The Pico core maps A0 to GPIO26, A1 to GPIO27, A2 to GPIO28, and A3 to the internal temperature sensor (channel 4).- Temperature Calculation: The internal sensor outputs a voltage that varies with temperature. The formula
T = 27 - (V - 0.706) / 0.001721converts the voltage to degrees Celsius. The constant 0.706V is the voltage at 27°C, and 0.001721 V/°C is the slope. - Serial Output: The results are printed every second.
Key Concepts
- ADC Resolution: The Pico’s ADC is 12-bit, meaning it can represent 4096 discrete voltage levels (0 to 4095). The reference voltage is 3.3V, so each step is about 0.8 mV.
- Analog vs Digital: Potentiometers provide a continuous voltage; the ADC converts it to a digital number.
- Internal Temperature Sensor: A handy feature for monitoring the chip’s temperature without external components.
- Voltage Divider: The potentiometer acts as a voltage divider, giving a fraction of the supply voltage.
Common Pitfalls & Debugging Tips
- Wrong Pin Mapping: Remember that A0 is GPIO26, A1 is GPIO27, A2 is GPIO28, and the internal temp sensor is accessed via A3 (channel 4).
- Floating Pins: If a potentiometer wiper is disconnected, the ADC reading may be random. Always ensure a solid connection.
- Serial Monitor: Make sure the baud rate matches (115200). In Velxio, open the Serial Monitor from the editor toolbar.
- LED Not Blinking: The LED in this example is not controlled by code; it’s just wired. To blink it, you’d need to add
digitalWrite(D2, HIGH)anddelay()calls.
Suggested Extensions
- Add a Third Potentiometer: Wire a third pot to GPIO28 (A2) and read it in the code.
- Control the LED: Use the temperature reading to turn on the LED when it’s above a threshold.
- Plot Data: Use the Serial Plotter in Velxio to visualize the analog readings over time.
- Use External Sensors: Replace the pots with a light-dependent resistor (LDR) or a temperature sensor like the LM35.
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!