114532 Views
101685 Views
86270 Views
54891 Views
51137 Views
49962 Views
Level Up your CAD Skills
Operation Pico
Raspberry Pi Home Hub
Hacky Temperature and Humidity Sensor
Robot Makers Almanac
High Five Bot
Using the Raspberry Pi Pico's Built-in Temperature Sensor
Getting Started with SQL
Introduction to the Linux Command Line on Raspberry Pi OS
How to install MicroPython
Wall Drawing Robot Tutorial
BrachioGraph Tutorial
KevsRobots Learning Platform
48% Percent Complete
By Kevin McAleer, 2 Minutes
Raw ADC values aren’t particularly useful on their own. This lesson will show you how to use a formula to convert the ADC value into a temperature in degrees Celsius.
The Pico’s temperature sensor uses the following formula to calculate temperature in degrees Celsius:
temperature = 27 - (raw_value - 0.706) / 0.001721
Modify your previous script to include the temperature calculation:
import machine import time # Initialize the ADC for the temperature sensor sensor_adc = machine.ADC(4) while True: # Read the raw ADC value raw_value = sensor_adc.read_u16() # Convert the ADC value to voltage voltage = raw_value * 3.3 / 65535 # Convert voltage to temperature temperature = 27 - (voltage - 0.706) / 0.001721 print(f"Temperature: {temperature:.2f}°C") time.sleep(1)
In the next lesson, you’ll learn how to format and enhance the output for better readability.
< Previous Next >