SunFounder ESP32 Starter Kit
Code
Note:
• Open the 5.13_dht11.ino file under the path of esp32-starter-kit-main\c\codes\5.13_dht11.
• After selecting the board (ESP32 Dev Module) and the appropriate port, click the Upload button.
• Always displaying “Unknown COMxx”?
• The DHT sensor library library is used here, you can install it from the Library Manager.
After the code is uploaded successfully, you will see the Serial Monitor continuously print out the temperature and
humidity, and as the program runs steadily, these two values will become more and more accurate.
How it works?
1. Includes the DHT.h library, which provides functions to interact with the DHT sensors. Then, set the pin and
type for the DHT sensor.
#include "DHT.h"
#define DHTPIN 14 // Set the pin connected to the DHT11 data pin
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
2. Initializes serial communication at a baud rate of 115200 and initializes the DHT sensor.
void setup() {
Serial.begin(115200);
Serial.println("DHT11 test!");
dht.begin();
}
3. In the loop() function, read temperature and humidity values from the DHT11 sensor, and print them to the
serial monitor.
1.29. 5.13 Temperature - Humidity 101