Contents

Interfacing SHT31 Temperature & Humidity Sensor with Arduino

SHT31 Temperature & Humidity Sensor Features

SHT31 is a digital temperature and humidity sensor. This module uses I2C communication and there are two SCL and SDA pins that are needed to be hooked up in order to communicate to this sensor. This sensor is ideal for temperature and humidity sensing.

Temperature measurement range: -40° +125°/ Accuracy ±0.3C°

Humidity measuring range: 0-100% RH°/ Accuracy ±2%

You can download the datasheet of this module here.

  

SHT31 Temperature Sensor Pinout

This sensor has 4 pins:

  • VCC: Module power supply –2.4-5 V
  • GND: Ground
  • SDA: I2C data
  • SCL: I2C clock

You can see pinout of this module in the image below.

Required Materials

Hardware Components

Arduino UNO R3 × 1
SHT31 temperature and humidity sensor × 1
Male to Female jumper wire × 1

Software Apps

Arduino IDE

Interfacing SHT31 Sensor with Arduino

Step 1: Circuit

The following circuit shows how you should connect Arduino to SHT31 sensor. Connect wires accordingly.

Step 2: Installing Library

Download the SHT31 sensor library from the link below and then install.

https://www.arduino.cc/reference/en/libraries/sht31/

Tip

If you need more help with installing a library on Arduino, read this tutorial: How to Install an Arduino Library

Step 3: Code

Upload the following code to your Arduino. This code displays the temperature and humidity read in the serial monitor. You can also use the Serial plotter to draw graphs.
/*
  SHT31 Temperature & Humidity Sensor
  modified on 20 Sep 2020
  by Mohammad Reza Akbari @ Electropeak
  
Home
Based on Library Example */ #include "Wire.h" #include "SHT31.h" uint32_t start; uint32_t stop; SHT31 sht; void setup() { Serial.begin(115200); Wire.begin(); sht.begin(0x44); //SHT31 I2C Address Wire.setClock(100000); uint16_t stat = sht.readStatus(); Serial.print(stat, HEX); Serial.println(); } void loop() { sht.read(); Serial.print("Temperature:"); Serial.print(sht.getTemperature(), 1); Serial.print("\t"); Serial.print("Humidity:"); Serial.println(sht.getHumidity(), 1); delay(50); }
After running the code, you will see the following image in the serial output.
Liked What You See?​
Get Updates And Learn From The Best​

Comments (2)

  • Gary Roy Hodkinson Reply

    Mohammadreza,
    Thank you, your code works and I have learnt about i2c bus.
    Gary 29/3/2022

    March 29, 2022 at 7:13 am
    • Mehran Maleki Reply

      Hi,
      You’re quite welcome.

      April 4, 2022 at 5:33 am

Leave a Reply

Your email address will not be published. Required fields are marked *