FUSION AUTOMATE
Published © GPL3+

Read Internal Temperature of Raspberry Pi Pico W

How to Read Internal Temperature of Raspberry Pi Pico W using On-Board Temperature Sensor

BeginnerProtip1 hour68
Read Internal Temperature of Raspberry Pi Pico W

Things used in this project

Hardware components

Raspberry Pi Pico W
Raspberry Pi Pico W
×1

Software apps and online services

MicroPython
MicroPython

Story

Read more

Code

main.py

Python
from machine import ADC
import time

# Define the ADC pin connected to the temperature sensor
adcpin = 4

# Initialize the ADC object with the ADC pin
sensor = ADC(adcpin)

while True:
    # Read the ADC value
    adc_value = sensor.read_u16()

    # Convert ADC value to voltage
    volt = (3.3 / 65535) * adc_value

    # Calculate temperature using the voltage
    temperature = 27 - (volt - 0.706) / 0.001721

    # Round the temperature to one decimal place
    temperature = round(temperature, 1)

    # Print the temperature
    print("Temperature:", temperature, "°C")

    # Wait for 1 second before reading temperature again
    time.sleep(1)

Credits

FUSION AUTOMATE

FUSION AUTOMATE

25 projects • 1 follower

Comments