Read Temperature with Si7021 sensor by using Sonoff TH

Hi everyone.

Please help me to read humidity and temperature from Si7021. I have Sonoff TH and use Si7021 Sensor.

I see example at Arduino Code | Adafruit Si7021 Temperature + Humidity Sensor | Adafruit Learning System

but it's not work. no show anything. Pls help me...

#include "Adafruit_Si7021.h"
Adafruit_Si7021 hum_sensor = Adafruit_Si7021();

void setup() {
  Serial.begin(115200);
  hum_sensor.begin();
}

void loop() {
      // Si7021
    float h = hum_sensor.readTemperature();
    float t = hum_sensor.readHumidity();
    Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: ");  Serial.print(t); Serial.println(" *C ");
    delay(2000); //Delay 2 sec.
}

but it's not work. no show anything.

Print something before and after trying to read the temperature, and before and after trying to read the humidity.

Do you still get nothing?

Check the return value of the begin() method. If it's false you're wiring is wrong.

PaulS:
Print something before and after trying to read the temperature, and before and after trying to read the humidity.

Do you still get nothing?

Yes. I try to print something that you recommend. Show result as below, I think it’s jack and need pin or not?

08:50:10.876 → Start print begin
08:50:11.045 → 0 Start print before
08:50:11.045 → Humidity: nan % Temperature: nan *C
08:50:11.045 → Start print after

But if i use AM2301 it’s work by this code below ( No work for Si7021 )

// Sensor AM2301, AM2302
#include <DHT.h> // Adafruit DHT
#include <Adafruit_Sensor.h> // Adafruit Unified Sensor
#define DHTPIN 14 // what pin we’re connected to
#define DHTTYPE DHT22 // DHT22 (AM2302) DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
Serial.begin(115200);

delay(5000);
dht.begin(); // Humidity and Temperature

}

void loop()
{
// AM2302
float h = dht.readHumidity();
float t = dht.readTemperature(); // Read temperature as Celsius
if (isnan(h) || isnan(t)) { Serial.println(“AM2301 - Failed to read from DHT sensor!”); }
Serial.print(“Humidity: “); Serial.print(h); Serial.print(” %\t”); Serial.print("Temperature: “); Serial.print(t); Serial.println(” *C ");

delay(2000); //Delay 2 sec.
}

Humidity: nan % Temperature: nan *C

Getting an output with nan is not the same as getting nothing!

But if i use AM2301 it's work by this code below ( No work for Si7021 )

The AM2301 (DHT22) is wired differently, it using kind of a 1-wire bus (not to be confused for a Dallas OneWire bus) but the SI7021 uses I2C. Most probably the wiring is wrong. Post a wiring diagram of your setup (may be hand drawn)!

You might need to make sure the device is powered and the ground is intact. Getting NaN means that you're likely getting garbage from the serial. Perhaps use a hex monitor to see what you're getting? Trashed data could come from bad GND and of course incorrect wiring.

pylon:
Getting an output with nan is not the same as getting nothing!

The AM2301 (DHT22) is wired differently, it using kind of a 1-wire bus (not to be confused for a Dallas OneWire bus) but the SI7021 uses I2C. Most probably the wiring is wrong. Post a wiring diagram of your setup (may be hand drawn)!

This is our circuit at IMG-7904 — ImgBB. I use Sonoff Si7021 and Sonoff model TH. Actually I have tested with old sonoff code. It's work but I try to flash via using our code. it's not work. I don't understand why is not work. I guess that about pin because all examples no use jack they use i2c as I know. If I misunderstand pls help us. :slight_smile:

Pls help me on this case if someone can read humidity and temperature.

This is our circuit at IMG-7904 — ImgBB

First: post picture here into the forum system and not to external sites that delete the link after short time frames. Second: Do you really think that this picture allows to see the circuit? Post schematics of the used components! And a wiring diagram (the white color on the connection doesn't allow to see any wiring).

pylon:
First: post picture here into the forum system and not to external sites that delete the link after short time frames. Second: Do you really think that this picture allows to see the circuit? Post schematics of the used components! And a wiring diagram (the white color on the connection doesn't allow to see any wiring).

Schematic link: Sonoff TH
https://www.itead.cc/wiki/images/3/39/Sonoff_TH10A(16A)_schmatic.pdf

Schematic link: Sensor Si7021 Humidity
https://www.itead.cc/wiki/File:Sonoff_Si7021_Sensor_Schematic.pdf

The Sonoff sensor contains an Si7021 sensor but it’s not directly connected to the Sonoff TH but by some microcontroller that seems to translate the I2C signals to a kind of one wire bus.

There are some indicators on the Itead Wiki that this single wire bus is compatible with DHT11/22 sensors. So try to read the sensor using that protocol but you won’t be successful if you request data as if it was a directly connected SI7021.