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. Its an I2C device so again is very simple to connect to any arduino
Features
Size | 3 x 3 x 1.1 mm |
Output | I²C digital, PWM, SDM |
Supply voltage range | 2.1 to 3.6 V |
Energy consumption | 3.2µW (at 8 bit, 1 measurement / s) |
RH operating range | 0 – 100% RH |
T operating range | -40 to +125°C (-40 to +257°F) |
RH response time | 8 sec (tau63%) |
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
Schematic
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
Code
You need to install the following library – https://github.com/markbeee/SHT21
[codesyntax lang=”cpp”]
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
‘These global variables will be declared once when the application starts.
‘Public variables can be accessed from all modules.
Public Serial1 As Serial
Public timer1 As Timer
Public sht21humi As Float
Public sht21temp As Float
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log(“AppStart”)
RunNative(“setup”,Null)
timer1.Initialize(“timer1_Tick”,1000)
timer1.Enabled = True
End Sub
Private Sub Timer1_Tick
RunNative(“loop”,Null)
Log(“Temperature is: “, sht21temp, “°C”)
Log(“Humidity is: “, sht21humi, ” %”)
End Sub
#if C
#include <Wire.h>
#include “SHT21.h”
SHT21 SHT21;
void setup(B4R::Object* o){
SHT21.begin();
}
void loop (B4R::Object* o) {
b4r_main::_sht21humi =SHT21.getHumidity();
b4r_main::_sht21temp =SHT21.getTemperature();
}
#End if
[/codesyntax]
Output
In the log view
Temperature is: 20.9541°C
Humidity is: 47.1311 %
Temperature is: 25.0403°C
Humidity is: 48.8706 %
Temperature is: 26.7027°C
Humidity is: 51.6553 %
Temperature is: 27.8289°C
Humidity is: 50.8161 %
Temperature is: 28.6547°C
Humidity is: 50.0150 %
Temperature is: 29.2982°C
Humidity is: 50.1371 %
Temperature is: 29.7915°C
Humidity is: 49.0003 %
Temperature is: 30.2420°C
Humidity is: 49.0079 %
Temperature is: 30.1562°C
Humidity is: 59.5365 %
Links
these come in at about $7 for a useful breakout board with this sensor
Humidity Sensor – SHT21 Breakout Board