Tutoriel ESP32 25/55 - Mesure de la température à l'aide du NTC et de l'écran LCD | Kit d'apprentissage IoT ESP32 de SunFounder
Na boyekoli oyo, tokoyekola ndenge ya komeka température na kosalela thermistor ya Coefficient ya Température Négative (NTC) mpe kotalisa ba lectures na écran LCD na kosalela microcontrôleur ESP32. Projet oyo ekokangama na kosangisa thermistor ya NTC na ESP32 mpe kosalela LCD mpo na kolakisa ba lectures ya température na Celsius mpe Fahrenheit. Oyo ezali ndenge ya malamu ya kobanda na komeka température mpe ba techniques ya kolakisa na kosalela plateforme ya ESP32.
Tokosalela carte ya extension ya ESP32 ya SunFounder, oyo ebakisaka makoki ya ESP32 na Wi-Fi mpe Bluetooth oyo esalemi na kati. Carte oyo ekoki kosangisama pete na ba capteurs mpe ba écrans ndenge na ndenge, mpo na yango ezali malamu mpo na ba projets ya IoT. Thermistor ya NTC ekopesa ba lectures ya température kolanda na résistance na yango, oyo ebongwanaka na ndenge ya kokesana na température. Mpo na ndimbola ya kokoba na mise en place mpe code, tala vidéo (na vidéo na 00:00).
Matériel oyo elobami
Ba composants ya minene oyo basalelaka na projet oyo ezali na microcontrôleur ESP32, thermistor ya NTC, résistor, mpe écran LCD. ESP32 ezali lokola unité ya traitement central, oyo esalelaka ba données ya thermistor mpe ekolakisa écran LCD. Thermistor ya NTC ebongwanaka résistance na yango kolanda température, mpo na yango ekopesa biso nzela ya kokanisa température kolanda na configuration ya diviseur de tension na résistor ya kosala.
Écran LCD ekotalisa ba lectures ya température na Celsius mpe Fahrenheit. Tokosalela protocole ya I2C mpo na kosolola na LCD, oyo ekokitisaka ba fils oyo esengeli mpo na kokitisa motango ya ba pins. Thermistor ya NTC ezali na caractéristique oyo résistance na yango ekokitaka ntango température emataki, oyo ezali na tina mingi mpo na ba calcul na biso.
Ba Détails ya Datasheet
| Fabricant | SunFounder |
|---|---|
| Numéro ya partie | Thermistor NTC |
| Résistance nominale | 10 kΩ |
| Valeur Beta | 3950 K |
| Étendue ya température | -40°C kino 125°C |
| Paquet | Axial |
- Kokamba ete thermistor ezali na rating mpo na étendue ya température oyo ezali kolukama.
- Salela résistor ya 10 kΩ mpo na diviseur de tension; soki te, ba lectures ekozala mabe.
- Vérifier ba connexions mpo na kokima ba courts-circuits.
- Kokamba ete adresse ya I2C ya LCD ezali malamu (mbala mingi 0x27).
- Salela ba niveaux ya alimentation ya malamu mpo na ESP32 mpe ba périphériques.
- Vérifier ete débit en bauds ya moniteur série ekokani na code (115200).
Ba Instructions ya Câblage


Mpo na kobongisa ba composants, banda na kosangisa thermistor ya NTC na ESP32. Thermistor ezali na polarité te, yango wana ekoki kosangisama na ndenge nyonso. Sangisa fil ya moko ya thermistor na pin ya terre (GND) na ESP32. Fil ya mosusu ekokani na résistor ya 10 kΩ, oyo yango ekokani na pin ya 3.3V na ESP32. Esika oyo thermistor mpe résistor bakutanaka ekokani na pin 35 na ESP32, oyo ekotanga tension mpo na calcul ya température.
Mpo na LCD, sangisa pin ya terre (mbala mingi pin ya mibale kolanda na likoló) na GND na ESP32. Na nsima, sangisa VCC (mbala mingi pin ya liboso) na pin ya 5V na ESP32. Pin ya SDA (mbala mingi pin ya misato) esengeli kokangama na pin 21 na ESP32, mpe pin ya SCL (mbala mingi pin ya minei) esengeli kokangama na pin 22. Kamba ete ba connexions nyonso ezali ya libende mpe tala lisusu ba numéro ya ba pins mpo na kokima ba mbeba.
Ba Exemples ya Code & Explication
Code ebandaka na kolimbola ba constantes mpo na thermistor, na kotanga motango ya pin, tension ya référence, mpe ba valeurs ya résistance. Fonction ya setup ebandisaka communication série mpe esengeli ete pin ya thermistor ezala lokola entrée.
const int thermistorPin = 35; // Pin oyo ekokani na thermistor
const float referenceVoltage = 3.3;
const float referenceResistor = 10000; // résistor 'mosusu'
Boucle ya principale etangaka valeur analogique na pin ya thermistor, ekokanisaka résistance, mpe na nsima ekokanisaka température na Celsius mpe Fahrenheit na kosalela équation ya paramètre Beta. Ba valeurs oyo bakanisami ekomami na moniteur série.
int adcValue = analogRead(thermistorPin); // Tanga valeur ADC
float voltage = (adcValue * referenceVoltage) / 4095.0; // Kanisa tension
float resistance = (voltage * referenceResistor) / (referenceVoltage - voltage); // Kanisa résistance ya thermistor
Na suka, température elakisamaka na LCD. Fonction lcd.print() esalelamaka mpo na kolakisa ba valeurs ya température, elongo na symbole ya degré.
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(tempC, 1);
lcd.write(223); // Symbole ya degré
lcd.print("C");
Code oyo ebongisaka LCD na mbala na mbala na 300 millisecondes na ba lectures ya suka ya température, mpo na kosalela monitoring na temps réel.
Démonstration / Nini Okoki Kozela
Nsima okomi code yango mpe kosala connexion na yango, okomona température ezali komonana na LCD na Celsius mpe Fahrenheit. Soki okangi thermistor na loboko na yo, okomona température ezali komata ntango résistance ezali kokita. Kozala na bokebi na polarité oyo ebaluki mpe sɔ́lɔ́kɔ́ que connexions ezali ya kolongobana, pamba te connexion mabe ekoki komemela yo ba lectures oyo ezali malamu te (na vidéo na 04:50).
Ba Timestamps ya Vidéo
- 00:00 Ebandeli
- 1:50 introduction na projet
- 5:32 wiring esili kolimbolama
- 8:20 Code Arduino NTC mpo na ESP32 esili kolimbolama
- 13:38 Kopona carte ESP32 mpe COM port na Arduino IDE
- 15:20 NTC komeka température démonstration
- 17:34 NTC température na LCD1602 na ESP32
- 18:42 Code Arduino NTC na LCD esili kolimbolama
- 21:15 Démonstration ya température na LCD
- 23:13 LCD vert to LCD bleu1601?
// Define constants
const int thermistorPin = 35; // Pin connected to the thermistor
const float referenceVoltage = 3.3;
const float referenceResistor = 10000; // the 'other' resistor
const float beta = 3950; // Beta value (Typical Value)
const float nominalTemperature = 25; // Nominal temperature for calculating the temperature coefficient
const float nominalResistance = 10000; // Resistance value at nominal temperature
void setup() {
Serial.begin(115200); // Initialize serial communication
pinMode(thermistorPin, INPUT); // Set pin as input
}
void loop() {
int adcValue = analogRead(thermistorPin); // Read ADC value
float voltage = (adcValue * referenceVoltage) / 4095.0; // Calculate voltage
float resistance = (voltage * referenceResistor) / (referenceVoltage - voltage); // Calculate thermistor resistance with updated configuration
// Calculate temperature using the Beta parameter equation
float tempK = 1 / (((log(resistance / nominalResistance)) / beta) + (1 / (nominalTemperature + 273.15)));
float tempC = tempK - 273.15; // Get temperature in Celsius
float tempF = 1.8 * tempC + 32.0; // Get temperature in Fahrenheit
//Print temperature
printf("TempC: %.2f C\n", tempC);
printf("TempF: %.2f F\n", tempF);
delay(300); // Wait 1 second
}
/*
This is Lesson 25/55 of SunFounder's ESP32 IoT Learning kit code
displays temperature from NTC on LCD screen
written by Ahmad Shamshiri for SunFounder's ESP32 IoT Learnign kit
watch full video https://youtu.be/zJh-gWY0DmE
download this code, wiring diagram and other resources from https://robojax.com/RJT707
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//SDA->21,SCL->22
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
// Define constants
const int thermistorPin = 35; // Pin connected to the thermistor
const float referenceVoltage = 3.3;
const float referenceResistor = 10000; // Resistance value (10k)
const float beta = 3950; // Beta value (Typical Value)
const float nominalTemperature = 25; // Nominal temperature for calculating the temperature coefficient
const float nominalResistance = 10000; // Resistance value at nominal temperature
void setup() {
lcd.clear();
lcd.init();// initialize the lcd
lcd.backlight(); // Turns on the LCD backlight.
//Serial.begin(115200); // Initialize serial communication
pinMode(thermistorPin, INPUT); // Set pin as input
}
void loop() {
int adcValue = analogRead(thermistorPin); // Read ADC value
float voltage = (adcValue * referenceVoltage) / 4095.0; // Calculate voltage
float resistance = (voltage * referenceResistor) / (referenceVoltage - voltage); // Calculate thermistor resistance with updated configuration
// Calculate temperature using the Beta parameter equation
float tempK = 1 / (((log(resistance / nominalResistance)) / beta) + (1 / (nominalTemperature + 273.15)));
float tempC = tempK - 273.15; // Get temperature in Celsius
float tempF = 1.8 * tempC + 32.0; // Get temperature in Fahrenheit
//Print temperature
//printf("TempC: %.2f C\n", tempC);
//printf("TempF: %.2f F\n", tempF);
// Display temperature on LCD
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(tempC, 1);
lcd.write(223); // Degree symbol
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(tempF, 1);
lcd.write(223); // Degree symbol
lcd.print("F");
delay(300); // Wait 1 second
}
Common Course Links
Common Course Files
Mokili na bisika
-
DokumentasiESP32 Tutorial 25/55- SunFounder doc page for NTS thermometerdocs.sunfounder.com
-
DokumentasiLearn about NTC Thermistordocs.sunfounder.com
Fichiers📁
Aucun fichier disponible.