Obtain Temperature Data From on Board Temperature Sensor of Raspberry Pi Pico
by Manodeep in Circuits > Raspberry Pi
6877 Views, 3 Favorites, 0 Comments
Obtain Temperature Data From on Board Temperature Sensor of Raspberry Pi Pico
The internal temperature sensor that comes with the Raspberry Pi Pico is connected to one of the ADCs or Analog-to-Digital Converters. The ADC pin supports a range of values, which is determined by the input voltage applied to the pin.
In the RP2040 Pico Board, the ADC pins support 12-bits, which means that the value can go from 0 to 4095. But the MicroPython code can scale the ADC values to a 16-bit range. So we effectively get the range from 0 to 65535. The microcontroller works at 3.3 V, which means that an ADC pin will return a value of 65535 when 3.3 V is applied to it or 0 when there is no voltage. We can obtain all the in-between values when the voltage applied to the pin is between 0 and 3.3 V.
Supplies
1. Raspberry Pi Pico
Connect Pi Pico With PC
Connect the Pi Pico with a computer using a USB cable.
Open Thonny or Any IDE Write the Code, Save It As Tempinbuilt.py and Run It
import machine import utime sensor_temp = machine.ADC(4) conversion_factor = 3.3 / (65535) while True: reading = sensor_temp.read_u16() * conversion_factor temperature = 27 - (reading - 0.706)/0.001721 print("Temperature: {}".format(temperature)) utime.sleep(2)