SHT40, SHT45 Humidity & Temperature Sensors
Contents
SHT4x Sensor Family Description
The SHT4x family from Sensirion is described in the datasheet as a digital platform for measuring relative humidity and temperature at different accuracies
. Current models are SHT40, SHT41, SHT43 and SHT45. The SHT40 and SHT45 are the most common to be found on breakout boards.
The sensor technology used in the SHT4x family is not explicitly stated.
Relative humidity is probably measured with a capacitive humidity sensor. This sensor consists of a hygroscopic dielectric material placed between a pair of electrodes that forms a small capacitor. The measured capacitance of the device changes as the dielectric material absorbs or loses moisture in proportion to the relative humidity of the surrounding air.
Temperature is most likely measured with a bandgap temperature sensor. This class of sensor relies upon the temperature dependent voltage characteristic of a silicon diode. They are more accurate and with better resolution than other measurement systems such as RTDs and thermocouples but don't have the extreme temperature range capability.
The product datasheet gives the typical RH% accuracy for the SHT45 as ±1.0% and other chips in the family as ±1.8%.
The typical temperature accuracy for the SHT45 is given as ±0.1°C and other chips in the family as ±0.2°.
The SHT4x is provided as an open-cavity dual flat no lead (DFN) package. The humidity sensor opening is centred on the top side of the package. The sensor chip is made of silicon, hosted on a copper-lead frame and overmolded with an epoxy-based compound. The chip is tiny, measuring only 1.5 mm x 1.5 mm.
The chip has a small onboard heater that has six different user selectable cycles. This is discussed in more details later.
The SHT4x operates on a supply voltage between 1.08V and 3.6V with a current draw of typically 320µA while taking a measurement with the heater off. It is very suitable for use with a micro:bit.
Power-up time and soft reset time (discussed later) is less than 1ms. There are three user selectable precision measurement settings. Even at the highest setting, measurement time is less than 10ms.
Communication with a microcontroller is through serial I2C. There are 11 different commands that can be written to the sensor by the microcontroller master. A command is issued by writing a single byte code to the sensor.
In all cases but one (the soft reset), a response of six bytes is then read back from the sensor. It's important to allow time for the sensor to respond to the command before requesting these six bytes.
The sensor calculates a checksum on each two bytes of measurement data. The user can optionally use the checksum to confirm the validity of the sensor data.
SHT4x Breakout Boards
The chip comes in a DFN package with no leads so is definitely not breadboard friendly. So, it's much more convenient for the hobbyist to purchase one of these sensors on a breakout board. The most commonly found are SHT40 and SHT45 boards. FIG 1 shows such a board, universally available for a (very) few dollars.
Fig 1 - Both sides of the SHT45 breakout board
These sensor chips are tiny. About the only way to determine which one is on the breakout board is to view the chip under a digital microscope.
The breakout boards all have the same layout and components regardless of which sensor chip (SHT40 or SHT45) is onboard. There is a bypass filter capacitor and 10kΩ pullup resistors on the two I2C pins.
SHT4x Breakout Board Pinout
All four pins of the SHT4x chip are brought out on the module board:
- VIN - Connect to 3.3V on the micro:bit.
- GND - connect to GND on the micro:bit.
- SCL - I2C Clock signal, connect to pin19 on the micro:bit.
- SDA - I2C Bidirectional data line, connect to pin20 on the micro:bit.
The two I2C pins on the module should be connected to the pins on the micro:bit as given in the above table. The two pins, pin19 and pin20 are reserved for I2C on the micro:bit.
These pin assignments are the defaults for the MicroPython driver discussed below.
Accessing the SHT4x Sensor
The microcontroller interacts with the sensor via standard I2C. SHT4x breakout boards come with the fixed slave address of 0x44. Communicating with the SHT4x sensor is very simple. A command (1 byte) is written to the sensor. Then (except in the case of the soft reset command) six bytes are received back.
The product datasheet on page 3 provides example code. These sensors really are simple to use.
Reading Humidity and Temperature
The SHT4x sensor can be instructed to take relative humidity and temperature readings at one of three possible precisions; highest, medium or lowest. As would be expected, the highest precision reading takes the longest to complete with a maximum time of 8.3ms while the lowest precision is the quickest at a mere 1.6ms maximum time.
The sensor identifies which precision is required by the command that is written to it via the I2C bus. Six byes are then read from the sensor after allowing for sufficient measurement time. These six bytes include:
- A two-byte raw temperature signal output
- A single-byte checksum
- A two-byte raw humidity signal output
- A single-byte checksum
Whether the user program calculates checksums and compares them to the sensor provided checksums is entirely optional.
The digital sensor signals are converted to temperature (°C) and humidity (RH%) with formulas provided on page 12 of the datasheet.
Onboard Heater
The onboard heater is provided for two purposes:
- The heater raises the measured temperature and humidity. If the read values don't change accordingly after the heater cycle completes then it's obvious there is a problem with the sensor chip.
- The sensor can return out of range readings in a high humidity environment. Initiating a heating cycle may 'cleanse' the sensor surface allowing the resumption of reliable measurements.
There are three power settings to choose from (200mW, 110mW and 20mW) and two possible heating durations (1s and 0.1s).
The desired combination of power setting and duration is selected by writing the appropriate 1-byte command to the sensor. This initiates the heating cycle.
The sensor takes a temperature and humidity reading just as the heating cycle is completing. This is read back by the microcontroller as six bytes and are in the same format as described above.
Experimentation shows that a heating cycle does raise the temperature by a few degrees but the chip quickly cools back to ambient air conditions.
Serial Number
Each individual sensor chip is assigned a unique 32-bit serial number during manufacture. This can be obtained from the chip by issuing a 1-byte command then reading back six bytes. The six bytes consist of the serial number (four bytes) and two x 1-byte checksums.
Soft Reset
A very rapid soft reset can be performed on the sensor chip by writing the reset 1-byte command. There is no return value to be read after the reset has completed.
MicroPython Driver for micro:bit
A SHT4x sensor family MicroPython driver specifically for the micro:bit has been developed as part of this series on MicroPython for the microbit. The driver webpage also provides a detailed description of the driver's methods with sample code.
The driver allows a user to easily connect and control one or more of these sensors from a micro:bit.
The SHT4x driver is implemented as a class. This is by far the most versatile approach as a program can use the class to instantiate more than one physical SHT4x module, all independent of each other. It is also easy for a knowledgeable user to extend the class.
The I2C slave address of the SHT4X is 0x44 and is fixed at the point of manufacture[1]. There are no options on the chip to change this address. So, if more than one of these sensors needs to be connected to the I2C bus of a microcontroller then a multiplexer is required.
The wellknown TCA9548A multiplexer is described here. A TCA9548A MicroPython driver which includes a code example of six SHT40/SHT45 sensor modules connected to the same bus can be found here.
The SHT4x driver implements the full function set of this chip family. Included are methods that allow the user to:
- Read the relative humidity and temperature. Checksum validation is available.
- Fully utilise the onboard heater.
- Read the sensor's serial number.
- Perform a soft reset of the sensor.