Este tutorial instrui você a usar o ESP32 para ler o valor de temperaturas do sensor de temperatura LM35 e imprimi-lo no Serial Monitor.
O sensor LM35 emite a tensão em proporção linear com a temperatura Celsius. O fator de escala de saída do LM35 é 10 mV/°C. Medindo a tensão no pino OUT do LM32, podemos calcular o valor da temperatura.
Código básico do LM35 para carregar no ESP32:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | /* * This ESP32 code is created by esp32io.com * * This ESP32 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-lm35-temperature-sensor */ #define ADC_VREF_mV 3300.0 // in millivolt #define ADC_RESOLUTION 4096.0 #define PIN_LM35 36 // ESP32 pin GIOP36 (ADC0) connected to LM35 void setup() { Serial.begin(9600); } void loop() { // read the ADC value from the temperature sensor int adcVal = analogRead(PIN_LM35); // convert the ADC value to voltage in millivolt float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION); // convert the voltage to the temperature in °C float tempC = milliVolt / 10; // convert the °C to °F float tempF = tempC * 9 / 5 + 32; // print the temperature in the Serial Monitor: Serial.print("Temperature: "); Serial.print(tempC); // print the temperature in °C Serial.print("°C"); Serial.print(" ~ "); // separator between °C and °F Serial.print(tempF); // print the temperature in °F Serial.println("°F"); delay(500); } |