EasyManuals Logo

SunFounder ESP32 User Manual

Default Icon
771 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #396 background imageLoading...
Page #396 background image
SunFounder ESP32 Starter Kit
(continued from previous page)
# Define the beta value of the thermistor, typically provided in the datasheet
beta = 3950
# Create an ADC object (thermistor)
thermistor = ADC(Pin(35, Pin.IN))
# Set the attenuation
thermistor.atten(thermistor.ATTN_11DB)
# Start an infinite loop to continuously monitor the temperature
while True:
# Read the voltage in microvolts and convert it to volts
Vr = thermistor.read_uv() / 1000000
# Calculate the resistance of the thermistor based on the measured voltage
Rt = 10000 * Vr / (3.3 - Vr)
# Use the beta parameter and resistance value to calculate the temperature in Kelvin
temp = 1 / (((math.log(Rt / 10000)) / beta) + (1 / (273.15 + 25)))
# Convert to Celsius
Cel = temp - 273.15
# Convert to Fahrenheit
Fah = Cel * 1.8 + 32
# Print the temperature values in both Celsius and Fahrenheit
print('Celsius: %.2f C Fahrenheit: %.2f F' % (Cel, Fah))
time.sleep(0.5)
When the code is run, the Shell will print out the Celsius and Fahrenheit temperatures.
How it works?
Each thermistor has a normal resistance. Here it is 10k ohm, which is measured under 25 degree Celsius.
When the temperature gets higher, the resistance of the thermistor decreases. Then the voltage data is converted to
digital quantities by the A/D adapter.
The temperature in Celsius or Fahrenheit is output via programming.
Here is the relation between the resistance and temperature:
RT =RN expB(1/TK - 1/TN)
• RT is the resistance of the NTC thermistor when the temperature is TK.
• RN is the resistance of the NTC thermistor under the rated temperature TN. Here, the numerical
value of RN is 10k.
• TK is a Kelvin temperature and the unit is K. Here, the numerical value of TK is 373.15 + degree
Celsius.
• TN is a rated Kelvin temperature; the unit is K too. Here, the numerical value of TN is 373.15+25.
• And B(beta), the material constant of NTC thermistor, is also called heat sensitivity index with a
numerical value 4950.
390 Chapter 3. For MicroPython User

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the SunFounder ESP32 and is the answer not in the manual?

SunFounder ESP32 Specifications

General IconGeneral
BrandSunFounder
ModelESP32
CategoryController
LanguageEnglish