Home Code SHT21 humidity and temperature sensor example

SHT21 humidity and temperature sensor example

by shedboy71

The SHT21 is a low cost humidity and temperature sensor. Its an I2C device so again is very simple to connect to any arduino

The digital SHT2x humidity sensor series is used in high volumes in a wide variety of applications and has today become the de facto industry standard. The SHT2x series consists of a low-cost version with the SHT20 humidity sensor, a standard version with the SHT21 humidity sensor, and a high-end version with the SHT25 humidity sensor. The open cavity mold package – which encapsulates the complete chip except for the humidity sensor area – protects the capacitive humidity sensor against external impact and facilitates excellent long-term stability.

The SHT2x provides calibrated, linearized sensor signals in digital, I2C format. The SHT2x humidity sensor series contains a capacitive-type humidity sensor, a band-gap temperature sensor, and specialized analog and digital integrated circuits ,the resolution of the SHT2x humidity sensor can be changed on command (8/12 bit up to 12/14 bit for RH/T) and a checksum helps to improve communication reliability

This is the breakout for the sensor that I bought. This makes it easy to use the sensor and hook it up to an Arduino



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


Here is a schematic showing the connection, easy device to connect up


UNO and SHT21

UNO and SHT21

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


There are a couple of libraries to help you out


I used the latter one


[codesyntax lang=”cpp”]

#include <Wire.h>
#include <SHT2x.h>

void setup()

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



When you open the serial monitor you should see the temperature and humidity displayed



these come in at about $7 for a useful breakout board with this sensor

Humidity Sensor – SHT21 Breakout Board


You may also like