DHT sensor library for ESPx: an example that runs
Yes. You can use the DHT sensor library for ESPx library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Temperature and humidity, DHT22). The example below, "Temperature, humidity and heat index with DHTesp", runs on the Arduino Uno R3.
Built in on Mokxi: #include <DHTesp.h> and it builds, with nothing to install. Free, and no account needed.
What DHT sensor library for ESPx does
DHTesp: setup(pin, DHTesp::DHT22), getTempAndHumidity(), getStatusString(), heat index and dew point. That is what DHT sensor library for ESPx, by beegee_tokyo, covers. The sketch below uses it on the Arduino Uno: “Temperature, humidity and heat index with DHTesp”.
The interface of beegee-tokyo's "DHT sensor library for ESPx" (DHTesp), the DHT11 and DHT22 library many ESP32 and ESP8266 tutorials use.
As upstream: a reading is taken at most once a sampling period (1 s for a DHT11, 2 s for a DHT22) and the calls in between return the last one. A failed read is NaN, with getStatus() saying TIMEOUT or CHECKSUM.
The calls follow release 1.19.0 of the library, so a sketch written here builds on a real board too. The example is the one Mokxi's own tests build and run, so what is printed here is what runs.
| Library Manager name | DHT sensor library for ESPx |
|---|---|
| Author | beegee_tokyo |
| Include | #include <DHTesp.h> |
| Boards | every board Mokxi compiles for but ATtiny85 |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | Temperature and humidity, DHT22 |
Install it
It builds on every board Mokxi compiles for but ATtiny85.
In Mokxi it is built in: #include <DHTesp.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "DHT sensor library for ESPx" by beegee_tokyo from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add DHT sensor library for ESPx to lib_deps in PlatformIO. Mokxi follows the calls of release 1.19.0, so a sketch written here builds there too.
What to know in the simulator: getComfortRatio() uses a fixed comfort box of 20 to 26 C and 30 to 70 %, not upstream’s comfort profile.
- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi
The calls you will use
In the order a sketch meets them.
DHTesp dht
Makes dht, the DHTesp object the calls below are made on.
dht.setup(2, DHTesp::DHT22)
Starts it up. Call it once in setup().
dht.getMinimumSamplingPeriod()
Returns the minimum sampling period as a whole number.
TempAndHumidity v
Declares v, a TempAndHumidity that the example uses.
dht.getTempAndHumidity()
Returns the temp and humidity as a TempAndHumidity.
dht.getStatusString()
Returns the status string as text.
dht.computeHeatIndex(v.temperature, v.humidity)
Computes the heat index and returns a decimal number. Arguments: temperature, percent humidity, is fahrenheit.
Example: Temperature, humidity and heat index with DHTesp
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include "DHTesp.h"
DHTesp dht;
void setup() {
Serial.begin(115200);
dht.setup(2, DHTesp::DHT22);
}
void loop() {
delay(dht.getMinimumSamplingPeriod());
TempAndHumidity v = dht.getTempAndHumidity();
Serial.print(dht.getStatusString());
Serial.print("\tTemperature: ");
Serial.print(v.temperature, 1);
Serial.print(" C\tHumidity: ");
Serial.print(v.humidity, 1);
Serial.print(" %\tHeat index: ");
Serial.println(dht.computeHeatIndex(v.temperature, v.humidity), 1);
}Wiring
- Arduino Uno R3 2 to Temperature and humidity, DHT22 DATA
- Arduino Uno R3 5V to Temperature and humidity, DHT22 VCC
- Arduino Uno R3 GND to Temperature and humidity, DHT22 GND
Try DHT sensor library for ESPx without installing anything
Open the example, change the sketch, and keep your version in a free account.