SHT31 Sensor Library for Proteus V1.1: two Arduino UNOs with purple GY-SHT31-D boards, the SHT31 Advance pop-up Sensor page at FRIDGE with 4.0 C, 85.0 % and a dew point of 1.7 C, and the TEP Serial Monitor in its Simple interface

SHT31 Sensor Library for Proteus V1.1 (Temperature + Humidity Sensor + Arduino)

2.5K Views
40
700
60
25
60
PCBWay

Hello friends, I hope you all are doing great. Today, I am going to share the new SHT31 Sensor Library for Proteus V1.1. The SHT31 from Sensirion is a small digital temperature and humidity sensor, best known on the purple GY-SHT31-D board. With this SHT31 Sensor Library for Proteus, you set the temperature and the humidity with presets, sliders or a click on the thermometer or the water drop, and your Arduino reads them over I2C with the same Adafruit SHT31 library you use on real hardware.

Version 1.1 replaces the first version of this post. You now get two devices: SHT31 Simple, with a control panel on the schematic, and SHT31 Advance, with a pop-up window and four measured sensor test tools. The model adds the ALERT pin, a heater that really warms the sensor and the real response time. The new SHT31 Arduino Proteus demo runs on two Arduino UNOs with the dew point and a humidity alarm LED, shown in the compact Simple interface of our TEP Serial Monitor. Have you read version 1.0? Then jump to "What's New" below.

NOTICE: This library is very special to our team. Our SHT31 model has the sensor's command protocol with its real measurement times, the CRC on every word, the status word, the heater and the alert mode with the ALERT pin, and it speaks I2C to the unmodified Adafruit library. It took our team a lot of hard work, many test runs and many design changes. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below or in the SHT31 Library board of our forum. And if our free libraries help you, you can buy us a coffee. So, let's get started with the SHT31 Sensor Library for Proteus:

SHT31 Sensor Library for Proteus V1.1: two Arduino UNOs with purple GY-SHT31-D boards, the SHT31 Advance pop-up Sensor page at FRIDGE with 4.0 C, 85.0 % and a dew point of 1.7 C, and the TEP Serial Monitor in its Simple interface
Figure: The SHT31 demo in Proteus 8.5: NODE 1 (Simple) and NODE 2 (Advance), U2's Sensor page at FRIDGE (status word 0x8010), U4 printing "Temperature: 4.0 C | Humidity: 85.0 %" and "Dew point: 1.7 C", and U2's humidity alarm LED D2 lit.

What is the SHT31 Temperature and Humidity Sensor?

The SHT31, made by Sensirion, is a digital temperature and humidity sensor of the SHT3x-DIS family. It sends the air temperature and the relative humidity to your Arduino over I2C, the 2-wire bus with a clock line (SCL) and a data line (SDA), each value with a checksum. For the commands, the timing and the formulas, see Sensirion's SHT3x-DIS datasheet.

Relative humidity compares the water vapour in the air with the most the air could hold at that temperature. Warm air can hold more, so the same air shows a lower relative humidity when it gets warmer. Keep that in mind for the heater below.

The SHT31 at a Glance

SHT31 in numbers
FeatureValue
MeasuresTemperature and relative humidity, as two 16-bit words
InterfaceI2C, standard and fast mode; address 0x44 (ADDR low) or 0x45 (ADDR high)
ChecksumA CRC-8 after every 16-bit word (polynomial 0x31, start value 0xFF)
Single shotOne measurement per command; high / medium / low repeatability: 12.5 / 4.5 / 2.5 ms typical, 15.5 / 6.5 / 4.5 ms maximum
Periodic mode0.5, 1, 2, 4 or 10 measurements per second; read with Fetch Data, stopped with Break; ART = 4 per second
Status wordAlert pending, heater, humidity / temperature alert, reset detected, command and CRC errors
HeaterA small heater on the chip, switched by a command
ALERT pinActive high (push-pull), set by four limits, only in periodic mode
Board pinsVIN, GND, SCL, SDA in a row on the GY-SHT31-D, AD and AL as separate pads
SupplyThe sensor runs on 2.4 to 5.5 V; the GY-SHT31-D has no regulator
Accuracy (real sensor)±2 % RH and ±0.3 C

SHT31 Terms You Will See in This Article

SHT31 terms
TermMeaning
RHRelative humidity, in %
Dew pointThe temperature at which that air would start to form dew
Single shotThe sensor measures once per command, for example 0x2400 (high repeatability, no clock stretching)
Periodic modeThe sensor measures by itself at a set rate; Fetch Data (0xE000) reads the newest result, Break (0x3093) stops it
ARTAccelerated response time: a periodic mode with 4 measurements per second
RepeatabilityHigh, medium or low: a longer or a shorter measurement
Busy NACKThe sensor refuses a read (NACK) because the measurement is not ready yet
Status word16 bits read with the command F32D: alert, heater, reset and error flags
Alert limitsHigh set, high clear, low clear and low set; each one holds a humidity and a temperature
TauThe time constant: the time a sensor needs to show 63 % of a sudden change

How the SHT31 Measures Temperature and Humidity

Single Shot and Periodic Mode

In single shot mode, the sketch sends a command, waits and reads six bytes. The Adafruit readBoth() sends 0x2400 (high repeatability), waits 20 ms and reads. The data sheet gives 12.5 ms typical and 15.5 ms at most; our model takes the maximum. A read that comes too early gets a busy NACK.

In periodic mode, the sensor measures by itself, 0.5 to 10 times a second (ART: 4), the sketch collects the newest result with Fetch Data (0xE000), and Break (0x3093) stops it. It matters here because the SHT31 checks its alert limits only in periodic mode.

From Raw Words to Degrees and Percent

Each value is an unsigned 16-bit word plus a CRC byte, converted with:

T = -45 + 175 x raw / 65535 C and RH = 100 x raw / 65535 %

So 25 C is the word 26214. The Adafruit library uses a quick integer version (65536 instead of 65535, cut to 0.01 steps) and makes 24.99 C of it, exactly what our Simple panel shows as SKETCH READ. The demo prints 25.0 C.

CRC and the Status Word

Every word carries a CRC-8 (polynomial 0x31, start value 0xFF). If one does not match, readBoth() returns false and the demo prints "Measurement or CRC error.". An alert limit written with a bad CRC is ignored, and status bit 0 is set.

The command F32D reads the 16-bit status word: bit 15 = alert pending, 13 = heater on, 11 = humidity alert, 10 = temperature alert, 4 = reset detected, plus error flags. After a reset, it is 0x8010, the data sheet value.

The Heater

On a real SHT31, the heater is for removing condensation and for a plausibility check. In v1.1, it really warms the sensor, by 4 C with a 4 s time constant (a model value): a higher temperature, a lower humidity, and the same dew point. In v1.0, it only set its status bit.

The Alert Mode and the ALERT Pin

The SHT31 holds four alert limits: high set, high clear, low clear and low set. Each one is a 16-bit word with the 7 top bits of a humidity and the 9 top bits of a temperature, read with E11F / E114 / E109 / E102 and written with 611D / 6116 / 610B / 6100 plus a CRC. The data sheet defaults: 80 % / 60 C, 79 % / 58 C, 22 % / -9 C and 20 % / -10 C.

The sensor checks them after every periodic measurement. Above "high set", status bits 15 and 11 (10 for the temperature) go on and the ALERT pin goes high; it clears only below "high clear" (the hysteresis). Version 1.0 did not have the alert mode.

The Dew Point

The dew point is the temperature at which the air would start to form dew. The demo uses the Magnus formula with Sensirion's constants:

g = ln(RH / 100) + 17.62 x T / (243.12 + T), then dew point = 243.12 x g / (17.62 - g)

For 25 C and 50 %, the exact value is 13.85 C, right on a rounding edge. From the library's 24.99 C, the demo gets 13.84 C and prints 13.8 C. Our panels show both: the SET line says 13.9 C, and SKETCH READ, computed like the demo, 13.8 C.

The Response Time

A real SHT31 follows a change with a time constant (tau63) of about 2 s for the temperature and 8 s for the humidity. Our model answers at once, like v1.0, unless you set the new RESPONSE property to 1 or click REAL TAU.

What's New in SHT31 Sensor Library for Proteus V1.1

If you used version 1.0, here is what has changed:

  • Two devices in TEPSHT31.LIB: SHT31 Simple (SHT31TEP, the v1.0 device) and SHT31 Advance (SHT31ADVTEP) with a pop-up window.
  • A redrawn, live board: the purple GY-SHT31-D with an animated climate view and PWR / I2C / ALERT LEDs (a TEP addition).
  • Six presets next to the v1.0 sliders; the Simple panel closes with a red X.
  • The ALERT pin and the alert mode, a known gap of v1.0: limits with CRC, hysteresis, periodic mode only.
  • A heater that warms the sensor (+4 C), with the dew point kept.
  • The real response time on request (the RESPONSE property, 2 s / 8 s), status 0x8010 after a reset, and ART.
  • Effects shown as base + now, and the panels' dew point matches the sketch.
  • An I2C log and four measured test tools on the Advance.
  • A two-UNO demo with the TEP Serial Monitor: the dew point, a humidity alarm LED and new commands; every v1.0 output line is kept.
  • Lighter package: about 1.61 MB, without the C++ source code and the AVR core archive.

And your old designs keep working. A design with the v1.0 symbol runs with the new model and shows the old slider panel; here, the v1.0 demo with the v1.1 DLL:

A v1.0 SHT31 design running on the v1.1 DLL in Proteus: the v1.0 SHT31 board, the v1.0 SHT31 CONTROLS panel with TEMPERATURE -0.3 C and HUMIDITY 50.0 %, and the Virtual Terminal printing Temperature: -0.3 C
Figure: A v1.0 design after the update: the v1.0 panel at -0.3 C, and the v1.0 sketch prints "Temperature: -0.3 C | Humidity: 50..." in its narrow Virtual Terminal.

Re-pick the part from the library to get the v1.1 board, the presets and the red X.

SHT31 Sensor Library for Proteus: Simple vs Advance

Both devices run the same model with the same properties; only the panel differs:

SHT31 Simple vs Advance
FeatureSimpleAdvance
Full SHT31 model (single shot, periodic mode, ART, CRC, status word, heater, alert mode, ALERT pin)✔✔
Purple GY-SHT31-D board: live climate view, PWR / I2C / ALERT LEDs✔✔
Control panel on the schematic (six presets, the v1.0 sliders, what the sketch read)✔✘
Pop-up window you can move, resize and minimise✘✔
Sensor page: a large climate view, presets, click-sliders with - / + for all three inputs, the last reading as tiles✘✔
I2C check, Timing, Step response and Dew point & heater✘✔
TEP Dark / Light theme, text size, Help page with Copy diagnostics✘✔
Same device name as v1.0 (old designs keep working)✔✘

Choose Simple to keep the controls beside your circuit, and Advance when your sheet is full or you want hard numbers about your sketch. The demo has one of each.

Download SHT31 Sensor Library for Proteus

Click the button below to download SHT31-Sensor-Library-for-Proteus-v1.1.zip (about 1.61 MB, without the C++ source code):

SHT31 Sensor Library for Proteus V1.1
  • README.txt: a detailed guide to the files, the wiring, the model, the test tools and real hardware.
  • Proteus Library Files: TEPSHT31.LIB (both devices), TEPSERIALMON.LIB and our Arduino UNO library ArduinoV3TEP.LIB / ArduinoV3TEP.IDX.
  • Proteus Model Files: TEPSHT31.DLL and TEPSERIALMON.DLL.
  • Proteus Simulation: SHT31-ArduinoUnoV3.pdsprj, SHT31_Demo.hex (both UNOs run it) and copies of both DLLs.
  • Arduino Code: SHT31_Demo.ino, the unmodified Adafruit SHT31 library 2.2.2 with its example (BSD licence, in its license.txt) and Adafruit BusIO 1.17.4, which it needs (MIT licence, in its LICENSE).

No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.

How to Install SHT31 Sensor Library for Proteus

  1. Close Proteus and extract the whole zip file.
  2. Copy the four files from Proteus Library Files into the LIBRARY folder, usually C:\Program Files (x86)\Labcenter Electronics\Proteus 8 Professional\LIBRARY (on some PCs C:\ProgramData\Labcenter Electronics\Proteus 8 Professional\LIBRARY).
  3. Copy TEPSHT31.DLL and TEPSERIALMON.DLL into the MODELS folder.
  4. Start Proteus, press P and search for SHT31. You get the Simple and the Advance device (category Sensors > Environmental, as in v1.0).

Updating from v1.0? Replace TEPSHT31.LIB and TEPSHT31.DLL, and delete TEPSHT31.IDX if there is one in LIBRARY. The DLL keeps its v1.0 name, so a v1.0 design keeps its v1.0 symbol and runs with the new model, with the v1.0 slider panel (no new board, no red X); re-pick the part to get the v1.1 board. Tested in Proteus 8.5; Proteus 7 is not supported.

The SHT31 Board in Proteus

We drew the sensor as a clean TEP board in the purple of the real GY-SHT31-D: the gold mounting hole, the "GY-SHT31-D" print, the small parts and the white SHT31 with its dark sensing opening. Here is U1, the Simple device, at the start values:

SHT31 Simple board in Proteus at ROOM: the purple GY-SHT31-D with the white SHT31, the climate view with 25.0 C, 50.0 % and DEW POINT 13.9 C, and the SHT31 CONTROLS panel with SKETCH READ 24.99 C 50.00 % DEW POINT 13.8 C
Figure: U1 (Simple) at 25 C and 50 %: SKETCH READ: 24.99 C 50.00 %, DEW POINT 13.8 C; the SET line gives the exact 13.9 C.

The Climate View

Above the board, the thermometer shows the temperature and the water drop fills up with the humidity. The dew point sits at the top right, and the SENSOR line says what the sensor element sees, the heater included. A red ALERT dot lights up while the ALERT pin is high. Click the thermometer or the drop to set a value.

Pinout

The six pins keep the v1.0 names and order: VIN, GND, SCL, SDA, ADDR and ALERT. On the real GY-SHT31-D, VIN, GND, SCL and SDA sit in a row, and AD and AL are separate pads.

SHT31 pins in Proteus (VIN GND SCL SDA ADDR ALERT)
PinWhat it doesDemo connection
VINPowerSupply terminal
GNDGroundGND
SCLI2C clockArduino A5
SDAI2C dataArduino A4
ADDRThe I2C address: low = 0x44, high = 0x45GND (0x44)
ALERTAlert output, active high (it also drives the ALERT LED)Not connected

LEDs and Indicators

Board animations (the same on both devices)
IndicatorWhat it shows
Climate viewThe thermometer, the water drop, the dew point, the heater and the ALERT sign
PWR LED (red)Lit while the board has power
I2C LED (blue)Flashes with every I2C transaction to this sensor
ALERT LED (amber)Lit while the ALERT pin is high
I2C 0x44The live address (0x45 with ADDR high)
PANEL / OPEN PANEL, SIMPLE / ADVANCEThe panel button and the device badge

The PWR, I2C and ALERT LEDs are a TEP addition; the real GY-SHT31-D has no LED.

Component Properties

SHT31 properties (double-click the sensor > Edit Properties; the same on both devices)
PropertyMeaningDefault
TEMPERATUREThe temperature in C, -40 to 12525
HUMIDITYThe relative humidity in %, 0 to 10050
RESPONSENew in v1.1: 1 = the real response time (tau 2 s / 8 s), 0 = at once, as in v1.00

Every Run starts again from these properties, not from the last slider positions. The panel style comes from the device (Simple or Advance), not from a property.

SHT31 Simple: The Control Panel on the Sheet

Beside the Simple board sits the SHT31 CONTROLS panel (on the right of the image above):

The SHT31 Simple control panel
PartWhat it does
Header, red XSHT31 CONTROLS; the X closes the panel
Six presetsROOM, SHOWER, FRIDGE, DESERT, BREATH and REAL TAU; the active one turns dark blue
TEMPERATURE, HUMIDITYThe two v1.0 sliders: drag them
SKETCH READWhat your sketch really read over I2C, converted as the Adafruit library does, with the dew point as the demo computes it
SET lineThe temperature and humidity you set, with their dew point
SENSOR lineWhat the sensor element sees now, and the heater (OFF, or ON with its warming)

ROOM is the start (25 C, 50 %), FRIDGE gives 4 C and 85 %, DESERT a hot, dry climate, and REAL TAU switches on the real response time. SHOWER and BREATH (a quick breath on the sensor) are effects that run for a while on top of your values. Watch SKETCH READ: it is what your Arduino got from the chip.

SHOWER: an Effect on Top of the Base Values

SHT31 Simple board in Proteus during SHOWER with ALERT ON 60: the climate view at 27.3 C and 85.1 % with the ALERT dot lit, the amber ALERT LED on, and the sliders at 25.0 C (base) and 50.0 % (base) with SHOWER now 27.3 C and SHOWER now 85.1 %
Figure: SHOWER with ALERT ON 60: the sliders keep the base values, the amber markers show "SHOWER now 27.3 C" and "SHOWER now 85.1 %", and the ALERT LED is lit.

Click SHOWER: the humidity climbs to 95 % in 8 s and falls again, and the temperature rises a little too. The sliders stay at your values, labelled "25.0 C (base)" and "50.0 % (base)", and an amber marker shows what the sensor gets now: "SHOWER now 27.3 C" and "SHOWER now 85.1 %". When the effect ends, the input returns to the base.

Before this shot, I typed ALERT ON 60 on U3, so at 85.1 % the amber ALERT LED and the red ALERT dot are lit. SKETCH READ (27.49 C, 87.45 %) is the last reading, so it trails the moving value.

Closing the Panel

Click the red X: the board button says PANEL: CLOSED, and the sensor keeps running. PANEL brings the panel back. Here, a SHOWER is running:

SHT31 Simple board in Proteus with the control panel closed: PANEL: CLOSED, the climate view at 27.9 C and 92.9 % with DEW POINT 26.6 C and the ALERT dot, the ALERT LED lit and the SIMPLE badge
Figure: The panel closed: PANEL: CLOSED; the climate view still shows the shower at 27.9 C and 92.9 %, and the ALERT LED stays lit.

SHT31 Advance: The Pop-Up Sensor Window

The Advance device keeps only the board on the schematic. Here is U2, at the start values:

SHT31 Advance board in Proteus: the purple GY-SHT31-D with the climate view at 25.0 C, 50.0 % and DEW POINT 13.9 C, I2C 0x44, the OPEN PANEL button and the ADVANCE badge
Figure: U2 (Advance) with OPEN PANEL and the ADVANCE badge; VIN goes to the supply, ADDR to GND, ALERT stays open.

At Run, the "TEP SHT31 Advance" pop-up opens with the look of our TEP Serial Monitor and no Windows title bar: move it by its header, resize or minimise it, and reopen it with OPEN PANEL. The header shows the state (U2 · SINGLE; below also ALERT, PERIODIC and HEATER), the Sensor and Test tabs and the palette (theme), gear (Settings) and ? (Help) icons.

The Sensor Page

SHT31 Advance Sensor page in Proteus during SHOWER: the red ALERT · HUMIDITY banner, the live view at 26.2 C and 67.6 % with dew point 19.7 C, the humidity row at 50.0 % base · SHOWER now 67.6 %, and the status word 0x8810
Figure: The Sensor page during SHOWER with the alert on: "ALERT · HUMIDITY", "50.0 % base · SHOWER now 67.6 %" and the status word 0x8810.
  • Toolbar and banner: I2C 0x44, 2 readings / s, the alert state, and a banner: green SINGLE SHOT normally, here the red ALERT · HUMIDITY.
  • LIVE VIEW: the thermometer and drop (26.2 C, 67.6 %) and the dew point (19.7 C).
  • CONTROLS: the presets and click-sliders with - / + for TEMPERATURE, HUMIDITY and REAL RESPONSE TIME ("OFF (at once)").
  • YOUR SKETCH READ: 25.99 C, 64.92 %, dew point 18.9 C and the status word 0x8810.
  • WHAT THE ARDUINO READ OVER I2C: 0 busy NACKs, 300 transactions (8 / s), SCL 89 kHz.

0x8810 is 0x8010 plus bit 11, the humidity alert. In alert mode, a reading takes four transactions (Fetch Data, the read, the status command and its read), so 2 readings make 8 a second. In the featured image, I clicked FRIDGE here, and LED D2 went on, because 85 % is above 70 %.

The Test Page: Four Measured Sensor Test Tools

The four tools on the Test tab only change the sensor's inputs (and restore them) and watch the I2C traffic your Arduino really makes; they never talk to your Arduino. Each tool ends with a bold "Good for:" line. All results below come from U2 with the demo sketch.

1. I2C Check: What Did Your Sketch Write Into the Chip?

SHT31 I2C check in Proteus: address 0x44, status 8010, last command 2400, mode single, the four alert limits, ALERT pin low, heater off, 0 busy NACKs, 194 transactions, 961 bytes, 0 NACKs, SCL 91 kHz and the decoded transactions
Figure: I2C check: status 8010, command 2400, the default alert limits, 0 NACKs and an SCL clock of 91 kHz.

Good for: "checking that the SHT31 answers and what your sketch really wrote into it." It works live, without a Run button. Read the table like a checklist:

  • Address 0x44 (ADDR low) and status 8010: "alert pending, reset seen, commands OK".
  • Last command 2400, mode single: single shot, high repeatability.
  • The alert limits: CD33 = 80 % RH / 59.9 C, CB2D = 79 % / 57.9 C, 3869 = 22 % / -9.1 C, 3266 = 20 % / -10.1 C, the data sheet defaults (9 temperature bits turn 60 C into 59.9 C).
  • ALERT pin low ("only in periodic mode"), heater off, 0 busy NACKs and 0 limit CRC errors.

Below: 0 NACKs and the SCL clock, measured on the pin: 91 kHz. The log shows the demo's rhythm: write 2400, and 20 ms later the read, "25.00 C, 50.00 % (CRC OK)", every 522 ms. It uses the data sheet formula, so it shows 25.00 C where the Adafruit library makes 24.99 C.

2. Timing: How Long Does a Measurement Take?

SHT31 timing test in Proteus over 3 s: 5 conversions every 522.63 ms, conversion time 15.50 ms, the sketch read 5 times every 522.6 ms, data age 5.3 ms, 0 busy NACKs, the datasheet times and every read listed
Figure: Timing, 3 s: a 15.50 ms measurement for every reading, 5 reads every 522.6 ms, each 5.3 ms after the result was ready.

Good for: "seeing how often new data exists and whether your sketch reads it in time." Choose a 1, 3 or 10 s window and click Run test. In 3 s: 5 conversions of 15.50 ms, one every 522.63 ms, and 5 reads, each one new data, with 0 busy NACKs. In single shot mode, the sketch starts each measurement, so "Expected (registers)" stays empty.

The middle box quotes the data sheet: "high / medium / low 12.5 / 4.5 / 2.5 ms typical, 15.5 / 6.5 / 4.5 ms max - the model takes the max". The library waits 20 ms for a 15.5 ms measurement, so each result is about 5 ms old when it is read: 5.3 ms, the transfers included. The 522.6 ms between readings are the demo's delay(500), those 20 ms, and the transfers and prints.

3. Step Response: How Quickly Does a Change Reach Your Sketch?

SHT31 step response test in Proteus, Humidity real tau: the humidity stepped 50 to 80, 80 to 50 and 50 to 80 %, the set value dashed and the sketch's readings as dots following the 8 s time constant
Figure: Step response, "Humidity, real tau" x 3: the readings follow the real 8 s time constant; 90 % after 18.6 to 18.8 s, settled after 31.4 to 31.7 s.

Good for: "seeing how quickly a change reaches your sketch - conversion, filter and read period together." Choose Temperature (25 to 35 C), Humidity (50 to 80 %) or Humidity, real tau, and 1, 3 or 5 steps; the chart shows the set value (dashed) and your readings (dots). Step 1 waits until the readings sit at the start value, so the chart starts flat.

Without the real response, the next reading has the whole step. "Humidity, real tau" uses the 8 s time constant, with 48 s (6 tau) per step:

Step response, Humidity real tau, 3 steps (U2, the demo in periodic mode, 2 readings a second)
StepChangeFirst reading (10 %)90 % reachedSettled (2 %)Readings
150.0 to 80.0 %1089.5 ms18795.8 ms31381.8 ms96
280.0 to 50.0 %1505.8 ms18651.6 ms31741.5 ms95
350.0 to 80.0 %1362.2 ms18565.0 ms31654.5 ms95

With tau = 8 s, 90 % takes 2.3 tau (18.4 s) and 2 % takes 3.9 tau (31.3 s); the measured 18.6 to 18.8 s and 31.4 to 31.7 s add the wait for the next reading. So on a real SHT31, a humidity change needs about half a minute to show in full, however fast your sketch reads.

4. Dew Point & Heater: Does Your Sketch Get the Dew Point Right?

SHT31 dew point and heater test in Proteus: room, bathroom, fridge and desert with the dew point of the set climate and from the sketch's readings, room plus heater at 29.0 C and 39.5 % with a dew point of 13.8 C, 5 of 5 set points OK, and a bar chart
Figure: Dew point & heater, with HEATER ON typed first: 5 of 5 set points OK; grey bars = the set climate, blue = from the sketch's readings, red marks = the temperature the sketch read.

Good for: "checking your dew point maths in four climates - and seeing what the heater does to the readings." The tool holds four climates for 5 s each, then room for 8 s with the heater, and computes the dew point (Magnus, 243.12 / 17.62) from what your sketch read. Type HEATER ON in the Serial Monitor before the last set point; I typed it before the run, so the heater warmed all five rows:

Dew point & heater (U2, the demo sketch, HEATER ON typed on U4; 5 reads per climate, 8 with the heater)
ClimateDew pointYour sketch readIts dew pointErrorVerdict
Room 25 C / 50 %13.9 C27.8 C / 42.5 %13.8 C-0.01 COK (heater on: +2.8 C)
Bathroom 28 C / 90 %26.2 C31.7 C / 72.9 %26.2 C-0.01 COK (heater on: +3.7 C)
Fridge 4 C / 85 %1.7 C7.9 C / 64.9 %1.7 C-0.01 COK (heater on: +3.9 C)
Desert 40 C / 15 %8.5 C44.0 C / 12.2 %8.4 C-0.01 COK (heater on: +4.0 C)
Room + heater13.9 C29.0 C / 39.5 %13.8 C-0.01 COK: +4.0 C, dew point kept

With the heater, the room read 29.0 C and 39.5 % instead of 25 C and 50 %: warmer, so the same air looks drier, yet its dew point is still 13.8 C. With its 4 s time constant, the heater's effect grew from +2.8 C to +4.0 C.

Settings and Help

The gear opens Settings: theme (TEP Dark or Light), text size, open the panel at Run, and the window size, saved for your Windows user.

Settings page of the SHT31 Advance pop-up: theme TEP Dark or Light, text size Small, Normal or Large, open the panel at Run on or off, and reset the window size
Figure: Settings, saved under HKCU\Software\TheEngineeringProjects\TEP SHT31 Advance.

The ? icon opens Help & Support: eight cards with their links (the SHT31 forum board for bugs and ideas, this article, updates, donate, website, forum), Check for updates, and Copy diagnostics for a bug report: the inputs, what was read, the registers, the last transactions and the test results. A links.ini next to the DLL can change the links.

Help and Support page of the SHT31 Advance: eight cards with their links to the SHT31 forum board, this article, the donate page, the website and the forum, and the Copy diagnostics button
Figure: Help & Support: every card shows its link; TEP SHT31 Advance v1.1, build 2026-10-08, TEPSHT31.DLL.

SHT31 Humidity Alarm with Arduino in Proteus

Open SHT31-ArduinoUnoV3.pdsprj from the Proteus Simulation folder, with SHT31_Demo.hex and both DLLs beside it. Its two Arduino UNOs from our Arduino Library for Proteus V3.0 run the same HEX file:

  • NODE 1 - SIMPLE: UNO 1 (ARD1) with the SHT31 Simple (U1), the humidity alarm LED D1 on A0 and Serial Monitor U3.
  • NODE 2 - ADVANCE: UNO 2 (ARD2) with the SHT31 Advance (U2), the humidity alarm LED D2 on A0 and Serial Monitor U4.

Both sensors sit at 0x44; each UNO has its own I2C bus, so that is no conflict.

SHT31 Arduino Proteus circuit running: two Arduino UNOs, the SHT31 Simple during SHOWER at 28.0 C and 95.0 % with its panel and LED D1 lit, the SHT31 Advance at 25.0 C and 50.0 % with LED D2 off, and two TEP Serial Monitors
Figure: The whole circuit running, without the pop-up windows: U1 during SHOWER at 28.0 C and 95.0 % (dew point 27.1 C, D1 on), U2 at 25.0 C and 50.0 % (D2 off).

Wiring

Demo wiring (the same on both UNOs, as in the v1.0 demo)
FromToWhy
SHT31 VIN / GNDSupply / groundPower (the PWR LED lights)
SHT31 SCL / SDAArduino A5 / A4I2C clock and data
SHT31 ADDRGNDThe address 0x44
SHT31 ALERTNot connectedOptional: active high, it drives the ALERT LED and can go to D2 for attachInterrupt
LED + 220 ΩA0 to GNDThe humidity alarm
Serial Monitor RXD / TXD / GNDArduino D1 / D0 / groundShows what the Arduino prints, sends what you type
Serial Monitor RXD2Not connectedI2C has no serial line to watch

A4 and A5 are the UNO's I2C pins (see our Introduction to Arduino UNO). The Wire library turns on the UNO's internal pull-ups, so the simulation needs no pull-up resistors.

The Arduino Code

The sketch uses the unmodified Adafruit SHT31 library 2.2.2, like v1.0, and keeps the v1.0 lines:

#include <Wire.h>
#include <Adafruit_SHT31.h>
Adafruit_SHT31 sensor;
bool ready=false;

New in v1.1: the LED pin, the address for the raw commands, the alarm level and three flags:

const uint8_t LED_PIN=A0;
const uint8_t ADDRESS=0x44;
float humidLimit=70;
bool humidOn=false, alertMode=false, alertWas=false;

In setup(), the I2C bus gets a 25 ms timeout, and begin(0x44) resets the sensor and reads its status word:

  Serial.begin(9600); Wire.begin(); Wire.setWireTimeout(25000,true);
  pinMode(LED_PIN,OUTPUT); digitalWrite(LED_PIN,LOW);
  ready=sensor.begin(0x44);
  Serial.println(ready ? F("TEP SHT31 - drag the temperature and humidity sliders.") : F("SHT31 not found. Check power, SDA, SCL and ADDR."));
  if(ready) Serial.println(F("TEP SHT31 Demo v1.1 - type HELP in the Serial Monitor"));

The loop reads both values with readBoth(), or with its own fetch() after ALERT ON, and prints the v1.0 line and the new dew point line:

    float temperature,humidity;
    const bool ok=alertMode ? fetch(&temperature,&humidity) : sensor.readBoth(&temperature,&humidity);
    if(ok) {
      Serial.print(F("Temperature: ")); Serial.print(temperature,1);
      Serial.print(F(" C | Humidity: ")); Serial.print(humidity,1); Serial.println(F(" %"));
      Serial.print(F("Dew point: ")); Serial.print(dewPoint(temperature,humidity),1); Serial.println(F(" C"));

The dew point is the Magnus formula from above, with Sensirion's constants:

float dewPoint(float t, float rh) {                   // Magnus formula with Sensirion's constants
  const float g=log(rh/100.0)+17.62*t/(243.12+t);
  return 243.12*g/(17.62-g);
}

The humidity alarm prints a line only when it changes:

      const bool humid=humidity>humidLimit;
      if(humid!=humidOn) { humidOn=humid; Serial.println(humidOn ? F("Humidity alarm: above the limit (LED on)") : F("Humidity alarm: off")); }
      digitalWrite(LED_PIN,humidOn ? HIGH : LOW);

In alert mode, the sketch also reports when bit 11 of the status word, the humidity alert, changes:

      if(alertMode) {
        const bool a=(sensor.readStatus()&0x0800)!=0;
        if(a!=alertWas) { alertWas=a; Serial.println(a ? F("SHT31 alert: humidity above the limit (ALERT pin high)") : F("SHT31 alert: cleared")); }
      }
    } else Serial.println(F("Measurement or CRC error."));

ALERT ON: Talking to the SHT31 Directly

The Adafruit library has no alert functions, so the sketch sends raw commands with its own CRC-8:

uint8_t crc8(const uint8_t* d, uint8_t n) {           // Sensirion CRC-8 (0x31, init 0xFF)
  uint8_t c=0xFF;
  for(uint8_t j=0;j<n;++j) { c^=d[j]; for(uint8_t i=0;i<8;++i) c=(c&0x80) ? (c<<1)^0x31 : (c<<1); }
  return c;
}

A limit packs 7 humidity bits and 9 temperature bits into one word, followed by its CRC:

void writeLimit(uint16_t c, float rh, float t) {      // an alert limit: the 7 MSBs of the RH word + the 9 MSBs of the T word
  const uint16_t rawRh=(uint16_t)(rh*65535.0/100.0), rawT=(uint16_t)((t+45.0)*65535.0/175.0);
  const uint16_t w=(rawRh&0xFE00)|(rawT>>7);
  uint8_t b[2]={(uint8_t)(w>>8),(uint8_t)w};
  Wire.beginTransmission(ADDRESS); Wire.write(c>>8); Wire.write(c&0xFF); Wire.write(b[0]); Wire.write(b[1]); Wire.write(crc8(b,2)); Wire.endTransmission();
}

ALERT ON stops periodic mode (Break), writes "high set" at your humidity and "high clear" 2 % lower, and starts periodic mode at 4 a second (0x2334). The 30 ms wait matters: a Fetch Data right after the start is refused, because there is no result yet.

      command(0x3093); delay(2);                       // stop any periodic mode before writing the limits
      writeLimit(0x611D,rh,60); writeLimit(0x6116,rh-2,58);
      command(0x2334); alertMode=true; alertWas=false;  // periodic, 4 measurements per second, high repeatability
      delay(30);                                       // the first periodic result (15 ms)

Then fetch() reads each result with Fetch Data, checks both CRCs and converts the words:

bool fetch(float* t, float* h) {                      // periodic mode: Fetch Data (0xE000), 6 bytes with CRCs
  command(0xE000);
  if(Wire.requestFrom(ADDRESS,(uint8_t)6)!=6) return false;
  uint8_t b[6]; for(uint8_t i=0;i<6;++i) b[i]=Wire.read();
  if(crc8(b,2)!=b[2] || crc8(b+3,2)!=b[5]) return false;
  *t=-45.0+175.0*(uint16_t)(b[0]<<8|b[1])/65535.0; *h=100.0*(uint16_t)(b[3]<<8|b[4])/65535.0;
  return true;
}

HEATER uses the library and reads the heater bit back:

  else if(!strcmp(s,"HEATER")) {
    if(arg && !strcmp(arg,"ON")) sensor.heater(true); else if(arg && !strcmp(arg,"OFF")) sensor.heater(false);
    else { Serial.println(F("HEATER ON or HEATER OFF")); return; }
    Serial.print(F("Heater: ")); Serial.println(sensor.isHeaterEnabled() ? F("ON (the sensor warms up a few degrees)") : F("OFF"));

HELP prints one line, short enough for the Serial Monitor's Simple interface:

void help() {
  Serial.println(F("Commands: HELP, STATUS, HEATER ON|OFF, ALERT ON [rh]|OFF, HUMID rh"));
}

A new Run brings back the start values. To change the sketch, export a new HEX file and load it into both UNOs; see How to get the HEX file from Arduino. New to Arduino? Start with our Arduino Tutorial for Beginners.

Serial Monitor Commands

Commands of the demo sketch, upper or lower case (monitor quick buttons: STATUS, HEATER ON, HEATER OFF, HELP)
CommandWhat it does
HELPThe command list (one line)
STATUSThe status word decoded: the heater, the alert, the mode and the LED's alarm level
HEATER ON | OFFThe sensor's heater
ALERT ON [rh] | OFFThe sensor's own alert: the high limits at rh (10 to 98 %, default 70 %; clear 2 % lower) and periodic mode at 4 a second; OFF goes back to single shot
HUMID rhThe LED's humidity alarm level, 1 to 99 % (start: 70 %)

How to Run the Demo

  1. Press Run. Both Serial Monitors (9600 baud) and U2's pop-up open.
  2. On U1's panel, drag HUMIDITY above 70 % (D1 goes on), then try the presets.
  3. Click STATUS on U3 or U4, then HEATER ON: the temperature reads about 4 C more, the dew point stays. Click HEATER OFF.
  4. Type ALERT ON 60 on U3 and click SHOWER on U1; ALERT OFF goes back.
  5. On U2, try the Sensor page and the four tools; close the window and reopen it with OPEN PANEL.

SHT31 Proteus Simulation Results

The Serial Monitor in Its Simple Interface

Both monitors in this demo run in the Simple interface of our TEP Serial Monitor, as in every monitor screenshot here. Only the log, the send box and one slim toolbar row stay visible (baud rate, follow, pause, search and clear), so the window stays small.

  • Switch to it: right-click the log and choose Simple interface, or press Ctrl+Shift+U.
  • Back to the full view: click the corner button (the expand arrows at the top right), press Esc or Ctrl+Shift+U, or right-click and choose Full interface.
  • Your choice is remembered.

Type commands such as STATUS or HEATER ON in the send box and press Enter; the quick buttons (STATUS, HEATER ON, HEATER OFF, HELP) come back with the full view. The demo's readings and answers are short lines, so they fit this small window. Read all about the monitor in TEP Serial Monitor Advance for Proteus.

Start-Up

After Run, U3 prints the v1.0 line, the new v1.1 line and then a reading and its dew point twice a second:

SHT31 Arduino Proteus start-up in the TEP Serial Monitor Simple interface: TEP SHT31 - drag the temperature and humidity sliders., TEP SHT31 Demo v1.1 - type HELP in the Serial Monitor, Temperature: 25.0 C | Humidity: 50.0 % and Dew point: 13.8 C
Figure: U3 in the Simple interface: the two start lines, then "Temperature: 25.0 C | Humidity: 50.0 %" and "Dew point: 13.8 C".
TEP SHT31 - drag the temperature and humidity sliders.
TEP SHT31 Demo v1.1 - type HELP in the Serial Monitor
Temperature: 25.0 C | Humidity: 50.0 %
Dew point: 13.8 C
Temperature: 25.0 C | Humidity: 50.0 %
Dew point: 13.8 C

The reading line is exactly the v1.0 line. The dew point, 13.8 C, is the value the Simple panel showed as SKETCH READ.

The Humidity Alarm

TEP Serial Monitor Simple interface in Proteus during a SHOWER: the humidity rising from 70.3 to 84.4 %, Humidity alarm: above the limit (LED on) after the 70.3 % reading, and the dew point rising from 20.5 to 24.4 C
Figure: U3 during a SHOWER: right after the 70.3 % reading, "Humidity alarm: above the limit (LED on)".
Temperature: 26.4 C | Humidity: 70.3 %
Dew point: 20.5 C
Humidity alarm: above the limit (LED on)
Temperature: 26.5 C | Humidity: 73.2 %
Dew point: 21.3 C
Temperature: 26.7 C | Humidity: 76.0 %
Dew point: 22.1 C
Temperature: 26.9 C | Humidity: 78.8 %
Dew point: 22.9 C

A SHOWER on U1: the first reading above 70 %, 70.3 %, switches LED D1 on, and the sketch says so once. The dew point rises too, because the air really holds more water. At 70 % or below, the sketch prints "Humidity alarm: off".

ALERT ON 60: the Sensor's Own Alert

TEP Serial Monitor Simple interface in Proteus after ALERT ON 60 during a SHOWER: the humidity rising from 54.3 to 68.4 %, and SHT31 alert: humidity above the limit (ALERT pin high) after the 59.9 % reading
Figure: U3 after ALERT ON 60, during a SHOWER: "SHT31 alert: humidity above the limit (ALERT pin high)" right after the 59.9 % reading.
Temperature: 25.5 C | Humidity: 57.1 %
Dew point: 16.4 C
Temperature: 25.7 C | Humidity: 59.9 %
Dew point: 17.3 C
SHT31 alert: humidity above the limit (ALERT pin high)
Temperature: 25.8 C | Humidity: 62.8 %
Dew point: 18.2 C
Temperature: 26.0 C | Humidity: 65.6 %
Dew point: 19.1 C

This time, the sensor decides: it sets status bit 11 and drives the ALERT pin high, and the amber ALERT LED lights up; the sketch only reports the bit. Note that the line follows the 59.9 % reading: a limit keeps only 7 humidity bits (see writeLimit()), so ALERT ON 60 really sets about 59.4 %. Below "high clear", the sketch prints "SHT31 alert: cleared".

STATUS and the Heater

TEP Serial Monitor Simple interface in Proteus: STATUS answered with Status: 0x8010 - heater OFF, alert pending, single shot, LED above 70 %, then HEATER ON answered with Heater: ON (the sensor warms up a few degrees) and the temperature rising to 25.5 C
Figure: U4: STATUS gives 0x8010; after HEATER ON, the temperature starts to rise and the humidity to fall, while the dew point stays at 13.8 C.
Temperature: 25.0 C | Humidity: 50.0 %
Dew point: 13.8 C
STATUS
Status: 0x8010 - heater OFF, alert pending, single shot, LED above 70 %
Temperature: 25.0 C | Humidity: 50.0 %
Dew point: 13.8 C
HEATER ON
Heater: ON (the sensor warms up a few degrees)
Temperature: 25.0 C | Humidity: 49.9 %
Dew point: 13.8 C
Temperature: 25.5 C | Humidity: 48.5 %
Dew point: 13.8 C

Once you send a command, the log marks your lines TX and the sketch's lines RX. STATUS shows the reset value 0x8010, single shot mode and the LED level. After HEATER ON, the readings climb to 25.5 C while the humidity drops to 48.5 %, and the dew point stays at 13.8 C; a few seconds later, they settle about 4 C higher.

Troubleshooting

  • "SHT31 not found. Check power, SDA, SCL and ADDR.": check VIN / GND (the PWR LED must be lit), SDA on A4, SCL on A5, and that ADDR matches the address in begin(); then restart.
  • "Measurement or CRC error.": no answer (power, wiring) or a bad CRC; in your own sketch, also a read before the 15.5 ms are over (the I2C check counts busy NACKs).
  • The values change slowly: REAL TAU / RESPONSE = 1 is on.
  • The temperature is a few degrees too high: the heater is on; type HEATER OFF.
  • ALERT never fires: the limits are checked only in periodic mode (ALERT ON in the demo).
  • No simulation, panel or monitor window: TEPSHT31.DLL or TEPSERIALMON.DLL is missing; click OPEN MONITOR on a closed monitor.
  • The Advance pop-up does not appear: click OPEN PANEL, or turn "Open the panel at Run" back on.
  • No red X, or the board looks like v1.0: replace TEPSHT31.LIB, delete TEPSHT31.IDX and re-pick the part.
  • Your own sketch receives with SoftwareSerial: Proteus 8.5 cannot do that; use the hardware Serial or AltSoftSerial.

Things to Know Before Using a Real GY-SHT31-D

The demo sketch uses only Wire and the Adafruit libraries, so it runs on a real UNO and GY-SHT31-D, too. Keep in mind:

  • Supply: the GY-SHT31-D has no regulator; the sensor runs on 2.4 to 5.5 V. 3.3 V is the usual choice, and 5 V works.
  • Pull-ups: 10 k on the board (to VIN), so A4 / A5 need nothing else.
  • Address: ADDR low = 0x44, high = 0x45: two SHT31 on one bus.
  • ALERT: active high (push-pull), only in periodic mode.
  • Self-heating: keep the sensor away from the regulator and the microcontroller.
  • The heater is for removing condensation and for a plausibility check, not for normal measuring.
  • Accuracy: ±2 % RH and ±0.3 C on a real SHT31; the model gives exact values.

Limitations of the Simulation

  • Not modelled: clock stretching on the bus (the result simply is not ready until the measurement ends), the general-call reset, noise, the accuracy tolerances and drift of the real sensor, and condensation.
  • The model is our own implementation, written from the Sensirion SHT3x-DIS data sheet; it contains no Sensirion code. The heater's warming (+4 C, tau 4 s) is a model value.
  • Licences: BSD for the Adafruit SHT31 library 2.2.2, MIT for Adafruit BusIO 1.17.4. The HEX file also contains the Arduino AVR core 1.8.6, which includes LGPL-licensed code; its source code is on GitHub.
  • Tested in Proteus 8.5 on 8 Oct 2026 (every screenshot here) and with 2,817 automatic PC checks, all passed, 30 of them with the real demo sketch and the unmodified Adafruit library; the v1.0 test passed too. Proteus 7 is not supported.

Need the air pressure as well? Our sibling BME280 Sensor Library for Proteus measures temperature, humidity and pressure, with a dew point too. For altitude, try our BMP280 Sensor Library for Proteus; for light, our BH1750 Light Sensor Library for Proteus; for colour, our TCS34725 Sensor Library for Proteus; for distance, our VL53L0X Sensor Library for Proteus; and for motion, our MPU6050 Sensor Library for Proteus. To send your readings by radio, add our HC-12 Library for Proteus.

So, that was all about the SHT31 Sensor Library for Proteus V1.1. I hope the live climate view, the dew point, the heater, the alert mode and the four test tools make the SHT31 much easier to understand, so your humidity project works the first time you wire a real GY-SHT31-D. If you use the SHT31 Sensor Library for Proteus in a project, please share your feedback in the comments or in our forum, and if you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!


Comments

0

Join the conversation