Si7021 Temperature and Humidity Sensor is Reading Wrong Sensor Values!

I am using Si7021 silicon lab's temperature and humidity sensor and APD300 light sensor together in my PCB board, I am also using STM32F103 Arduino compatible microcontroller which communicates the sensors through the I2C protocol, I have tested it before and the sensors were reading the correct sensor data in the Arduino Serial monitor, but now my humidity and temperature sensor is reading way too much values like "219982828282 C" even though I am using the correct pull-up resistors, I was wondering if there is something wrong with the code I am using (Found it from the internet). I have attached the source code I used and the serial monitor output of my sensors.

#include <Wire.h>

// SI7021 I2C address is 0x40(64)
#define Addr 0x40

void setup()
{
// Initialise I2C communication as MASTER
Wire.begin();
// Initialise serial communication, set baud rate = 9600
Serial.begin(9600);

// Start I2C transmission
Wire.beginTransmission(Addr);
// Stop I2C transmission
Wire.endTransmission();
delay(300);
}

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

// Start I2C transmission
Wire.beginTransmission(Addr);
// Send humidity measurement command, NO HOLD MASTER
Wire.write(0xF5);
// Stop I2C transmission
Wire.endTransmission();
delay(500);

// Request 2 bytes of data
Wire.requestFrom(Addr, 2);

// Read 2 bytes of data
// humidity msb, humidity lsb
if(Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}

// Convert the data
float humidity = ((data[0] * 256.0) + data[1]);
humidity = ((125 * humidity) / 65536.0) - 6;

// Start I2C transmission
Wire.beginTransmission(Addr);
// Send temperature measurement command, NO HOLD MASTER
Wire.write(0xF3);
// Stop I2C transmission
Wire.endTransmission();
delay(500);

// Request 2 bytes of data
Wire.requestFrom(Addr, 2);

// Read 2 bytes of data
// temp msb, temp lsb
if(Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}

// Convert the data
float temp = ((data[0] * 256.0) + data[1]);
float cTemp = ((175.72 * temp) / 65536.0) - 46.85;
float fTemp = cTemp * 1.8 + 32;

// Output data to serial monitor
Serial.print("Relative humidity : ");
Serial.print(humidity);
Serial.println(" % RH");
Serial.print("Temperature in Celsius : ");
Serial.print(cTemp);
Serial.println(" C");
Serial.print("Temperature in Fahrenheit : ");
Serial.print(fTemp);
Serial.println(" F");
delay(500);
}

Arduino Serial Monitor Output

Illumination: 101
Relative humidity : 65802760.00 % RH
Temperature in Celsius : 92502848.00 C
Temperature in Fahrenheit : 166505152.00 F

Check his library - Arduino library for SHT21, HTU21D & Si70xx Digital Humidity and Temperature Sensor

It returns 255, if there is a CRC8 mismatch or a communication error has occurred.

First: Use code tags to post code! (That's the </> button in the editor)

 // Start I2C transmission
  Wire.beginTransmission(Addr);
  // Send humidity measurement command, NO HOLD MASTER
 Wire.write(0xF5);
  // Stop I2C transmission
  Wire.endTransmission();
  delay(500);

  // Request 2 bytes of data
  Wire.requestFrom(Addr, 2);

Why the hell do you wait half a second between selecting the register and reading it? In the highest resolution the sensor needs less than 15ms to gather the data.

unsigned int data[2];

If you read byte values you shouldn't use uint16_t typed variables, especially if you don't check for failures before reading.

Looks like a wiring problem. Check your wires (replace them by good ones), post a wiring diagram if it still doesn't work.

Thanks, I don't have any wiring problem as I am using A PCB card and I just solder the sensors to my PCB card, is there any chance that my sensor is broken?

Ayanle17:
I have tested it before and the sensors were reading the correct sensor data in the Arduino Serial monitor, but now my humidity and temperature sensor is reading way too much values like "219982828282 C"

What changed in the time between when "the sensors were reading the correct sensor data" and "sensor is reading way too much "?

first I was using a small module I designed for the sensor using DIPTrace card and I was connecting the sensor to STM32F103 blue pill board through wires, now I made another PCB card for both STM32F103 chip and the sensors , both sensors are communicating with the microcontroller through I2C protocol, my light sensor (APDS-9300) is now working and reading the light intensity data while the temperature sensor(si7021) is reading wrong data.

Each i2c sensor has unique ID address from 10 to 256. It' is no a lot. So some times two different sensors may have same ID. By the way, similar sensor always have the same ID.

When master (arduino) trying to talk with salves(sensors) it broadcasts ID first. My library does the same - it transmit the ID and listen for the sensor answer, and throws the error message if no answer.

possible issues:

  • you do not have pull up resistors
  • your data lines are to long
  • two or more sensor on the I2C bus has the same ID
  • you connect sensor wrong
  • your sensor toasted

I don't have any wiring problem as I am using A PCB card and I just solder the sensors to my PCB card

Why should that eliminate a wiring problem? It doesn't make a difference if the wiring is with wires or PCB traces. They could be wrong.

If you don't use wires, post schematics of your custom PCB!

is there any chance that my sensor is broken?

That's possible but we cannot tell we don't have any information about your hardware.