Menu Close

Raspberry pi Pico Internal Temperature Measurement

In this project, we use the internal temperature sensor built into the Raspberry Pi Pico to read the current temperature. The sensor is connected to ADC channel 4 and outputs a voltage that varies with temperature. We read this voltage using the ADC and apply a formula to convert it to degrees Celsius and Fahrenheit. This experiment demonstrates how to use on-board hardware features and basic analog-to-digital conversion.

Connections:

No external components or wiring required

The temperature sensor is built-in and connected to ADC channel 4 internally

Code:

from machine import ADC

# Internal temperature sensor is connected to ADC channel 4
temp_sensor = ADC(4)

def read_internal_temperature():
    # Read the raw ADC value
    adc_value = temp_sensor.read_u16()

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

    # Temperature calculation based on sensor characteristics
    temperature_celsius = 27 - (voltage - 0.706) / 0.001721

    return temperature_celsius

def celsius_to_fahrenheit(temp_celsius): 
    temp_fahrenheit = temp_celsius * (9/5) + 32 
    return temp_fahrenheit

# Reading and printing the internal temperature
temperatureC = read_internal_temperature()
temperatureF = celsius_to_fahrenheit(temperatureC)
print("Internal Temperature:", temperatureC, "°C")
print("Internal Temperature:", temperatureF, "°F")

Download Code:

Result:
When the code runs, it reads the internal sensor’s voltage, converts it to Celsius using a calibrated formula, and also displays the temperature in Fahrenheit. The results are printed to the console for monitoring.

Leave a Reply