Skip to content

SHT 21/HTU 21 – Measure Temperature and Himidity with Arduino + OLED/LCD []


Hello everyone, and welcome to another tutorial Sponsored by: DigitSpace
Get the products used: GY-21/SHT-21/HTU-21 Temperature and Humidity sensor
0.96″ OLED display 128×64 Blue/Yellow

             So this tutorial is about interfacing the SHT-21 or HTU-21 or GY-21, call it as you want, temperature and humidity sensor, we gonna see how to test it first then how to use it with OLED and LCD i²c screens, the humidity will be displayed in %RH and for the temperature it will be with (°C) Celsius and (°F) Fahrenheit.

Here are some quick data taken from the module datasheet:

SHT 21 Data

*The accuracy changes depending on the conditions:

SHT 21 accuracy variation

So this is the module (click pictures to expand):

As you can see the module has 4 pins (Vin/GND) are for power using 3.3V/GND from Arduino board, and SCL/SDA for i²c communication.

Test 1

For the test 1 and the rest we’ll need of course an Arduino board, here I’m using UNO, you can add some jumpwires and a breadboard… And we gonna test the module with the serial monitor and check the values given by it.

Arduino UNO board


This is the direct wiring, the module is powered by 3.3V and for i²c interface we need SDA/SCL wired with A4/A5.


Test 0

Here before I use any library/code or add other modules I prefer to test if the modules works first, to do so, wire the module and upload the i²c scanner code from the Arduino Playground:
Get the Code from the Arduino Playground

Once the code is uploaded, open the serial monitor you’ll be able to see that a device is found and its address.

Test 0


Now we can proceed to our next steps, test the module and check its values…

This the library I used you can download it from Github:
Download the SHT-21 Library by

Once the .ZIP file is downloaded go to Arduino IDE -> Sketch -> Include Library -> Add .ZIP Library and look for the ZIP file to be installed.


The code I used is the first example from the library, after you install the library go to:
File -> Examples -> SHT21-Arduino-Library-Master -> SHT21_Demo


After uploading the code open the serial monitor you’ll be able to see the temperature in Celsius and the humidity in %RH.

Test 1

Test 2

In this test we gonna add an OLED screen, here I used 128×64 you can use 128×32 aswell but you have to modify the code.

OLED 128x64
OLED 128×64


Both modules uses 3.3V and i²c interface, so they share all the pins:

Arduino + SHT21 + OLED


In addition to the SHT-21 library we have to add libraries for the OLED:

Download here  Adafruit OLED SSD1306 library.
Download here Adafruit GFX Library (may not be required, but in case you want to add some shapes).

Download and install just like before.


Here I’ve used 2 different codes, they have little differences:

  • The first code displays the (T/H) simultaneously in (°C/%RH)
  • The second code displays the T for 2s and then H for 2s in (°F/%RH)

Download the codes from the links below (Google Drive):


This is the result for the code 1:


Here is the result for the code 2:

Each of them is displayed every 2s, and I also converted the values to “Int”



Test 3

In this test, instead of using the OLED we gonna use the LCD i²c for the people who have this display…

lcd i2c
LCD i²c


Again all the modules share all the pins:

Arduino + SHT21 + LCD


Beside the SHT21 library, we’ll need LCD i²c library:
Download the LCD i²c library.

It’s installed the same way as a normal Arduino library.


I’ve created one code only, it displays the Temperature in °C and Humidity in %RH, you can modify it to display the °F…

Download the Code here.


Here is the result for the test 3:



Thanks to DigitSpace for their sponsorship.

Yassine View All

Automation and Electrical Engineer, Electronics amateur trying to share my little projects.

One thought on “SHT 21/HTU 21 – Measure Temperature and Himidity with Arduino + OLED/LCD [] Leave a comment

Leave a Reply

%d bloggers like this: