• This repository has been archived on 14/Apr/2023
  • Stars
    star
    233
  • Rank 172,230 (Top 4 %)
  • Language
    C++
  • License
    GNU General Publi...
  • Created almost 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Optimized DHT library for ESP32/ESP8266 using Arduino framework

DHTesp Build Status

This library is no longer maintained

An Arduino library for reading the DHT family of temperature and humidity sensors.
Forked from arduino-DHT
Original written by Mark Ruys, [email protected].

Why did I clone this library instead of forking the original repo and push the changes? When I searched through Github for DHT libraries, I found a lot of them, some of them offers additional functions, some of them only basic temperature and humidity values. I wanted to combine all interesting functions into one library. In addition, none of the DHT libraries I found were written to work without errors on the ESP32. For ESP32 (a multi core/ multi processing SOC) task switching must be disabled while reading data from the sensor.
Another problem I found is that many of the available libraries use the same naming (dht.h, dht.cpp), which easily leads to conflicts if different libraries are used for different platforms.

According to users, the library works as well with DHT33 and DHT44 sensors. But as I do not own these sensors, I cannot test and confirm it. However, if you want to use this sensors, you can do so by using setup(pin, DHTesp::DHT22) and it should work. Please give me feedback in the issues if you successfull use these sensors. Thank you

The library is tested as well on ESP8266 and should work on AVR boards as well.

Changes to the original library:

  • 2017-12-12: Renamed DHT class to DHTesp and filenames from dht.* to DHTesp.* to avoid conflicts with other libraries - beegee-tokyo, [email protected].
  • 2017-12-12: Updated to work with ESP32 - beegee-tokyo, [email protected].
  • 2017-12-12: Added function computeHeatIndex. Reference: Adafruit DHT library.
  • 2017-12-14: Added function computeDewPoint. Reference: idDHTLib.
  • 2017-12-14: Added function getComfortRatio. Reference: libDHT. (References about Human Comfort invalid)
  • 2017-12-15: Added function computePerception. Reference: WikiPedia Dew point==> Relationship to human comfort - beegee-tokyo, [email protected].
  • 2018-01-02: Added example for multiple sensors usage.
  • 2018-01-03: Added function getTempAndHumidity which returns temperature and humidity in one call.
  • 2018-01-03: Added retry in case the reading from the sensor fails with a timeout.
  • 2018-01-08: Added ESP8266 (and probably AVR) compatibility.
  • 2018-03-11: Updated DHT example
  • 2018-06-19: Updated DHT example to distinguish between ESP8266 examples and ESP32 examples
  • 2018-07-06: Fixed bug in ESP32 example
  • 2018-07-17: Use correct field separator in keywords.txt
  • 2019-03-07: Added computeAbsoluteHumidity which returns the absolute humidity in g/m³. Reference: How to convert relative humidity to absolute humidity kudos to Wurstnase
  • 2019-03-22: Fixed auto detection problem
  • 2019-07-31: Make getPin() public, Updated ESP8266 example
  • 2019-10-01: Using noInterrupts() & interrupts() instead of cli and sei
  • 2019-10-05: Reduce CPU usage and add decimal part for DHT11 (thanks to Swiftyhu)
  • 2019-10-06: Back to working version by removing the last commit
  • 2021-02-20: Fix negative temperature problem (credits @helijunky)

Features

Functions

void setup(uint8_t pin, DHT_MODEL_t model=AUTO_DETECT);

  • Call to initialize the interface, define the GPIO pin to which the sensor is connected and define the sensor type. Valid sensor types are:
    • AUTO_DETECT Try to detect which sensor is connected (default if 2nd parameter is not used)
    • DHT11
    • DHT22
    • AM2302 Packaged DHT22
    • RHT03 Equivalent to DHT22
      void resetTimer();
  • Reset last time the sensor was read

float getTemperature();

  • Get the temperature in degree Centigrade from the sensor
    Either one of getTemperature() or getHumidity() or getTempAndHumidity() initiates reading a value from the sensor if the last reading was older than the minimal refresh time of the sensor.
    See example DHT_ESP32.ino or DHT_Test.ino

float getHumidity();

  • Get the humidity from the sensor
    Either one of getTemperature() or getHumidity() or getTempAndHumidity() initiates reading a value from the sensor if the last reading was older than the minimal refresh time of the sensor.
    See example DHT_ESP32.ino or DHT_Test.ino

TempAndHumidity getTempAndHumidity();

  • Get the temperature and humidity from the sensor
    Either one of getTemperature() or getHumidity() or getTempAndHumidity() initiates reading a value from the sensor if the last reading was older than the minimal refresh time of the sensor.
    Return value is a struct of type TempAndHumidity with temperature and humidity as float values. See example DHT_Multi.ino

DHT_ERROR_t getStatus();

  • Get last error if reading from the sensor failed. Possible values are:
    • ERROR_NONE no error occured
    • ERROR_TIMEOUT timeout reading from the sensor
    • ERROR_CHECKSUM checksum of received values doesn't match

const char* getStatusString();

  • Get last error as a char *

DHT_MODEL_t getModel()

  • Get detected (or defined) sensor type

int getMinimumSamplingPeriod();

  • Get minimmum possible sampling period. For DHT11 this is 1000ms, for other sensors it is 2000ms

int8_t getNumberOfDecimalsTemperature();

  • Get number of decimals in the temperature value. For DHT11 this is 0, for other sensors it is 1

int8_t getLowerBoundTemperature();

  • Get lower temperature range of the sensor. For DHT11 this is 0 degree Centigrade, for other sensors this is -40 degree Centrigrade

int8_t getUpperBoundTemperature();

  • Get upper temperature range of the sensor. For DHT11 this is 50 degree Centigrade, for other sensors this is 125 degree Centrigrade

int8_t getNumberOfDecimalsHumidity();

  • Get number of decimals in the humidity value. This is always 0.

int8_t getLowerBoundHumidity();

  • Get lower humidity range of the sensor. For DHT11 this is 20 percent, for other sensors this is 0 percent

int8_t getUpperBoundHumidity();

  • Get upper temperature range of the sensor. For DHT11 this is 90 percent, for other sensors this is 100 percent

static float toFahrenheit(float fromCelcius);

  • Convert Centrigrade value to Fahrenheit value

static float toCelsius(float fromFahrenheit) { return (fromFahrenheit - 32.0) / 1.8; };

  • Convert Fahrenheit value to Centigrade value

float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=false);

  • Compute the heat index. Default temperature is in Centrigrade.

float computeDewPoint(float temperature, float percentHumidity, bool isFahrenheit=false);

  • Compute the dew point. Default temperature is in Centrigrade.

float computeAbsoluteHumidity(float temperature, float percentHumidity, bool isFahrenheit=false);

  • Compute the absolute humidity in g/m³. Default temperature is in Centrigrade.

float getComfortRatio(ComfortState& destComfStatus, float temperature, float percentHumidity, bool isFahrenheit=false);

  • Compute the comfort ratio. Default temperature is in Centrigrade. Return values:
    0 -> OK
    1 -> Too Hot
    2 -> Too cold
    4 -> Too dry
    8 -> Too humid
    9 -> Hot and humid
    5 -> Hot and dry
    10 -> Cold and humid
    6 -> Cold and dry

byte computePerception(float temperature, float percentHumidity, bool isFahrenheit=false);

  • Compute the human perception. Default temperature is in Centrigrade. Return values:
    0 -> Dry
    1 -> Very comfortable
    2 -> Comfortable
    3 -> Ok
    4 -> Uncomfortable
    5 -> Quite uncomfortable
    6 -> Very uncomfortable
    7 -> Severe uncomfortable

uint8_t getPin(void);

  • Returns the assigned GPIO for this instance. Usefull when connecting multiple sensors

Usage

See examples. For all the options, see dhtesp.h.

Installation

In Arduino IDE open Sketch->Include Library->Manage Libraries then search for DHT ESP
In PlatformIO open PlatformIO Home, switch to libraries and search for DHT ESP32. Or install the library in the terminal with platformio lib install 2029

For manual installation download the archive, unzip it and place the DHTesp folder into the library directory.
In Arduino IDE this is usually <arduinosketchfolder>/libraries/
In PlatformIO this is usually <user/.platformio/lib>

More Repositories

1

SX126x-Arduino

Arduino library to use Semtech SX126x LoRa chips and modules to communicate
C++
229
star
2

CCTVview

Simple ONVIF RTSP camera viewer for Android
Java
40
star
3

disaster-radio-android

Chat application to be used with
Java
33
star
4

SX126x-Mesh-Network

A simple LoRa Mesh network low level layer for the Semtech SX126x transceivers.
C++
29
star
5

WisBlock-API

WisBlock API takes care of all the LoRaWAN, BLE, AT command functionality. It makes development of event driven power savings applications easy.
C++
28
star
6

ESP32-Weatherstation

ESP32 with TFT display as small weather station displaying local and internet weather data
C
27
star
7

GCM-ESP8266

Send notifications to Android devices with Google Cloud Messaging without additional web server
Arduino
23
star
8

SX1262-SC-GW

Single channel LoRaWan gateway for ESP8266/ESP32 using Semtech SX1262 LoRa module
C++
19
star
9

RAK4631-LoRa-BLE-Config

Example how to configure LORa/LoRaWAN of a WisBlock Core RAK4631 over BLE
C++
16
star
10

WisBlock-API-V2

WisBlock API V2 for RAK4631 takes care of all the LoRaWAN, BLE, AT command functionality. It makes development of event driven power savings applications easy. RUI3 AT command compatible allows the usage of RAKwireless' WisToolBox to setup the device.
C++
12
star
11

Meshtastic-Sensor-Network

Setup a sensor network using Meshtastic mesh network and MQTT broker
JavaScript
11
star
12

RAK4631-LPWAN-Tracker

Example code for a LPWAN tracker based on the RAK WisBlock products
C++
10
star
13

MyAirCon

Remote control for air con using Adafruit HUZZAH ESP8266 modules
Arduino
10
star
14

nRF52_OLED

An I2C/SPI display driver for SSD1306/SH1106 oled displays connected to an nRF52
C
9
star
15

phoenix

Android auto reboot and restart defined app
Java
9
star
16

WisBlock-Sensor-For-LoRaWAN

Firmware for RAKwireless WisBlock RAK4631 Core module.
C
9
star
17

Emy-Chat

Chat app based on my SX126x-Mesh-Network
C++
6
star
18

RUI3-LowPower-Example

Example how to achieve lowest power consumption with a custom firmware created with RUI3
C++
6
star
19

RAK4631-Quick-Start-Examples

The results of this development have been moved to the WisBlock API. Approach to separate LoRa(WAN) and BLE handling from user application
C++
6
star
20

WisBlock-Seismic-Sensor

Example for WisBlock RAK12027 Seismic Sensor based on the Omron D7S. This repo includes the code for RAK4631 based on Arduino and the RAK4631-R and RAK3172 based on RAK's RUI3
C++
6
star
21

SHT1x-ESP

Arduino ESP library for SHT1x Temp & Humidity Sensors for ESP32
C++
5
star
22

RAK4631-RAK12014-Waterlevel

A water tank level sensor **Built With WisBlock** to detect overflow and low level conditions.
C++
5
star
23

Circuitrocks_ISP4520_Arduino

Circuitrocks code for the Insight SIP ISP4520 SoC on Arduino
C
5
star
24

My-nRF52-Toolbox

Simplified nRF52 toolbox created from Nordic's nRF52 Toolbox
Java
5
star
25

WiFi-Config-Info

ESP32 Example code how to get saved STA and AP configurations without connecting the WiFi
C++
4
star
26

RAK4631-DeepSleep

Example code for RAK4631 DeepSleep using LoRa P2P connections
C++
4
star
27

WisBlock-Toolbox

Compagnion to the WisBlock API which supports the OTA DFU firmware update and the LoRa® / LoRaWAN® configuration over BLE.
Java
4
star
28

RAK4631-Kit-1-RAK1901-RAK1902-RAK1903

Example code for WisBlock Weather Monitor Kit 1 with RAK1901/RAK1902/RAK1903
C++
4
star
29

ESP8266-Security-Front

Motion detection, alarm system and automatic light with ESP8266 (My frontyard version)
C++
4
star
30

RUI3-Sensor-Node

RAK4630 RUI3 example code for WisBlock I2C sensor modules.
C++
4
star
31

RUI3-Modular

An approach to create a sensor application with RUI3 without coding. Check the README file how it works.
C++
3
star
32

RAK11310-RAK1906

WisBlock RAK11310 with RAK1906 Environment Sensor for LoRaWAN with AT Command Interface
C++
3
star
33

Security

Security system based on ESP8266 module with Android devices as monitoring system
Java
3
star
34

RUI3-Sensor-Node-Air-Quality

RAK3172 RUI3 example code for air quality sensors
C++
3
star
35

RUI3-Signal-Meter-P2P-LPWAN-UI

This is a PoC of a very basic signal tester. It works in both LoRa P2P and LoRaWAN mode. It uses a simple OLED display and a simple one-button controlled UI for settings changes.
C++
3
star
36

spMonitor

# spMonitor Solar Panel Monitor with Arduino Yun, current and light sensors and WiFi module to transfer data to a PC or Android device
PHP
3
star
37

MHC-Sunnyboy-RAK13300

WisBlock RAK11200 - RAK13300 SMA Sunnyboy to IoT
C++
2
star
38

ESP32WiFiBLE-NimBLE

Setup ESP32 WiFi credentials over BLE from Android. ESP32 source code using NimBLE
C++
2
star
39

ESP32-MyLog

Log output functions similar to the Arduino-ESP32 log function, but used for application code output only without the system level log output
C
2
star
40

RUI3-Sensor-Node-Environment

RAK3172 RUI3 example code for environment sensors
C++
2
star
41

ESP8266-LightBackYard

WiFi controlled relay to switch on the lights in my backyard
C++
2
star
42

Disaster-Radio-BLE---nRF52832

DisasterRadio for Nordic nRF52
C++
2
star
43

Circuitrocks_ISP4520_Platform

For PlatformIO
Python
2
star
44

ESP32-BaseProject

Base project for my ESP32 module
C++
2
star
45

Emy-Chat-Android

An Android app to connect to Emy-Chat LoRa nodes
Java
2
star
46

OTA-TFT

Using a TFT display to show OTA status of an ESP32 module
C++
2
star
47

RAK11200-WiFi-setup-over-BLE

Use `My nRF52 Toolbox` to setup WiFi credentials over BLE
C++
2
star
48

RAK4631-Kit-2-RAK12500-RAK1906

Example code for WisBlock GNSS tracker with RAK12500 GNSS module and RAK1906 environment sensor
C++
2
star
49

WisBlock-IAQ-PM-CO2-VOC-EPD

Build a indoor air quality sensor with the WisBlock eco system.
C
2
star
50

ESP8266-Camera

Connect a simple serial camera module to an ESP8266 to capture pictures
C++
2
star
51

MyHomeControl

Application to get information from and send commands to my home applicance control system devices
Java
2
star
52

RUI3-Field-Tester

Location tracker that implements the LoRaWAN Field Tester payload format for https://www.disk91.com/2021/technology/lora/low-cost-lorawan-field-tester/
C++
2
star
53

Circuitrocks_ISP4520_Bootloader

USB-enabled bootloaders for the ISP4520 SoC chips
C
2
star
54

RAK4631-Kit-4-RAK1906

Example code for WisBlock Environment Sensor with RAK1906 environment sensor
C++
2
star
55

WeatherStation

This application uses the environment temperature sensor, air pressure sensor and humidity sensor of a Samsung Galaxy S4 to continously measure the weather conditions. It records with a background service every hour the values and stores them.
Java
2
star
56

RAK4631-Kit-2-RAK1910-RAK1904-RAK1906

Example code for WisBlock GNSS tracker with RAK1910 GNSS module, RAK1904 acceleration sensor and RAK1906 Environment sensor (optional, not included in Kit 2)
C++
2
star
57

WisBlock-API-Mesh

Simple LoRa Mesh network based on WisBlock API V2
C++
2
star
58

Emy-Chat-NimBLE

Chat app based on my SX126x-Mesh-Network. Using NimBLE library for reduced code and heap consumption
C++
1
star
59

ganbarou_vendor_gapps_43

Gapps for Ganbarou ROMs for Android 4.3
Shell
1
star
60

MyHomeControlMini

Minimal version of MyHomeControl for older phones without sufficient storage and low screen resolution.
Java
1
star
61

RUI3-my-IDEa

No-Code proof of concept for RAKwireless RUI3 API
C++
1
star
62

RAK11200-SMA-Sunnyboy

WisBlock application to read production data from a SMA Sunnyboy Solar Inverter
C++
1
star
63

ESP8266-MyLib

Functions I use in all my ESP8266 projects
C
1
star
64

RUI3-Signal-Meter-P2P-LPWAN

PoC of a very basic signal tester. It works in both LoRa P2P and LoRaWAN mode.
C++
1
star
65

RAK4631-RAK14014-Demo

Simple demo for the RAK14014 TFT display
C
1
star
66

RAK13011-Alarm-Msg-Queue

Example for RAK13011 magnetic switch. Sending status over LoRaWAN with event queue to make sure events are not missed.
C++
1
star
67

MHControl

Part of my home control system for data collection and security video recording.
C
1
star
68

RUI3-RAK13011

RUI3 application for the WisBlock magnetic switch RAK13011
C++
1
star
69

RUI3-RAK12010

Simple RUI3 application for WisBlock RAK12010 light sensor
C++
1
star
70

ESP32-MyLib

Functions I use in all my ESP32 projects
C++
1
star
71

test

Just some tests
1
star
72

TSL2561_simp

TSL2561 light sensor lib. Based on Adafruits library but removed requirement to include Unified sensor library.
C++
1
star
73

RUI3-RAK12047-Air-Quality

C++
1
star
74

Blues-Minimal-I2C

This library covers the communication between a RAKwireless WisCore module and a Blues.IO Notecard over I2C.
C++
1
star
75

PicoSoftwareSerial

Quick 'n' dirty PIO based implementation of SoftwareSerial for an RP2040 based board
C++
1
star
76

LoRa-P2P-Gateway

LoRa P2P gateway to MQTT broker or HTTP POST service
C++
1
star
77

Hydroponic-Control-System

A hydroponic control system built with RAKwireless WisBlock modules
C++
1
star