
SHT40 Humidity Sensor Library for Proteus Simulation

Hello friends, I hope you all are doing great. Today, I am going to share the new SHT40 Humidity Sensor Library for Proteus Simulation. The SHT40 is one of the most accurate low-cost temperature and humidity sensors you can buy: a chip of 1.5 x 1.5 mm that reads the temperature to about 0.2 °C and the relative humidity to about 1.8 %RH, talks I2C and even has its own heater to dry itself after condensation. With this library you can run a full Proteus simulation of the SHT40 breakout, watch every command it receives and see what its heater really does to a reading.
SHT40 Humidity Sensor Library for Proteus
Latest version: V1.0 (December 2026, this tutorial)
Helping Tools
- Serial Monitor Advance: a serial terminal window for the UART of your board
- Serial Monitor Expert: the serial monitor with extra debugging tools
- LCD Library for Proteus V3.0: 16x2, 20x4 and I2C LCDs to show your readings
The demo is a bathroom extractor fan: the SHT40 measures the air twice a second, a 16x2 LCD on an I2C backpack shows the temperature, the humidity and the dew point, and a 12 V PC fan speeds up as the humidity climbs during a shower.
NOTICE: Our team has put a lot of effort into these small parts: the bodies, the animation and the pop-ups are all our own design, and you get them free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below or in the temperature and humidity sensor board of our forum. And if our free libraries help you, you can buy us a coffee. So, let's get started with the SHT40 Humidity Sensor Library for Proteus Simulation:
What Is the SHT40 Humidity Sensor?
The SHT40 is a digital humidity and temperature sensor from the fourth generation of a well-known family. Inside the tiny package sit a capacitive humidity sensor, a band-gap temperature sensor, an ADC, the calibration data and an I2C interface, so the chip hands you finished numbers instead of raw voltages. On a breakout board it gets a 3.3 V regulator, two pull-up resistors and a four-pin header, which makes it as easy to wire as any I2C module.
| SHT40 | |
|---|---|
| Temperature | -40 to 125 °C, typically ±0.2 °C |
| Humidity | 0 to 100 %RH, typically ±1.8 %RH |
| Interface | I2C at 0x44 (0x45 / 0x46 for other versions) |
| Measurement | 8.3 / 4.5 / 1.6 ms at most (high / medium / low repeatability) |
| Heater | 200 / 110 / 20 mW for 1 s or 0.1 s |
| Supply | chip 1.08 - 3.6 V; breakout VIN 3.3 - 5 V |
| Pins (module) | VIN GND SCL SDA |
One Command Byte, Six Bytes Back
The SHT40 has no registers to set up. Everything it does starts with a single command byte. 0xFD starts a measurement with high repeatability, 0xF6 with medium and 0xE0 with low repeatability; 0x89 reads the serial number; 0x94 is a soft reset; and six more bytes switch on the heater. After a measurement the host reads six bytes: the temperature (two bytes and a CRC) and the humidity (two bytes and a CRC). The raw values become real units with two simple formulas: T = -45 + 175 x St / 65535 in degrees Celsius, and RH = -6 + 125 x Srh / 65535 in percent, clipped to 0 - 100.
No Clock Stretching: a NACK Until It Is Ready
A high-repeatability measurement takes up to 8.3 ms. Some sensors hold the clock line low until they are done; the SHT40 does not. While it is busy it simply does not answer its address - the host gets a NACK. So the rule is easy: send the command, wait the measurement time, then read. Read too early and the read fails; read the same result twice and the second read fails too, because a result is read only once. The simulation behaves exactly like that, and its pop-up counts every NACK so you can see when a sketch is in too much of a hurry.
The CRC: Trust Nothing on a Long Wire
Each two-byte value comes with a CRC-8 byte (polynomial 0x31, starting value 0xFF). A sensor in a bathroom or a greenhouse often sits at the end of a long cable, and a single flipped bit could turn 23 °C into something absurd. Checking both CRCs costs a few microseconds and catches those errors before they reach your fan or your display.
The Heater
Humidity sensors do not like condensation: a film of water on the sensor makes it read too high for a long time, and long hours at very high humidity make the readings creep. The SHT40 has a small heater on the chip for exactly this. A heater command switches it on for 1 s or 0.1 s at 200, 110 or 20 mW, then makes a measurement while it is still on, and switches it off. That measurement is hot - according to the maker's application note, 200 mW for 1 s warms the chip by about 50 °C on average - so it must never be used as the temperature of the air. The datasheet also limits the heater to under 10 % of the time.
Relative Humidity and the Dew Point
Relative humidity is how much water vapour the air holds compared with the most it could hold at that temperature. Warm the same air and its relative humidity falls, even though no water left it - which is also why a heated sensor reads a low humidity. The dew point turns the pair into one useful number: the temperature at which this air would start to condense. A cold mirror or wall below the dew point fogs up, and that is what an extractor fan in a bathroom is there to prevent.
Features of the SHT40 Humidity Sensor Library for Proteus Simulation
- A real-looking breakout: the 18 x 13 mm board at its real size, with the SHT40 on its island cut free by two routed slots, the regulator, the pull-ups and the PWR LED that lights at Run.
- The real command set: measure with three repeatabilities, the serial number, the soft reset and all six heater commands, with their timings.
- A real bus partner: a NACK while busy, a NACK for a result read twice, six bytes with correct CRCs, repeatability noise like the real chip.
- A working heater: the chip warms and cools on its own time constant, its humidity reading falls as it warms, and the sensor glows orange on the sheet while it heats.
- Air to test with: PROFILE DEMO is a bathroom with a shower; PROFILE STEADY holds a temperature and a humidity that the pop-up's chips move.
- A pop-up: the air, the chip and your last reading on two bars, the last commands with their results, tiles for every number - graphs, an event log and a check page.
- A complete package: about 2.0 MB with the library, our I2C LCD and PC fan, our Arduino UNO V4.0 and the demo, without the source code of the model.
The SHT40 in Proteus
The device is SHT40TEP in TEPSHT40.LIB, under Modules > Sensors, with the prefix U and the model TEPSHT40.DLL. Search SHT40 or humidity in Pick Devices. Its four pins are on the left: VIN, GND, SCL and SDA. Four properties set it up: ADDRESS (0x44, 0x45 or 0x46), PROFILE (DEMO or STEADY), TEMP and HUMIDITY (the air for STEADY).
Download SHT40 Humidity Sensor Library for Proteus Simulation
Click the button below to download SHT40-Humidity-Sensor-Library-for-Proteus-v1.0.zip (about 2.0 MB, without the source code of the models):
SHT40 Humidity Sensor Library for Proteus V1.0- README.txt: installation, the demo, the wiring, troubleshooting and the limits of the simulation.
- Proteus Library Files:
TEPSHT40.LIB,TEPI2CLCD16X2.LIB,TEPPCFAN.LIBandArduinoV4TEP.LIB. - Proteus Model Files:
TEPSHT40.DLL,TEPLCD.DLL,TEPPCFAN.DLLandTEPARDUINO.DLL. - Arduino Code: the demo sketch (Wire only).
- Proteus Simulation: the demo project, its HEX file and copies of the DLLs.
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 SHT40 Humidity Sensor Library for Proteus Simulation
- Close Proteus and extract the whole zip file, for example to your Desktop.
- Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
- Copy the files from Proteus Model Files into the MODELS folder.
- Delete
TEPSHT40.IDXfrom the LIBRARY folder if it is there. - Start Proteus, press P and search for SHT40.
Proteus Simulation of a Bathroom Extractor Fan
The demo uses an A4 sheet with our Arduino UNO Library for Proteus V4.0. The SHT40 (U1, at 0x44) and a 16x2 LCD on its I2C backpack from our I2C LCD 16x2 Library for Proteus (LCD1, at 0x27) share the I2C bus on A4 and A5. A 12 V PC fan from our 4-Pin PC Fan Library for Proteus (FAN1) plays the extractor fan: its PWM wire on D9 sets the speed at the PC fan standard of 25 kHz, and its tach wire on D2 reports the speed back. The SHT40 runs on its DEMO air: a bathroom in fast time, with a shower from 0.5 s to 4.5 s. The Arduino's monitor is built in, the same window as our TEP Serial Monitor Advance for Proteus. Open SHT40-Bathroom-Fan-ArduinoUnoV4.pdsprj.
The Sketch
The sketch needs only the Wire library. One function does a whole measurement - the command, the wait, the six bytes, the CRC check and the two formulas:
bool measure(byte cmd, unsigned int waitMs, float& t, float& rh) {
if (!shtCommand(cmd)) return false;
delay(waitMs); // 0xFD: 8.3 ms at most - the SHT40 does not stretch the clock
byte d[6];
if (!shtRead(d)) return false;
t = -45.0 + 175.0 * word(d[0], d[1]) / 65535.0;
rh = constrain(-6.0 + 125.0 * word(d[3], d[4]) / 65535.0, 0.0, 100.0);
The CRC is the standard eight-bit one, computed over each two-byte word:
byte crc8(const byte* d) { // polynomial 0x31, start 0xFF, over one 2-byte word
byte c = 0xFF;
for (byte i = 0; i < 2; i++) { c ^= d[i]; for (byte b = 0; b < 8; b++) c = (c & 0x80) ? (c << 1) ^ 0x31 : c << 1; }
The fan follows a band rather than a single threshold, so it does not flick on and off around one value: it starts at 65 %RH, stops only below 58 %RH, and in between its speed rises from 40 % to 100 % as the humidity goes from 65 % to 90 %:
if (!fanOn && rh >= 65) fanOn = true; // the band: on at 65 %, off under 58 %
if (fanOn && rh < 58) fanOn = false;
fan = fanOn ? constrain(map((long)rh, 65, 90, 40, 100), 40, 100) : 0;
Finally, when the humidity stays at 90 % or more for two readings in a row, the sketch fires the heater once with 0x39 (200 mW for 1 s) to dry the sensor, prints the heated reading and ignores it.
SHT40 Simulation Results
Open the project and press Run. The demo runs 7.6 simulated seconds and took about 3 minutes 43 seconds on our PC with the pop-up open and the pictures being taken. Click U1 for its pop-up. Every number below comes from one simulation run, the demo exactly as it ships.
The Shower Starts
At power-on the sketch sends a soft reset (0x94), reads the serial number (0x89) and starts measuring every half second. The first reading, at 0.2 s, is the quiet bathroom: 22.99 °C and 50.0 %RH, a dew point of 12.0 °C, the fan off. At 0.5 s the shower starts and the humidity climbs fast: 60.2 %RH at 0.7 s and 76.4 %RH at 1.2 s, while the temperature creeps up from 23 to 24 °C. The pop-up at 1.59 s shows the air at 24.7 °C and 83.6 %RH, and the host's last reading (the white dot) a little behind it at 76.4 %RH - a reading is a snapshot, and the air keeps moving between two of them.
The Fan Starts
At 1.2 s the humidity passes 65 % and the fan starts at 66 % speed; at 1.7 s, 85.0 %RH, it runs at 88 %, and from 2.7 s it is at full speed. The LCD shows every step: "T 24.2C RH 76.4%" on top and "Dp 19.8C Fan 66%" underneath at 1.2 s - the dew point is already close to the room temperature, which is exactly when mirrors and tiles start to fog. The tach on D2 reports the fan turning, so the sketch could also tell a stuck fan from a running one.
The Heater Pulse
At 2.7 s the reading is 92.1 %RH and at 3.2 s 93.5 %RH: two readings in a row at 90 % or more, so the sketch fires the heater with 0x39. The pop-up at 3.49 s turns orange: "HEATING 200 mW for 1 s - the chip at 77.9 C, 0.80 s left; NACK until done". The temperature bar shows the chip 52 degrees above the air (26.1 °C), and the humidity bar shows why a heated reading is useless for the room: the chip reads only 7.2 %RH while the air holds 93.9 %RH. The chip current tile shows 60.6 mA - the heater's 200 mW at 3.3 V. The heater command ends with a measurement, and the sketch prints it and throws it away: 78.99 °C and 7.1 %RH. On the sheet, the sensor glows orange while it heats.
The Room Dries
At 4.5 s the shower stops and the room dries. Half a second after the heater pulse the chip has cooled back to the air - its time constant is only 50 ms - and the readings are good again: 26.15 °C and 81.6 %RH at 4.9 s, the fan back down to 78 %. The humidity falls to 71.1 %RH at 5.4 s and 64.8 % at 5.9 s, and the fan slows to its minimum of 40 %. Below 65 % it does not stop - that is the band - and keeps running at 40 % until the humidity drops under 58 %: 58.6 % at 6.9 s, then 57.2 % at 7.4 s, and the fan switches off. The pop-up at 5.0 s shows the drying room: the air at 79.1 %RH and falling, the chip back at the air's temperature.
The Graphs, the Event Log and the Check Page
The Graphs page plots the air temperature, the air humidity, the chip temperature and the heater power - the heater pulse stands out as a tall orange spike on the chip temperature. The Event log lists the commands and the heater with their times and results. The Check page sums up the run: Supply green at 5.00 V with the SHT40 at 0x44; Measurements green - 14, all at high repeatability, and 15 results read (the serial number is the 15th); Reading green - the last reading 24.94 °C / 57.2 %RH against the air at 24.93 °C / 57.2 %RH at that moment; Timing green - not one read while busy and not one read with no result, because the sketch waits 9 ms after each 0xFD; and Heater green - 1 pulse, 1.01 s on in all, well under the 10 % duty limit.
The Arduino's built-in serial monitor is the log of the run: the serial number, then one line every half second with the time, the temperature, the humidity, the dew point, the fan's duty and its speed from the tach, and the two lines of the heater pulse with its ignored reading.
Why the Humidity Falls When the Chip Warms
The heater does not dry the air - it warms the sensor. The amount of water vapour around the chip stays the same, but the warmer the chip, the more vapour the air right at its surface could hold, so the relative humidity it measures drops. The model works this out with the same Magnus formula the dew point uses: at about 50 °C above the air, a reading of 90 %RH falls to a few percent. That is exactly why heated readings must be thrown away, and why a sensor mounted next to a warm regulator or a busy processor reads too dry. The breakout's routed slots are there for the same reason.
SHT40, AHT20 or DHT22?
All three measure temperature and humidity, but they are not the same class. The DHT22 from our DHT11 / DHT22 Library for Proteus uses its own single-wire protocol with tight timing and gives a reading every two seconds at most. The AHT20 from our AHT20 Sensor Library for Proteus is an I2C sensor with good accuracy at a very low price. The SHT40 is the most accurate of the three, the fastest, the only one with CRC-protected results and an on-chip heater, and it shares the bus with any other I2C device. For a bathroom fan any of them would do; for a weather station, a greenhouse or a museum display case, the SHT40 is the safer choice.
Try It Yourself
- Click U1 while the simulation runs and use the chips: RH +5 % and RH -5 % move the humidity by hand (the sensor leaves the DEMO air), and the fan answers at once.
- Change the wait after 0xFD from 9 ms to 2 ms: the reads fail with a NACK, and the pop-up counts them.
- Use 0xF6 or 0xE0 instead of 0xFD: faster measurements with a little more noise.
- Fire the heater in every loop: the Check page warns that the heater is above its 10 % duty cycle.
- Set ADDRESS to 0x45 and change the sketch: the address of another SHT40 version.
Ideas to Extend the Demo
- A mirror heater: switch a heater pad when the mirror's temperature is below the dew point.
- A greenhouse controller: a fan, a mist maker and a heater, each with its own band.
- A data logger: one reading a minute to an EEPROM, with the time from an RTC.
Your Own Sketches
The demo sketch is in the zip file, and you can change it in the Arduino IDE. New to Arduino? Start with our Arduino Tutorial for Beginners. Export the compiled binary, and set the UNO's PROGRAM property to the new file. Our guide on How to get the HEX file from Arduino shows you where the file ends up.
Things to Know Before Using a Real SHT40
- Timing: wait 8.3 ms after 0xFD (4.5 ms after 0xF6, 1.6 ms after 0xE0) before reading.
- Placement: keep the sensor away from warm parts and in moving air; a sealed box reads its own warmth.
- Response: the real sensor needs a few seconds to follow a change of the air; the simulation follows at once.
- Heater: at most 1 s at a time and under 10 % of the time; throw away its readings.
- Addresses: 0x44, 0x45 or 0x46 depending on the version - check what your board carries.
Troubleshooting
- The read returns 0 bytes: the sketch read too early, or read the same result twice.
- The CRC never matches: the bytes are read out of order, or the CRC starts from 0x00 instead of 0xFF.
- The temperature is far too high and the humidity far too low: the reading came from a heater command.
- No answer at all: the address does not match ADDRESS, or VIN is not powered.
- The part is not simulated:
TEPSHT40.DLLis missing from MODELS and from the project folder.
Limitations of the Simulation
- The command set, the timings, the NACKs, the CRCs, the formulas and the repeatability follow the SHT4x datasheet; the board is our own drawing.
- Our own figures: the chip reads the air exactly (the real one is within about 0.2 °C and 1.8 %RH); the heater warms the chip with a 50 ms time constant and 263 K/W, matching the maker's published averages; the DEMO air runs in fast time.
- Not modelled: the long-term creep at high humidity, the sensor's response time to the air, the 1 MHz bus mode.
- Arduino is a name of Arduino; this library is not made or endorsed by Arduino, Labcenter or the chip's maker.
- Tested in Proteus 8.5 in November 2026 (the demo as shipped). Proteus 7 is not supported.
So, that was all about the SHT40 Humidity Sensor Library for Proteus Simulation, the first part of our new list of modules. I hope it helps you build projects that know exactly how warm and how damp the air is. 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