Si7021 Humidity Sensor

The Silicon Labs Si7021 [1] gives relative humidity measurements with a range of 0–80% RH and an accuracy of ±3%, and temperature measurements in the range of -10 to +85°C with an accuracy of ±0.4 °C. It uses I2C for data transfer.

It has an operating voltage range of 1.9 V to 3.6 V, so you'll need a regulator and logic-level conversion if you want to use it on a 5 V board.

A breakout board is available from Adafruit [2]:

Si7021.jpg

The I2C address is #x40 or 64.

Reading temperature and humidity

The following floating-point functions reset the device, and read temperature and relative humidity:

(defun si7021-reset ()
  (with-i2c (s #x40)
    (write-byte #xFE s))
  (delay 50)
  nil)
(defun si7021-temperature ()
  (with-i2c (s #x40)
    (write-byte #xF3 s))
  (delay 25)
  (with-i2c (s #x40 3)
    (let* ((hi (read-byte s))
           (lo (read-byte s))
           (ckecksum (read-byte s))
           (raw-temp (float (logior (ash hi 8) (logand lo #xFF)))))
      (- (/ (* raw-temp 175.72) 65536.0) 46.85))))
(defun si7021-humidity ()
  (with-i2c (s #x40)
    (write-byte #xF5 s))
  (delay 25)
  (with-i2c (s #x40 3)
    (let* ((hi (read-byte s))
           (lo (read-byte s))
           (ckecksum (read-byte s))
           (raw-humid (float (logior (ash hi 8) (logand lo #xFF)))))
      (- (/ (* raw-humid 125.0) 65536.0) 6.0))))

Thanks to Dave Astels for permission to reproduce these from his article about uLisp on the Adafruit site.


  1. ^ Si7021 Datasheet on Silicon Labs.
  2. ^ Adafruit Si7021 Temperature & Humidity Sensor Breakout Board on Adafruit.