Arduino Code

You can easily wire this breakout to any microcontroller, we'll be using an Arduino. For another kind of microcontroller, just make sure it has I2C, then port the code - its pretty simple stuff!

  • Connect Vin to the power supply, 3-5V is fine. Use the same voltage that the microcontroller logic is based off of. For most Arduinos, that is 5V
  • Connect GND to common power/data ground
  • Connect the SCL pin to the I2C clock SCL pin on your Arduino. On an UNO & '328 based Arduino, this is also known as A5, on a Mega it is also known as digital 21 and on a Leonardo/Micro, digital 3
  • Connect the SDA pin to the I2C data SDA pin on your Arduino. On an UNO & '328 based Arduino, this is also known as A4, on a Mega it is also known as digital 20 and on a Leonardo/Micro, digital 2

The SHT31-D has a default I2C address of 0x44 which you can change to 0x45 by connecting the ADR pin to the VIN pin

Download Adafruit_SHT31

To begin reading sensor data, you will need to download Adafruit_SHT31 from our github repository. You can do that by visiting the github repo and manually downloading or, easier, just click this button to download the zip

Rename the uncompressed folder Adafruit_SHT31 and check that the Adafruit_SHT31 folder contains Adafruit_SHT31.cpp and Adafruit_SHT31.h

Place the Adafruit_SHT31 library folder your arduinosketchfolder/libraries/ folder.
You may need to create the libraries subfolder if its your first library. Restart the IDE.

We also have a great tutorial on Arduino library installation at:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use

Load Demo

Open up File->Examples->Adafruit_SHT31->SHT31test and upload to your Arduino wired up to the sensor

Thats it! Now open up the serial terminal window at 9600 speed to begin the test.

You can try breathing on the sensor to increase the humidity. The sensor reacts very fast!

Library Reference

The library we have is simple and easy to use

You can create the Adafruit_SHT31 object with:

Adafruit_SHT31 sht31 = Adafruit_SHT31();

There are no pins to set since you must use the I2C bus!

Then initialize the sensor with:

sht31.begin(0x44)

This function returns True if the sensor was found and responded correctly and False if it was not found

The 0x44 is the i2c address you have the sensor set up for. By default its 0x44, you can also adjust the sensor for 0x45 and then pass that value in

Once initialized, you can query the temperature in °C with

sht31.readTemperature()

Which will return floating point (decimal + fractional) temperature. You can convert to Fahrenheit by multiplying by 1.8 and adding 32 as you have learned in grade school!

Reading the humidity is equally simple. Call

sht31.readHumidity()

to read the humidity also as a floating point value between 0 and 100 (this reads % humidity)

We also have a few helper functions. Want to soft-reset the sensor? Use

sht31.reset()

There's also a heater built into the sensor, used to heat/evaporate any condensation. You can turn it on or off with

sht31.heater(true)
sht31.heater(false)
This guide was first published on Dec 08, 2015. It was last updated on Nov 17, 2018. This page (Arduino Code) was last updated on Feb 23, 2018.