Integrating the HTU21D humidity and temperature sensor into a project is straightforward. For this project, the HTU21D’s sensor results will be displayed with a single Adafruit 24 NeoPixel Ring. Both temperature and humidity results will be displayed simultaneously.
By default the HTU21D sets the temperature and humidity sensor resolutions are set at their highest. These default values are, humidity = 12bit and temperature = 14bit. This is all well and good for most situations when you are trying to get the best performance from your device. However, a higher resolution comes at the expense of increased measuring time. Consequently, a longer measuring time will increase the current consumption too.
To demonstrate, I’ve tabulated the maximum measuring times for the different sensor resolution modes from the HTU21D_datasheet.
Having both temperature and humidity sensor capabilities in a single package makes the HTU21D an ideal sensor for a home weather station. As such, if you’re a person who is interested in knowing the current weather conditions, you’ll probably want to know what the Dew Point is too. But before we can get carried away, we need to learn how to use an additional library.
If you’ve missed out on part 1 of this tutorial, you can catch up here.
If you closely read the HTU21D_datasheet, you’ll realise that the humidity data that you read directly from the HTU21D sensor does not meet the device’s guaranteed humidity accuracy of +-3%. Additionally, the sensor is only optimised to perform in the range of 5-95%RH, the rated accuracy of +-3% only applies between 20-80%RH.
This excerpt from the datasheet shows the device’s range of performance.
This tutorial will show you how to interface your Arduino to a HTU21D humidity and temperature sensor and start taking measurements. Once you’ve got the basics, we’ll take a look at configuring the sensor to optimise its performance. What you’ll need:
- An Arduino or compatible clone
- A HTU21D temperature sensor. I’ll be using one of these from Adafruit.
- Jumper wires
A few days ago, my HTU21D temperature and humidity sensor from Adafruit arrived in the mail. I’m planning to use it for a temperature and humidity display at home.
In one night I managed to start reading temperature and humidity measurements from the sensor using my own code that uses the Arduino Wire library. I wrote my own code instead of using the Adafruit HTU21D library to practice and learn interfacing a micro to an I2C device. All the measurement results are then output to the serial terminal.