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:
*The accuracy changes depending on the conditions:
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.
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.
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.
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.
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 e-radionica.com
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.
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.
Both modules uses 3.3V and i²c interface, so they share all the pins:
In addition to the SHT-21 library we have to add libraries for the OLED:
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”
In this test, instead of using the OLED we gonna use the LCD i²c for the people who have this display…
Again all the modules share all the pins:
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…
Here is the result for the test 3:
Thanks to DigitSpace for their sponsorship.
Automation and Electrical Engineer, Electronics amateur trying to share my little projects.