Demonstration / Test program for HTU21D Humidity / Temperature sensor

PhilHornby

Senior Member
Demonstration / Test program for HTU21D Humidity / Temperature sensor (V2)

HTU21D Humidity / Temperature Sensor Demonstration / Test Program

There are several threads in the forum regarding this sensor - this seeks to expand on the information found therein.

See: http://www.picaxeforum.co.uk/showthread.php?26344-Integrating-HTU21D-temperature-humidity-sensor-using-I2c-using-18m2/page2

and http://www.picaxeforum.co.uk/showthread.php?26354-HTU21D-Maths-question

Manufacturer's datasheets:-

(Main) http://www.amsys.info/sheets/amsys.en.htu21d.pdf and (Serial no. information) http://www.amsys.info/sheets/amsys_fan001.pdf

The attached code was developed on a Picaxe 20X2 (running @ 3V to match the HTU21D). It contains some 20X2-specific features (I²C SFR references and Picaxe-basic instructions). The minimum circuit is simply the 20X2 connected to the HTU21D via the I²C bus wires (SDA/SCL). I used a ready-made module containing the HTU21D and the I²C pull-up resistors. The resistors needed to be connected via pads on the module. I have also included the schematic for running the Picaxe @ 5V, with the HTU21D at its maximum of 3.3V. In this case, the SCL/SDA pull-up resistors must be connected to the 3.3V line NOT the 5V line.

The program demonstrates the following features (in addition to retrieving basic Humidity / Temperature readings) :-

  1. R.H. compensated for temperature, when readings are in the range 0º to 80ºC.
  2. Diagnostic Heater operation. This is turned on for 30 seconds when the program starts, so you should see the readings fall back towards ambient, over a period of 5 minutes or so.
  3. Unique Serial Number decoding.
  4. Testing for the device presence on the I²C bus.
  5. PSU status (as monitored by the HTU21D)
  6. CRC checking of the received data. In tests, CRC errors have been very, very rare - but they have occurred.

Sample output :-

Code:
HTU21D - Diagnostic / Demo 
HTU21D Serial = 0x48540053F7B33211

Heater turned ON for 30 secs. Please wait 
Heater turned OFF, monitoring 
Temperature: 25.0c Humidity: 33% adj. -0.000% Comp. Humidity: 33% 
Temperature: 23.3c Humidity: 37% adj. -0.255% Comp. Humidity: 37% 
Temperature: 23.0c Humidity: 37% adj. -0.300% Comp. Humidity: 37% 
Temperature: 22.9c Humidity: 38% adj. -0.315% Comp. Humidity: 38% 
Temperature: 22.8c Humidity: 38% adj. -0.330% Comp. Humidity: 38% 
Temperature: 22.7c Humidity: 38% adj. -0.345% Comp. Humidity: 38% 
Temperature: 22.6c Humidity: 38% adj. -0.360% Comp. Humidity: 38% 
Temperature: 22.6c Humidity: 38% adj. -0.360% Comp. Humidity: 38% 
Temperature: 22.6c Humidity: 38% adj. -0.360% Comp. Humidity: 38%
Demo Circuit.png
 

Attachments

Last edited:
Top