SHT3X Temperature and Humidity sensor Interfacing with ESP8266

(Last Updated On: July 24, 2020)

Introduction:

In this tutorial, we will design and develop a Digital Thermometer and Hygrometer Meter With Oled Display. For this, we will be Interfacing SHT3X Temperature and Humidity sensor with ESP8266.

Various Sensors are available to sense humidity and temperature but when we need small size and low power consuming sensor only a few stand out, here we have taken the sensor SHT31 from sensirion for sensing humidity and temperature, It can be fully calibrated and I2C Interface available with communication speeds up to 1 MHz and two user-selectable addresses (0x44 or 0x45). It provides a very fast start-up and measurement time. Sensor SH31 Arduino interface can be done through the breakout board.

In the previous article, we have interfaced SHT31 with Arduino check out here. Also, We have interfaced with ESP32 Checkout here.

Digital Humidity Sensor SHT3x (RH/T)

The digital SHT3x humidity sensor series takes sensor technology to a new level. As the successor of the SHT2x series, it sets the industry standard in humidity sensing. The SHT3x humidity sensor series consists of a low-cost version with the SHT30 humidity sensor, a standard version with the SHT31 humidity sensor, and a high-end version with the SHT35 humidity sensor. Automotive-grade versions are also available. The SHT3x humidity sensor series combines multiple functions and various interfaces (I2C, analog voltage output) with an applications-friendly, very wide operating voltage range (2.15 to 5.5 V). The SHT3x humidity sensor is available in both large and small volumes.

 

SHT31

Features

Size 2.5 x 2.5 x 0.9 mm
Output I²C, Voltage Out
Supply voltage range 2.15 to 5.5 V
Energy consumption 4.8µW (at 2.4 V, low repeatability, 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%)

 

0.96″ I2C OLED Display:

This is a 0.96 inch blue OLED display module. The display module can be interfaced with any microcontroller using SPI/IIC protocols. It is having a resolution of 128×64. The package includes display board, display,4 pin male header pre-soldered to board.

OLED (Organic Light-Emitting Diode) is a self light-emitting technology composed of a thin, multi-layered organic film placed between an anode and cathode. In contrast to LCD technology, OLED does not require a backlight. OLED possesses high application potential for virtually all types of displays and is regarded as the ultimate technology for the next generation of flat-panel displays.

128x64-Blue-I2C-OLED-Display

Specifications:

  • OLED Driver IC: SSD1306
  • Resolution: 128 x 64
  • Visual Angle: >160°
  • Input Voltage: 3.3V ~ 6V
  • Compatible I/O Level: 3.3V, 5V
  • Mini Size: 2.7 x 2.8cm
  • Only Need 2 I/O Port to Control
  • Fully Compatible with Arduino
  • Working temperature: -30°C ~ 70°C
  • Module volume ( generous ): 27.0 x 27.0 x 4.1mm
  • Factory configured for SPI protocol (can be easily changed to IIC)

For more information about the SSD1306 OLED Display, check out this datasheet.

 

 

Circuit Diagram: Interfacing SHT3X Temperature and Humidity sensor with ESP8266

 

SHT31_ESP8266

 

Source Code: Interfacing SHT3X Temperature and Humidity sensor with ESP8266

Here is a source code for interfacing SHT3x with ESP8266 for reading humidity and Temperature. Copy the code and paste it in on the ArduinoIDE. Before going to upload the code Install all the libraries. You download the libraries from the links provided beside the library in the code.

#include "Adafruit_SHT31.h" //https://github.com/adafruit/Adafruit_SHT31/archive/master.zip
Adafruit_SHT31 sht31 = Adafruit_SHT31();

#include <Wire.h>
#include <Adafruit_GFX.h> //https://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_SSD1306.h> //https://github.com/adafruit/Adafruit_SSD1306

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
      Serial.begin(9600);
      delay(10);
      Serial.println("SHT31 test");
      if (! sht31.begin(0x44)) {   // Set to 0x45 for alternate i2c addr
      Serial.println("Couldn't find SHT31");
      while (1) delay(1);
      }

        if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  delay(2000);
  display.clearDisplay();

}

void loop() {
  
    float t = sht31.readTemperature();
    float h = sht31.readHumidity();
    
    if (! isnan(t)) {  // check if 'is not a number'
    Serial.print("Temp *C = "); Serial.println(t);
    }
    else {    
    t=0.0;
    Serial.println("Failed to read temperature");
    }
    
    if (! isnan(h)) {  // check if 'is not a number'
    Serial.print("Hum. % = "); Serial.println(h);
    }
    else { 
    h=0.0;
    Serial.println("Failed to read humidity");    
    }
    Serial.println();
    delay(500);

display.clearDisplay();
    
    // display temperature
    display.setTextSize(1);
    display.setCursor(0,7);
    display.print("Temperature: ");
    display.setTextSize(2);
    display.setCursor(0,18);
    display.print(t);
    display.print(" ");
    display.setTextSize(1);
    display.cp437(true);
    display.write(167);
    display.setTextSize(2);
    display.print("F");
    
    // display humidity
    display.setTextSize(2);
    display.setCursor(0, 45);
    display.print(h);
    display.print("%");
    display.setTextSize(1);
    display.setCursor(74, 50);
    display.print(" ");
    display.print("Rel H");  
    display.display(); 
}

Output:

On Serial Monitor:

SHT3x_ESP32

On OLED Display:

 

Leave a Reply