I am using SHT21 temp sensor with ESP32 using I2C. The sensor only reports temp of -273 and 0 for RH. The sensor is not faulty as I have tried this on an Arduino UNO with the same sketch and it works fine. I am using the default data and clk pins on ESP 32. Also I tried it on a different ESP32 board as well as powering the sensor from the ESP32 and externally but still get incorrect readings. I suspect it is more of a software issue than a hardware one. Could you please help me find the cause?

Here is my sketch:

#include <Wire.h>
#include <Sodaq_SHT2x.h>

void setup()

void loop()
  Serial.print("Humidity(%RH): ");
  Serial.print("     Temperature(C): ");
  Serial.print("     Dewpoint(C): ");
  • 1
    Maybe there is some MCU-specific code in the Sodaq_SHT2x library, such that maybe one section might compile for an Uno while another might compile for an ESP. That and connectivity, voltages, etc. seem to be the only differences. I agree that your own code should run on either MCU. – JRobert Aug 8 '20 at 13:44
  • 1
    "so far using sensors on I2C bus is giving me a lot of issues" sounds like a clue, doesn't it? Especially if other sensors have given you the same problem. If that's the case, your issues sound very likely related to differences in hardware compatibility such as voltages, supply capability, connections, choice of ESP pins - something that is different about the ESP that applies consistently across the various sensors, and less likely to be software related. Has any sensor worked with ESP32 and I2C? – JRobert Aug 8 '20 at 13:54
  • 1
    @Zaffresky that sounds solid - you wouldn't believe the number of people who wire stuff up and don't hook up GND or something like that... :) the only other issue there I can think of is if the wires are really long; that can cause issues with I2C. I'd try a different library that's known to work with the ESP32 - Adafruit and Sparkfun are both very good about this but unfortunately they don't seem to have an SHT21 library. FWIW, I've used BME280s with the ESP32 extensively with no problems. – romkey Aug 8 '20 at 18:14
  • 1
    There's a small chance that adding pull-up resistors to SCL and SDA might help - the ESP32's internal pull-ups are quite weak. A 47K resistor between SCL and 3.3V and SDA and 3.3V might make a difference. – romkey Aug 8 '20 at 18:16
  • 1
    The two main issues I encounter with sensors/I2C and different board types are that the needed pullups are different for 5V and 3.3V parts/systems, and if the library is written for AVR (i.e. Uno) it may not work properly on a ESP8266, etc, due to variances in the architecture, etc. So it's always good to try a few libraries, especially if you were able to detect the i2c device using the scanner sketch ;) – Peter Feerick Aug 10 '20 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.