The SHT31 from Sensirion is a factory calibrated sensor for measuring relative humidity & temperature. The SHT31 has increased intelligence, reliability and improved accuracy specifications compared to its predecessor. Unlike the SHT15 this sensor is fully I2C compatible.
The easiest way to use this sensor is using a breakout board. We use the breakout board from Adafruit. This board has the pullup and pulldown resistors already installed. We just need to connect the wires from the SHT31 board to the Arduino and load the software.
(Images are not to scale)
To use the alternative I2C address we need to pull the ADR pin high. This is pulled to ground on the breakout board via one of the resistors. As shown in the diagram below we have connected the ADR pin to the 5V pin on the Arduino. We will also need to modify the sketch so that when we create the SHT31 object we define the address 0x45. We create the object using cactus_io_SHT31 sht(0x45).
The RST pin is used to hardware reset the sensor. We do not use it. The ALR pin is used to signal the microcontroller that a trigger event has occured on the sensor. This could be a maximum or minimum temperature or humidity has been reached. We are not using this functionality. Refer to the product website for more details on this functionality.
We can test this sensor using the simple sketch as shown below. It requires the cactus.io SHT31 Library to communicate with the sensor.
It reads the temperature and humidity every 2 seconds and then displays it on the console.
The cactus_io_SHT31 library provides the following functions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#include "cactus_io_SHT31.h"
cactus_io_SHT31 sht31; // or cactus_io_SHT31 sht31(0x45); // for the alternative address void setup(){ Serial.begin(9600); Serial.println("Sensirion SHT31 Humidity - Temperature Sensor | cactus.io"); if (!sht31.begin()) { Serial.println("Count not find sensor. Check wiring and I2C address"); while(1) delay(1); } Serial.println("Humidity\t\tTemp \t\tTemp"); } void loop(){ Serial.print(sht31.getHumidity()); Serial.print(" %\t\t"); Serial.print(sht31.getTemperature_C()); Serial.print(" *C\t"); Serial.print(sht31.getTemperature_F()); Serial.print(" *F\t"); Serial.print(sht31.getDewPoint()); Serial.println(" *C\t"); // Add a 2 second delay. delay(2000); } |