Si7021 Based Temperature and Humidity Sensor

by Electroveins in Circuits > Sensors

9 Views, 0 Favorites, 0 Comments

Si7021 Based Temperature and Humidity Sensor

thumb.JPG

This small Si7021 fully compatible with Arduino and works on I2C interface. Has a batter resolution and measuring ability than DHT.

Supplies

mini_IMG_1712.JPG
mini_IMG_1733.JPG

Components required:

1) Si7021 module from SEEED Studio

2) Arduino NANO/ UNO

3) OLED screen

4) Battery and connection wires

Story

mini_IMG_1729.JPG

There are a lot of temperature and humidity sensors available in market. Some of them are known for their performance and other for the cheap price. DHT family is the widely used temperature and humidity monitoring sensor till now. But we can use a better option from Silabs which gives a better price to performance ratio. The size of sensor and compatibility with microcontrollers matters a lot. That’s why I am introducing a new I2C based sensor, this is Si7021. A 6-pin small sensor which can work on a 3.3v logic level.

Originally the sensor is made by Silabs and you may get one using the SMT assembly service from SEEED Fusion. Seeed fusion is provides SMT and PCBA services at a very reasonable prices. I got this free PCBA service from SEEED fusion under the ignite your passion Grove sensor competition.

SI7021 Sensor:

ice_screenshot_20221125-233852.png

The Si7021 I2C Humidity and Temperature Sensor is a monolithic CMOS IC integrating humidity and temperature sensor elements, an analog-to-digital converter, signal processing, calibration data, and an I2C Interface.

The patented use of industry-standard, low-K polymeric dielectrics for sensing humidity enables the construction of low-power, monolithic CMOS Sensor ICs with low drift and hysteresis, and excellent long-term stability. The humidity and temperature sensors are factory-calibrated and the calibration data is stored in the on-chip non-volatile memory. This ensures that the sensors are fully interchangeable, with no recalibration or software changes required.

Features:

  • Precision Relative Humidity Sensor (± 3% RH (max), 0–80% RH )
  • High Accuracy Temperature Sensor ( ±0.4 °C (max), –10 to 85 °C)
  • 0 to 100% RH operating range
  • Up to –40 to +125 °C operating range
  • Wide operating voltage (1.9 to 3.6 V)
  • Low Power Consumption (150 µA active current)
  • I2C Interface
  • Integrated on-chip heater


Circuit Diagram:

ice_screenshot_20220928-151734.png
Arduino circuit.png

The sensor comes with a 6-pin interface, in which only 4 pins are used other two are not connected. They are just to give stability to the soldering joints. In this 2 pins are for the power +VCC and GND and other two are for the digital data transfer. These Serial data and serial clock pins are pulled up using 10k resistors.

The circuit with the Arduino is also given here, the connection of screen, sensor and microcontroller are very simple. Both the screen and sensor works on I2C interface with different address. The SSH1306 OLED display is using 0X3C and SI7021 is using 0x40. At a time one address can be given to one I2C device. The circuit works on 5volts but the SI7021 sensor is supplied by onboard 3.3v Arduino regulator.

Downloads

PCB Designs and Details:

mini_IMG_1713.JPG
pcb 7021 temp and humidity.png

Here I made this PCB for the Grove sensor competition and this design with Si7021 temperature and humidity monitoring got selected. I made this PCB in Altium designer and exported the Gerber, BOM and CPL files for the assembly. Download all the required files from here.

I am using Red colour for this PCB and here I have 2 PCBA modules. Grove sensor has a dimension of 20x20mm and one dedicated Grove connector. If you want to know more about the Seeed fusion PCBA service then visit the website from here.

Code for Temp/Humidity:

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define si7021 0x40
#define OLED_RESET 1
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);

bool WireEnd() {
unsigned char err;
err = Wire.endTransmission();
if( err ) {
Serial.print("Error: ");
Serial.println(err);
}
return err;
}

void setup() {
bool err;
unsigned int data;
Serial.begin(115200);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
delay(1000);
Wire.begin();


// Reset chip
Serial.println("Starting up SI7021 sensor...");
Wire.beginTransmission(si7021);
Wire.write(0xFE);
WireEnd();
delay(100);

// Get serial
Serial.print("Serial ID: ");
Wire.beginTransmission(si7021);
Wire.write(0xFA);
Wire.write(0x0F);
err = WireEnd();
if( !err ) {
Wire.requestFrom(si7021, 8);
while(Wire.available()) {
data = Wire.read();
Serial.print(data,HEX);
Serial.print(" ");
}
Wire.beginTransmission(si7021);
Wire.write(0xFC);
Wire.write(0xC9);
err = WireEnd();
if( !err ) {
Wire.requestFrom(si7021, 6);
while(Wire.available()) {
data = Wire.read();
Serial.print(data,HEX);
Serial.print(" ");
}
}
Serial.println();
}

// Get Firmware revision
Serial.print("Firmware revision: ");
Wire.beginTransmission(si7021);
Wire.write(0x84);
Wire.write(0xB8);
err = WireEnd();
if( !err ) {
Wire.requestFrom(si7021, 1);
if(Wire.available() == 1)
{
data = Wire.read();
Serial.print(data, HEX);
Serial.println();
} else {
Serial.println("Error reading from chip");
}
}
}

void loop() {
unsigned int data[2];

// Humidity measurement
Wire.beginTransmission(si7021);
Wire.write(0xF5);
WireEnd();
delay(100);
Wire.requestFrom(si7021, 2);
if(Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
unsigned int temp = ((data[0] << 8) + data[1]);
float humidity = ((125.0 * temp) / 65536.0) - 6;

// Temperature measurement
Wire.beginTransmission(si7021);
Wire.write(0xF3);
WireEnd();
delay(100);
Wire.requestFrom(si7021, 2);
if(Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
temp = ((data[0] << 8) + data[1]);
float celsTemp = ((175.72 * temp) / 65536.0) - 46.85;

Serial.print("Humidity : ");
Serial.print(humidity);
Serial.println(" % RH");
Serial.print("Celsius : ");
Serial.print(celsTemp);
Serial.println(" C");
delay(1000);

display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10,10);
display.print("Humid:");
display.setCursor(45,10);
display.setTextSize(2);
display.print(humidity);
display.setTextSize(1);
display.setCursor(110,15);
display.print("%RH");
display.display();

display.setCursor(10,40);
display.print("Temp: ");
display.setCursor(43,40);
display.setTextSize(2);
display.print(celsTemp);
display.setTextSize(1);
display.setCursor(100,45);
display.print(" C");
display.display();

}

Libraries Used in Arduino:

ice_screenshot_20221126-222815.png
ice_screenshot_20221126-222845.png

For the screen we are using Adafruit SSD1306 and for the sensor we are using Adafruit I2C SI7021. These libraries are more stable in comparison with other 3rd party ones. Download the code from here.

Working and Testing the Sensor:

mini_IMG_1732.JPG

This sensor is working very good under normal conditions. This is small and more accurate than DHT on the other hand it is rated IP67 still there are some problems in water. You cannot directly put water on this sensor as mentioned in the datasheet. Temperature readings are much accurate and I am satisfied with the testing procedure. On a small screen and Serial monitor the real time values of temperature and humidity can be seen.