Raspberry Pi Pico Onboard Temperature Sensor: USB Setup and MicroPython Code
Learn to read the temperature sensor built into the Raspberry Pi Pico (RP2040) and print a simple monitor with current, minimum and maximum estimates. This beginner project needs no soldering or external sensor. It introduces analog-to-digital conversion, averaging and USB serial output.
What you will build: a MicroPython program that reports the RP2040 chip temperature about once per second. The sensor measures the silicon inside the chip; board activity and power conditions influence it. Use it to explore trends, rather than as a calibrated room thermometer.
Contents
- Parts and board choice
- How it works
- Circuit and USB connection
- MicroPython and Thonny setup
- Complete program
- Run and test
- Troubleshooting and FAQs
Parts and board choice
| Item | Required quantity | Specification and purchase information |
|---|---|---|
| Raspberry Pi Pico (RP2040) | 1 board | Original non-wireless Pico with RP2040; store SKU RS0000003. Package contains one board. Headers are unnecessary. |
| USB data cable | 1 | Micro-USB plug at Pico end; computer end must match your USB port. No compatible standalone cable was verified in the store catalog. Supply your own data-capable cable; the Uno USB Type-B cable does not fit. |
| Computer with USB and Thonny | 1 existing computer | Windows, macOS or Linux. No store purchase link is applicable. |
This guide targets the original Pico. Choose its matching firmware, not the Pico W or Pico 2 download. A normal computer USB data port supplies the board for this unloaded project. No external power supply or additional current-consuming hardware is connected. Actual board current depends on firmware activity; this tutorial does not claim a measured current value.
How the onboard temperature sensor works
The RP2040 routes its internal temperature sensor to ADC channel 4. MicroPython exposes an ADC reading scaled from 0 to 65535. The underlying converter is 12-bit; the 16-bit API range does not create 16 bits of measurement precision. The program averages 16 samples and applies the documented nominal conversion:
voltage = average_reading * 3.3 / 65535
temperature_C = 27 - (voltage - 0.706) / 0.001721
The assumed 3.3 V reference and typical sensor constants introduce uncertainty. Averaging can reduce random variation, but it cannot remove reference error or calibrate the sensor. One decimal place keeps the display readable; it does not promise 0.1 °C accuracy. The minimum and maximum values apply only since the program started.
Circuit schematic and connections
All sensing circuitry is already on the Pico. The first diagram is a simplified connection schematic at the USB interfaces; it omits the onboard regulator and USB circuitry. The second shows how to connect the intact cable. There is no external breadboard circuit to assemble.


| Connection or channel | Destination | What to do |
|---|---|---|
| Computer USB | Pico Micro-USB socket | Connect one intact data cable for power and serial communication. |
| ADC channel 4 | Internal RP2040 temperature sensor | Select ADC(4) in software. Do not connect GPIO4. |
| GPIO headers, VSYS and 3V3 | Unused | Leave disconnected for this project. |
Before connecting: place the board on a dry, non-conductive surface. Avoid loose metal beneath it. Do not apply USB 5 V to GPIO or 3V3 pins, splice the USB cable, or add a second power source. No heaters, flames, liquids or cooling sprays are needed to test the program.
Install MicroPython and prepare Thonny
- Download Thonny from thonny.org and install it using the instructions for your operating system.
- Back up any existing Pico files before changing its firmware. Download a stable UF2 for Raspberry Pi Pico from MicroPython. The release listed during preparation was v1.29.0; use the matching Pico build, not a preview build.
- Disconnect the Pico. Hold BOOTSEL while connecting it by USB, then release the button. The RPI-RP2 drive should appear.
- Copy the UF2 onto that drive. It disappears when flashing finishes and the board restarts. This is expected.
- Open Thonny and select the MicroPython (Raspberry Pi Pico) interpreter and the Pico USB serial port in its interpreter settings. Stop any running script to obtain the prompt.
- Create a new editor file, paste the complete program below and save it on the Pico as
pico_temperature.py. No extra library or cloud account is needed.
Complete MicroPython program
Copy all lines, preserving indentation. The complete file is also supplied with the local review preview. A permanent Shopify code-download link has not yet been added.
# Anu Electronics: Pico RP2040 chip-temperature monitor.
# Original application; conversion constants from Raspberry Pi documentation.
from machine import ADC
from time import sleep_ms
VREF = 3.3 # Nominal reference, not a measured or calibrated value.
SAMPLES = 16
def to_celsius(raw):
volts = raw * VREF / 65535
return 27 - (volts - 0.706) / 0.001721
def averaged_temperature(sensor):
total = 0
for _ in range(SAMPLES):
total += sensor.read_u16()
sleep_ms(5)
return to_celsius(total / SAMPLES)
def main():
sensor = ADC(4) # Internal temperature channel; NOT GPIO4.
minimum = None
maximum = None
sample = 0
print("sample,chip_C,min_C,max_C")
try:
while True:
temperature = averaged_temperature(sensor)
minimum = temperature if minimum is None else min(minimum, temperature)
maximum = temperature if maximum is None else max(maximum, temperature)
sample += 1
print("{},{:.1f},{:.1f},{:.1f}".format(
sample, temperature, minimum, maximum))
sleep_ms(920) # Plus 16 x 5 ms sampling; about one report per second.
except KeyboardInterrupt:
print("Stopped. Readings were chip-temperature estimates.")
if __name__ == "__main__":
main()
Key code sections
-
ADC(4)selects the internal sensor channel. -
averaged_temperature()collects 16 readings with short gaps, then converts their average. -
minimumandmaximumstart from the first result, so negative readings do not break the range calculation. - The sampling delay plus the final wait makes the report interval approximately one second, not a precision timer.
- Ctrl+C stops the loop cleanly. Nothing is repeatedly written to flash memory.
Upload, run and inspect the result
- Run the saved file in Thonny. Look for the column header
sample,chip_C,min_C,max_Cin the Shell. - Leave the board undisturbed for a minute and watch successive rows. The sample number should increase; minimum should never increase and maximum should never decrease during the same run.
- Stop with Ctrl+C, then run again. The sample count and minimum/maximum reset.
- To run at boot later, save a copy as
main.pyon the Pico, after backing up any existing main.py. Keep Thonny connected to see USB output. Use Stop or Ctrl+C before editing a running startup script.

Small fluctuations are normal. An unchanged rounded value is also possible. Do not expect these example numbers on your board, and do not use the program for thermal protection, safety alarms or precise environmental measurement.
Troubleshooting
| Symptom | Check |
|---|---|
| No RPI-RP2 drive | Hold BOOTSEL before connecting. Try a known data cable and another computer USB port. |
| Drive disappears after UF2 copy | Expected: select the new serial port in Thonny after the restart. |
| No module named machine | The program is running on desktop Python. Select the Pico MicroPython interpreter. |
| No output or port busy | Close other serial applications, check the selected port, then stop and run the file again. |
| Readings differ from a room thermometer | The chip has its own temperature and the conversion is uncalibrated. Use an external sensor suited to room measurements. |
| Very implausible results | Confirm the original RP2040 Pico, correct firmware, ADC(4), and the complete formula. Do not divide read_u16 values by 4095. |
Frequently asked questions
Does ADC(4) mean GPIO4?
No. Here 4 identifies an internal ADC channel. No wire goes to GPIO4 or any header pin.
Do I need to solder headers?
No. The USB connector is the only physical connection in this project.
Can I use this as a room thermometer?
It is useful for learning and observing chip-temperature trends. For air temperature and humidity, try our DHT11 tutorial after checking its required board and wiring.
Why is the output CSV?
The header and comma-separated rows are easy to copy into a spreadsheet. The program only prints; it does not automatically save a log.
Sources and validation
Technical references: Raspberry Pi board documentation, Raspberry Pi ADC temperature conversion, MicroPython RP2 API reference and official Pico firmware installation. Article organisation was inspired by CircuitDigest's tutorial format; this text, program and diagrams were created for Anu Electronics.
The program passed desktop Python syntax and simulated logic checks. It has not been run on physical Pico hardware. The GIF is simulated. Cover artwork uses the matching store product as a visual reference; use the technical diagrams for connections.
Build your first Pico monitor
Start with the Raspberry Pi Pico (RP2040) and a compatible Micro-USB data cable. Once the monitor works, experiment with the sample count and compare how smooth the output looks.