The temperature and humidity sensors in this toolkit are combined into a single DHT (Digital Humidity and Temperature) sensor module. This means a single physical component provides both sets of data.
There are two common versions of this sensor: DHT11 (usually blue) and DHT22 (usually white). While they look similar and use the same pinout, they have different performance characteristics:
#include"DHT.h"#define DHTPIN 14 // Digital pin connected to the DHT sensor#define DHTTYPE DHT22 // Change to DHT11 if using the blue versionDHTdht(DHTPIN,DHTTYPE);voidsetup(){Serial.begin(115200);dht.begin();}voidloop(){delay(2000);floath=dht.readHumidity();floatt=dht.readTemperature();if(isnan(h)||isnan(t)){Serial.println(F("Failed to read from DHT sensor!"));return;}Serial.print(F("Humidity: "));Serial.print(h);Serial.print(F("% Temperature: "));Serial.print(t);Serial.println(F("°C "));}