ESP8266 and SHT21 humidity and temperature sensor example

SHT21, the new humidity and temperature sensor of Sensirion is about to set new standards in terms of size and intelligence: Embedded in a reflow solderable Dual Flat No leads (DFN) package of 3 x 3mm foot print and 1.1mm height it provides calibrated, linearized signals in digital, I2C format.

With a completely new designed CMOSens® chip, a reworked capacitive type humidity sensor and an improved band gap temperature sensor the performance has been lifted even beyond the outstanding level of the previous sensor generation (SHT1x and SHT7x). For example, measures have been taken to stabilize the behavior at high humidity levels. Every sensor is individually calibrated and tested. Lot identification is printed on the sensor and an electronic identification code is stored on the chip – which can be read out by command.

Furthermore, the resolution of SHT21 can be changed by command (8/12bit up to 12/14bit for RH/T), low battery can be detected and a checksum helps to improve communication reliability.

SHT21 features a generation 4C CMOSens® chip. Besides the capacitive relative humidity sensor and the band gap temperature sensor, the chip contains an amplifier, A/D converter, OTP memory and a digital processing unit.

This is the breakout for the sensor that I bought.

Here is a simple schematic, again be careful as Vcc is 3.3v with this device



Lets look at the required libraries and a basic code example, there is not much to this to be honest most of the work is done in the library


You need the following library for this example –




[codesyntax lang=”cpp”]

#include <Wire.h>
#include <Sodaq_SHT2x.h>

void setup()

void loop()
Serial.print("Humidity(%RH): ");
Serial.print(" Temperature(C): ");
Serial.print(" Dewpoint(C): ");






Open the serial monitor

Humidity(%RH): 43.24
Temperature(C): 24.56
Dewpoint(C): 11.21
Humidity(%RH): 43.26
Temperature(C): 24.54
Dewpoint(C): 11.21
Humidity(%RH): 43.52
Temperature(C): 24.93
Dewpoint(C): 11.62
Humidity(%RH): 44.13
Temperature(C): 25.10
Dewpoint(C): 12.11
Humidity(%RH): 44.77
Temperature(C): 25.59
Dewpoint(C): 12.80



SHT21 Digital Humidity And Temperature Sensor Module


Please enter your comment!
Please enter your name here