KevsRobots Learning Platform
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.
You can use the arrows β β on your keyboard to navigate between lessons.
Comments