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 #108 background imageLoading...
Page #108 background image
SunFounder ESP32 Starter Kit
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (it's a very slow
˓sensor)
float humidity = dht.readHumidity();
// Read temperature as Celsius (the default)
float temperture = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperture)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the humidity and temperature
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperture);
Serial.println(" *C");
}
The dht.readHumidity() function is called to read the humidity value from the DHT sensor.
The dht.readTemperature() function is called to read the temperature value from the DHT
sensor.
The isnan() function is used to check if the readings are valid. If either the humidity or tem-
perature value is NaN (not a number), it indicates a failed reading from the sensor, and an error
message is printed.
Learn More
You can also display the temperature and humidity on the I2C LCD1602.
Note:
You can open the file 5.10_thermistor_lcd.ino under the path of euler-kit/arduino/5.
10_thermistor_lcd.
After selecting the board (ESP32 Dev Module) and the appropriate port, click the Upload button.
Always displaying “Unknown COMxx”?
The LiquidCrystal_I2C and DHT sensor library libraries are used here, you can install them from the
Library Manager.
102 Chapter 1. For Arduino 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