Products used: GY-21/SHT-21/HTU-21 Temperature and Humidity sensor0.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 I'm using:
SHT 21
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 1For 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.
Wiring_1 can be found below.
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 0Here 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.
CodeThe 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
ResultAfter 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.
wiring_2 can befound below
Both modules uses 3.3V and i²c interface, so they share all the pins:
LibrariesIn 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.
CodesHere 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)
Codes can be found below.
ResultsThis is the result for the code 1:
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…
Wiring_3 can be found below
Again all the modules share all the pins.
LibrariesBeside 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.
CodeI’ve created one code only, it displays the Temperature in °C and Humidity in %RH, you can modify it to display the °F…
Code can be found below
ResultHere is the result for the test 3:
*Sorry if I don't respond to comments, I don't receive notifications.
Comments