In this tutorial we are going to interface Silicon Labs’ Si7021 I2C humidity and temperature sensor to Arduino.
Si7021 is a great replacement for the DHT22.
Why the Si7021?

If you need a humidity sensor, you probably stumbled on tutorials that are using a DHT22 or DHT11. These sensors are not very precise and not very reliable for hobbyists. If you’re in need of a homemade weather station, I strongly vouch for the all digital, I2C Si7021. It features:
- ± 3% humidy precision (at worst)
- ± 0.4°C (at worst) temperature precision from –10 to 85°C (14 to 185°F)
- Operates on full humidity range (0 to 100%) and from -40 to 125°C
- Serial I2C interface!
You can get a module of the chip on Aliexpress for about US$3 shipping included.
Connecting the sensor to Arduino
The Si7021 module is I2C, which means wiring it is fairly easy:
- Connect the VCC pin to 3.3V and GND to GND on your Arduino.
- Connect SDA/SCL (serial data/serial clock) to the matching pins on your Arduino.

Your module should clearly states on the front or back the pinout. If you don’t have a SDA or SCL pin on your Arduino this means you are using an older version of the Uno or another micro controller entirely.

You should refer to the documentation of your microcontroller for I2C, but here are some popular boards I2C pins:
Board | SDA pin | SCL pin |
Uno | A4 | A5 |
Mega2560 | 20 | 21 |
Leonardo | 2 | 3 |
Due | 20 | 21 |
On other popular microcontrollers such as the ESP8266 you can directly specify which pin you wish to use for SDA and SCL.

Reading data from the sensor: Si7021 library
Adafruit originally released a library for the sensor; which you can still find here. It doesn’t support all the features the Si7021 has to offer though (built-in heater, changing resolution & reading temperature from humidity to name them). As a result, I made my own library, which is feature complete and is available here for download.
Download the Si7021 Arduino library
The library is very easy to use and has a set of dedicated functions:
- measureHumidity forces a humidity measurement. Take up to 25ms
- measureTemperature & measureTemperatureF forces a temperature measurement.
- getTemperatureFromPreviousHumidityMeasurement & getTemperatureFromPreviousHumidityMeasurementF gets the temperature from a previous humidity measurement (see below)
Every time you ask the sensor to measure the humidity, the chip also performs a temperature measurement; as relative humidity highly depends on the temperature. As such, you can simply retrieve this temperature by calling the function getTemperatureFromPreviousHumidityMeasurement. Unless you have a good reason, you should never make a direct call to measure temperature; it is a waste of time.
Once the library is installed you can simply load the “Simple_Example” sketch: it will display every 500ms the temperature and humidity.
#include "Si7021.h" Si7021 si7021; void setup() { uint64_t serialNumber = 0ULL; Serial.begin(115200); si7021.begin(); serialNumber = si7021.getSerialNumber(); //arduino lib doesn't natively support printing 64bit numbers on the serial port //so it's done in 2 times Serial.print("Si7021 serial number: "); Serial.print((uint32_t)(serialNumber >> 32), HEX); Serial.println((uint32_t)(serialNumber), HEX); //Firware version Serial.print("Si7021 firmware version: "); Serial.println(si7021.getFirmwareVersion(), HEX); } void loop() { Serial.print("Humidity: "); Serial.print(si7021.measureHumidity()); Serial.print("% - Temperature: "); Serial.print(si7021.getTemperatureFromPreviousHumidityMeasurement()); Serial.println("C"); delay(500); }
Additionally, you can get extra information like your device serial number and firmware revision number.
Going further: the heater
In order to be exhaustive with this sensor, I have to mention the heater. Indeed, the Si7021 comes with a “defogger/dehumidifier” in the form of a small heating resistance you can control via a special I2C command. And as you can see below, the effects are pretty dramatic; going from a 82% RH to 66% in about 10s; while the temperature rose by 10 degrees Celsius:

This is a very useful feature if your sensor lies in very high humidity (such as the tropical climate of Singapore where I obtained these numbers above!). To use this feature, you just have to call:
si7021.setHeater(true, param);
Where param is a value between 0x00 and 0x0F (0 to 15). Be very warned that using the resistor draws power. The 3.3V pin of a typical Arduino Uno can only provide up to 50mA of current so be careful if you are powering up the sensor from your Arduino board.
Here’s the typical power consumption for different values:
Heater | Current Draw (mA) |
0x00 | 3.09 |
0x01 | 9.18 |
0x02 | 15.24 |
0x04 | 27.39 |
0x08 | 51.69 |
0x0F | 94.2 |
Do not exceed 0x04 or you risk frying the 3.3V regulator.
Conclusion
We have now covered all features offered by the Si7021. I haven’t talked about “setSensorResolution” because by default the sensor is already calibrated to offer its maximum resolution; but I’d advise you to get the datasheet and read the library source code if you wish to dig even deeper.
I’m convinced this is the best sensor for typical weather projects; but I’d be delighted to hear your thoughts on this. For now, enjoy your sensor!