Si7021 Humidity and Temperature Sensor Hookup Guide a learn.sparkfun.com tutorial
Available online at: http://sfe.io/t467
Introduction
The Si7021 is a low-cost, easy to use, highly accurate, digital temperature and humidity sensor. All you need is two lines for I2C communication, and you’ll have relative humidity readings and accurate temperature readings as well! This sensor is ideal for environmental sensing and data logging, perfect for a weather station or humidor control system.
The Si7021 also comes equipped with a hydrophobic PTFE filter covering the inlet on the sensor. This filter blocks contaminants but allows water vapor to pass through, keeping your sensor safe from water damage while still proving accurate sensor readings.
Required Materials
To follow along with this hookup guide, you will need the following:
Suggested Reading
Before embarking upon this tutorial, you may find the following links useful:
- I2C Protocol
- Logic Levels
- Installing an Arduino Library
- What are Pull-up Resistors?
- How to use a Breadbaord
Board Overview
Let’s go over the Si7021 Breakout in detail.
Si7021 Details:
- Uses the I2C interface
- Typical humidity accuracy of ±2%
- Typical temperature accuracy of ±0.3C
- Operates from 0 to 100% humidity but this sensor isn’t recommended for harsh environments where it could come in contact with water (such as rain)
- 3.3V sensor - use inline logic level converters or 10kΩ resistors to limit 5V signals
- Only one Si7021 sensor can reside on the I2C bus at a time
Pull-up Resistors
This breakout board has built-in 4.7KΩ pull up resistors for I2C communications. If you’re hooking up multiple I2C devices on the same bus, you may want to disable/enable the pull-up resistors for one or more boards. On the Si7021, the pull-ups are enabled by default. To disable them, simply use some solder wick to remove the solder on the jumper labeled PU. This will disconnect the resistors from VCC and from the I2C bus.
PTFE Filter
The tiny white cover on the IC is known as a Polytetrafluorethylene (PTFE) Membrane Filter. It keeps moisture out but allows humidity in. This filter is very low-profile, hydrophobic and oleophobic, and excludes particulates down to 0.35 microns in size.
From the Si7021 datasheet:
“Because the sensor operates on the principal of measuring a change in capacitance, any changes to the dielectric constant of the polymer film will be detected as a change in relative humidity. Therefore, it is important to minimize the probability of contaminants coming into contact with the sensor. Dust and other particles as well as liquids can affect the RH reading.”
Image courtesy of Silicon Labs datasheet
Hooking It Up
Wiring up the Si7021 is very easy! We recommend soldering four male headers to the breakout board. You can also solder wires if your application needs.
Power
This board runs at 3.3V. Be sure to power the board from the 3.3V pin! Because I2C is an open drain signal, there’s no need to worry about level shifting the signal; the 3.3V signal will be adequate to communicate with the Arduino and the signal will never reach a dangerous level for the pins on the Si7021.
Connections: Breakout to Arduino
Method 1
There are two ways to connect an Si7021 to an Arduino. The first is using pins A4 and A5 on classic Arduino boards. This breakout was designed using our standard I2C pinout, allowing the sensor to be connected directly to an Arduino without using a breadboard or wires.
- GND → A2
- VCC → A3
- SDA → A4
- SCL → A5
This would look like the following:
If using this wiring scheme, be sure to assign pins A2 and A3 as GND and VCC, respectively, in your code.
Method 2
This method is for those with newer model Arduino boards that have the SDA and SCL lines broken out. We’ll be hooking up VCC and GND to the normal power pins and two data lines for I2C communication. Connect the SDA and SCL lines directly to the SDA and SCL lines broken out on the Arduino headers.
- VCC → 3.3V
- GND → GND
- SDA → SDA
- SCL → SCL
This would look something like the following:
Si7021 Library and Example Code
To get started immediately, use the example code and library files below.
NOTE: For this example, we're hosting the code on codebender, which not only features code-sharing, but also allows anyone to upload and debug Arduino sketches from within a web browser. Plus, it works on lower-tech machines, like Chromebooks!
There are codebender plugins for Chrome, Chromium, and Firefox. Visit the codebender plugin page for help installing the codebender plugin.
Once you’ve uploaded the code, connect using this serial terminal to see the output.
If you prefer to work in the Arduino IDE, you can download the library from the link below. Check out our Installing an Arduino Library tutorial for more help.
Once the library is installed, open Arduino, and expand the examples menu. You should see the Si7021 example.
The examples menu expanded to show Si7021 example
Si7021 Functions:
Weather::getRH()
- Returns current Relative Humidity measurement.
Weather::readTemp()
- Returns temperature in Celsius from previous RH measurement.
Weather::getTemp()
- Returns current temp in Celsius.
Weather::readTempF()
- Returns temperature in Fahrenheit from previous RH measurement.
Weather::getTempF()
- Returns current temp in Fahrenheit.
Weather::changeResolution()
- Allows the user to change the humidity and temperature resolution. The vast majority of users do not need to change the resolution. By default the sensor will be in its highest resolution settings. This function is useful if you need to decrease the amount of time between readings or to save power. See the datasheet for more information. As an example, to change the resolution to 11 bit RH and 11 bit temperature, you would call myHumidity.SetResolution(0b10000001); to set bit 7 and bit 0.
Resolution table can be found on page 25 of the datasheet.
Resources and Going Further
With that, you should now have a functional humidity and temperature sensing system. Check the links below for more information.
- Si7021 Datasheet
- Si7021 Breakout Board Schematic
- Si7021 Breakout Board Eagle Files
- Github repo containing all the latest files and code
Need some inspiration? Check out these other tutorials:
- Make an automated terrarium that manages heat and humidity levels.
- Build a humidor control box that maintains a constant humidity in a controlled space.
HTU21D Humidity Sensor Hookup Guide
MPL3115A2 Pressure Sensor Hookup Guide
Weather Shield Hookup Guide
learn.sparkfun.com |CC BY-SA 3.0 | SparkFun Electronics | Niwot, Colorado