Home ArduinoB4R B4R and Arduino SHT31 sensor example

B4R and Arduino SHT31 sensor example

SHT31 is the next generation of Sensirion’s temperature and humidity sensors. It builds on a new CMOSens® sensor chip that is at the heart of Sensirion’s new humidity and temperature platform.

The SHT3x-DIS has increased intelligence, reliability and improved accuracy specifications compared to its predecessor. Its functionality includes enhanced signal processing, two distinctive and user selectable I2C addresses and communication speeds of up to 1 MHz. The DFN package has a footprint of 2.5 x 2.5 mm2 while keeping a height of 0.9 mm.

This allows for integration of the SHT3x-DIS into a great variety of applications.

Features

Fully calibrated, linearized, and temperature compensated digital output
Wide supply voltage range, from 2.4 V to 5.5 V
I2C Interface with communication speeds up to 1 MHz and two user selectable addresses

I bought the following module

SHT31

SHT31

If you’re using an Arduino simply connect the VIN pin to the 5V voltage pin, GND to ground, SCL to I2C Clock (Analog 5) and SDA to I2C Data (Analog 4).

Here is a layout drawn up in fritzing to illustrate this

 

Layout

 

arduino-and-sht31

arduino-and-sht31

 

Code

This example uses the adafruit sht31 library – https://github.com/adafruit/Adafruit_SHT31

[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 sh31temp As Float
Public sht31humidity 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: “, sh31temp, “°C”)
Log(“Humidity is: “, sht31humidity, “%”)
End Sub

#if C
#include <Wire.h>
#include “Adafruit_SHT31.h”
Adafruit_SHT31 sht31 = Adafruit_SHT31();
void setup(B4R::Object* o){
sht31.begin();
}

void loop (B4R::Object* o) {

b4r_main::_sh31temp =sht31.readTemperature();
b4r_main::_sht31humidity =sht31.readHumidity();
}

#End if


[/codesyntax]

 

Output

Temperature is: 23.7770°C
Humidity is: 28.5069%
Temperature is: 23.7476°C
Humidity is: 28.5237%
Temperature is: 23.7343°C
Humidity is: 28.7312%
Temperature is: 25.9854°C
Humidity is: 31.9265%
Temperature is: 26.6743°C
Humidity is: 36.7315%
Temperature is: 27.0695°C
Humidity is: 41.0742%
Temperature is: 26.4233°C
Humidity is: 42.5605%

 

Link

1PCS/LOT SHT31 Temperature & SHT31-D Humidity Sensor module Breakout Weather for Arduino

You may also like