377_SHT45. PRECISION TEMPERATURE AND HUMIDITY SENSOR
Quote from Defran on December 2, 2026, 6:23 pm
The SHT45 is a factory-calibrated digital temperature and relative humidity sensor. Its 7-bit I²C address is 0x44.
FEATURES:
Temperature range: −40 to +125 °C
Typical temperature accuracy: ±0.1 °C
Relative humidity range: 0 to 100% RH
Typical humidity accuracy: ±1 percentage point RH
Chip supply: 1.08 to 3.6 V
Typical average current consumption: 0.4 µA
Conversion time: 6.9 ms typical and 8.3 ms maximum at high repeatability
Response to an environmental change: 2 s for temperature and 4 s for humidity to reach 63% of the change
Package: 4-pin DFN, 1.5 × 1.5 × 0.5 mm
Built-in features: Data verification by CRC and three-stage heaterAccuracy figures are typical and vary with temperature and humidity. Electronic conversion takes milliseconds, but the physical sensor needs a few seconds to reflect an environmental change.
SCHEMATIC:
The measurement values are displayed on an SSD1306 128x64 OLED.
The sensor body contains two potentiometers for simulation. When you start sim1 in Simulide and move these potentiometers, you will see the simulated temperature and humidity values.SOFTWARE:
The sensor is implemented using a script. The operating program is very standard. No libraries are used for the sensor; only the typical OLED libraries are used. Both listings are shown below.// SCRIPT SHT45, TEMPERATURE AND HUMIDITY MEASUREMENT. DEFRAN26A IoPin@ sclPin = component.getPin("scl"); IoPin@ sdaPin = component.getPin("sda"); IoPin@ vddPin = component.getPin("vdd"); IoPin@ tempPin = component.getPin("vtemp"); IoPin@ humidPin = component.getPin("vhumid"); enum BusState { Idle, Address, Write, Send, SlaveAck, MasterAck, Ignore }; BusState state; bool prevScl, prevSda, reading, accepted, masterAck, wroteCommand; uint8 bits, incoming, outgoing, index; const uint64 edgeDelay = 350000; // ps array<uint8> frame(6); bool busy, ready; void setup() { print("SHT35s: script cargado"); } void reset() { component.cancelEvents(); sclPin.setPinMode(2); sdaPin.setPinMode(2); vddPin.setPinMode(1); tempPin.setPinMode(1); humidPin.setPinMode(1); state = Idle; busy = false; ready = false; prevScl = true; prevSda = true; sclPin.setOutState(true); sdaPin.setOutState(true); sclPin.changeCallBack(element, true); sdaPin.changeCallBack(element, true); } uint8 crc8(uint16 word) { uint8 crc = 0xff; for (int shift = 8; shift >= 0; shift -= 8) { crc ^= uint8(word >> shift); for (int bit = 0; bit < 8; bit++) { if ((crc & 0x80) != 0) crc = uint8((crc << 1) ^ 0x31); else crc = uint8(crc << 1); } } return crc; } uint16 encode(double value, double minimum, double span) { double scaled = (value - minimum) * 65535.0 / span; if (scaled <= 0.0) return 0; if (scaled >= 65535.0) return 65535; return uint16(scaled + 0.5); } void putWord(uint8 pos, uint16 word) { frame[pos] = uint8(word >> 8); frame[pos + 1] = uint8(word & 0xff); frame[pos + 2] = crc8(word); } double inputFraction(IoPin@ pin) { double fraction = pin.getVoltage() / 3.30; // CALIBRATION_______ if (fraction < 0.0) return 0.0; if (fraction > 1.0) return 1.0; return fraction; } void runEvent() { double temperature = -40.0 + 165.0 * inputFraction(tempPin); double humidity = 100.0 * inputFraction(humidPin); putWord(0, encode(temperature, -45.0, 175.0)); putWord(3, encode(humidity, -6.0, 125.0)); busy = false; ready = true; } bool receiveCommand(uint8 cmd) { if (cmd == 0x94) { component.cancelEvents(); busy = false; ready = false; return true; } if (cmd == 0x89) { putWord(0, 0x5348); putWord(3, 0x5435); ready = true; return true; } uint64 timePs; switch (cmd) { case 0xfd: timePs = 8300000000; break; case 0xf6: timePs = 4500000000; break; case 0xe0: timePs = 1600000000; break; default: return false; } ready = false; busy = true; component.addEvent(timePs); return true; } void sendBit() { sdaPin.scheduleState((outgoing & 0x80) != 0, edgeDelay); outgoing = uint8(outgoing << 1); bits--; } void startByte() { outgoing = frame[index]; bits = 8; state = Send; sendBit(); } void voltChanged() { bool scl = sclPin.getInpState(); bool sda = sdaPin.getInpState(); if (sda != prevSda && scl) { if (sda) state = Idle; else { state = Address; incoming = 0; bits = 8; wroteCommand = false; } } prevSda = sda; if (scl == prevScl) return; prevScl = scl; if (scl) { if ((state == Address || state == Write) && bits > 0) { incoming = uint8((incoming << 1) | (sda ? 1 : 0)); bits--; } else if (state == MasterAck) masterAck = !sda; return; } switch (state) { case Address: if (bits != 0) break; reading = (incoming & 1) != 0; accepted = (incoming >> 1) == 0x44 && !busy && (!reading || ready); sdaPin.scheduleState(!accepted, edgeDelay); state = SlaveAck; break; case Write: if (bits != 0) break; accepted = !wroteCommand && receiveCommand(incoming); wroteCommand = true; sdaPin.scheduleState(!accepted, edgeDelay); state = SlaveAck; break; case SlaveAck: if (!accepted) state = Ignore; else if (reading) { index = 0; ready = false; startByte(); } else { sdaPin.scheduleState(true, edgeDelay); incoming = 0; bits = 8; state = Write; } break; case Send: if (bits != 0) sendBit(); else { sdaPin.scheduleState(true, edgeDelay); state = MasterAck; } break; case MasterAck: index++; if (masterAck && index < 6) startByte(); else state = Ignore; break; default: break; } }// SHT45 TEMPERATURE AND HUMIDITY PRECISION MEASUREMENT. DEFRAN26A #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> constexpr uint8_t SENSOR_ADDR = 0x44; constexpr uint8_t OLED_ADDR = 0x3C; Adafruit_SSD1306 oled(128, 64, &Wire, -1, 100000UL, 100000UL); void loop() { uint8_t data[6] = {}; bool received = false; if (sendCommand(0xFD)) { delay(10); if (Wire.requestFrom(SENSOR_ADDR, uint8_t(6)) == 6) { for (uint8_t &value : data) value = Wire.read(); received = true; } } bool tempOk = received && validCrc(data); bool humOk = received && validCrc(data + 3); uint16_t rawTemp = (uint16_t(data[0]) << 8) | data[1]; uint16_t rawHum = (uint16_t(data[3]) << 8) | data[4]; float temperature = -45.0f + 175.0f * rawTemp / 65535.0f; float humidity = constrain(-6.0f + 125.0f * rawHum / 65535.0f, 0.0f, 100.0f); oled.clearDisplay(); showReading(0, F("TEMPERATURE"), tempOk, temperature, F(" \xF8" "C")); oled.drawFastHLine(0, 31, 128, SSD1306_WHITE); showReading(35, F("RELATIVE HUMIDITY"), humOk, humidity, F(" %")); oled.display(); } bool sendCommand(uint8_t command) { Wire.beginTransmission(SENSOR_ADDR); Wire.write(command); return Wire.endTransmission() == 0; } bool validCrc(const uint8_t *data) { uint8_t crc = 0xFF; for (uint8_t i = 0; i < 2; i++) { crc ^= data[i]; for (uint8_t bit = 0; bit < 8; bit++) { if (crc & 0x80) crc = (crc << 1) ^ 0x31; else crc <<= 1; } } return crc == data[2]; } void showReading(uint8_t y, const __FlashStringHelper *label, bool valid, float value, const __FlashStringHelper *unit) { oled.setTextSize(1); oled.setCursor(0, y); oled.print(label); oled.setCursor(0, y + 11); if (!valid) { oled.print(F("Read error")); return; } oled.setTextSize(2); oled.print(value, 1); oled.setTextSize(1); oled.print(unit); } void setup() { Wire.begin(); Wire.setClock(100000UL); if (!oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR, true, false)) {while (true) {}} oled.setTextColor(SSD1306_WHITE); oled.cp437(true); sendCommand(0x94); delay(20); }FILES PROVIDED:
The attached ZIP file includes: the schematic, the "ino" file, the "exe" file, all subcircuits used in this project, all located in the "data" directory and the SHT45 sensor. Simulide version 1.2 or higher is required.

The SHT45 is a factory-calibrated digital temperature and relative humidity sensor. Its 7-bit I²C address is 0x44.
FEATURES:
Temperature range: −40 to +125 °C
Typical temperature accuracy: ±0.1 °C
Relative humidity range: 0 to 100% RH
Typical humidity accuracy: ±1 percentage point RH
Chip supply: 1.08 to 3.6 V
Typical average current consumption: 0.4 µA
Conversion time: 6.9 ms typical and 8.3 ms maximum at high repeatability
Response to an environmental change: 2 s for temperature and 4 s for humidity to reach 63% of the change
Package: 4-pin DFN, 1.5 × 1.5 × 0.5 mm
Built-in features: Data verification by CRC and three-stage heater
Accuracy figures are typical and vary with temperature and humidity. Electronic conversion takes milliseconds, but the physical sensor needs a few seconds to reflect an environmental change.
SCHEMATIC:
The measurement values are displayed on an SSD1306 128x64 OLED.
The sensor body contains two potentiometers for simulation. When you start sim1 in Simulide and move these potentiometers, you will see the simulated temperature and humidity values.
SOFTWARE:
The sensor is implemented using a script. The operating program is very standard. No libraries are used for the sensor; only the typical OLED libraries are used. Both listings are shown below.
// SCRIPT SHT45, TEMPERATURE AND HUMIDITY MEASUREMENT. DEFRAN26A
IoPin@ sclPin = component.getPin("scl");
IoPin@ sdaPin = component.getPin("sda");
IoPin@ vddPin = component.getPin("vdd");
IoPin@ tempPin = component.getPin("vtemp");
IoPin@ humidPin = component.getPin("vhumid");
enum BusState { Idle, Address, Write, Send, SlaveAck, MasterAck, Ignore };
BusState state;
bool prevScl, prevSda, reading, accepted, masterAck, wroteCommand;
uint8 bits, incoming, outgoing, index;
const uint64 edgeDelay = 350000; // ps
array<uint8> frame(6);
bool busy, ready;
void setup()
{
print("SHT35s: script cargado");
}
void reset()
{
component.cancelEvents();
sclPin.setPinMode(2);
sdaPin.setPinMode(2);
vddPin.setPinMode(1);
tempPin.setPinMode(1);
humidPin.setPinMode(1);
state = Idle;
busy = false;
ready = false;
prevScl = true;
prevSda = true;
sclPin.setOutState(true);
sdaPin.setOutState(true);
sclPin.changeCallBack(element, true);
sdaPin.changeCallBack(element, true);
}
uint8 crc8(uint16 word)
{
uint8 crc = 0xff;
for (int shift = 8; shift >= 0; shift -= 8)
{
crc ^= uint8(word >> shift);
for (int bit = 0; bit < 8; bit++)
{
if ((crc & 0x80) != 0) crc = uint8((crc << 1) ^ 0x31);
else crc = uint8(crc << 1);
}
}
return crc;
}
uint16 encode(double value, double minimum, double span)
{
double scaled = (value - minimum) * 65535.0 / span;
if (scaled <= 0.0) return 0;
if (scaled >= 65535.0) return 65535;
return uint16(scaled + 0.5);
}
void putWord(uint8 pos, uint16 word)
{
frame[pos] = uint8(word >> 8);
frame[pos + 1] = uint8(word & 0xff);
frame[pos + 2] = crc8(word);
}
double inputFraction(IoPin@ pin)
{
double fraction = pin.getVoltage() / 3.30; // CALIBRATION_______
if (fraction < 0.0) return 0.0;
if (fraction > 1.0) return 1.0;
return fraction;
}
void runEvent()
{
double temperature = -40.0 + 165.0 * inputFraction(tempPin);
double humidity = 100.0 * inputFraction(humidPin);
putWord(0, encode(temperature, -45.0, 175.0));
putWord(3, encode(humidity, -6.0, 125.0));
busy = false;
ready = true;
}
bool receiveCommand(uint8 cmd)
{
if (cmd == 0x94)
{
component.cancelEvents();
busy = false;
ready = false;
return true;
}
if (cmd == 0x89)
{
putWord(0, 0x5348);
putWord(3, 0x5435);
ready = true;
return true;
}
uint64 timePs;
switch (cmd)
{
case 0xfd: timePs = 8300000000; break;
case 0xf6: timePs = 4500000000; break;
case 0xe0: timePs = 1600000000; break;
default: return false;
}
ready = false;
busy = true;
component.addEvent(timePs);
return true;
}
void sendBit()
{
sdaPin.scheduleState((outgoing & 0x80) != 0, edgeDelay);
outgoing = uint8(outgoing << 1);
bits--;
}
void startByte()
{
outgoing = frame[index];
bits = 8;
state = Send;
sendBit();
}
void voltChanged()
{
bool scl = sclPin.getInpState();
bool sda = sdaPin.getInpState();
if (sda != prevSda && scl)
{
if (sda) state = Idle;
else
{
state = Address;
incoming = 0;
bits = 8;
wroteCommand = false;
}
}
prevSda = sda;
if (scl == prevScl) return;
prevScl = scl;
if (scl)
{
if ((state == Address || state == Write) && bits > 0)
{
incoming = uint8((incoming << 1) | (sda ? 1 : 0));
bits--;
}
else if (state == MasterAck) masterAck = !sda;
return;
}
switch (state)
{
case Address:
if (bits != 0) break;
reading = (incoming & 1) != 0;
accepted = (incoming >> 1) == 0x44 && !busy && (!reading || ready);
sdaPin.scheduleState(!accepted, edgeDelay);
state = SlaveAck;
break;
case Write:
if (bits != 0) break;
accepted = !wroteCommand && receiveCommand(incoming);
wroteCommand = true;
sdaPin.scheduleState(!accepted, edgeDelay);
state = SlaveAck;
break;
case SlaveAck:
if (!accepted) state = Ignore;
else if (reading)
{
index = 0;
ready = false;
startByte();
}
else
{
sdaPin.scheduleState(true, edgeDelay);
incoming = 0;
bits = 8;
state = Write;
}
break;
case Send:
if (bits != 0) sendBit();
else
{
sdaPin.scheduleState(true, edgeDelay);
state = MasterAck;
}
break;
case MasterAck:
index++;
if (masterAck && index < 6) startByte();
else state = Ignore;
break;
default: break;
}
}
// SHT45 TEMPERATURE AND HUMIDITY PRECISION MEASUREMENT. DEFRAN26A
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
constexpr uint8_t SENSOR_ADDR = 0x44;
constexpr uint8_t OLED_ADDR = 0x3C;
Adafruit_SSD1306 oled(128, 64, &Wire, -1, 100000UL, 100000UL);
void loop()
{
uint8_t data[6] = {};
bool received = false;
if (sendCommand(0xFD))
{
delay(10);
if (Wire.requestFrom(SENSOR_ADDR, uint8_t(6)) == 6)
{
for (uint8_t &value : data) value = Wire.read();
received = true;
}
}
bool tempOk = received && validCrc(data);
bool humOk = received && validCrc(data + 3);
uint16_t rawTemp = (uint16_t(data[0]) << 8) | data[1];
uint16_t rawHum = (uint16_t(data[3]) << 8) | data[4];
float temperature = -45.0f + 175.0f * rawTemp / 65535.0f;
float humidity = constrain(-6.0f + 125.0f * rawHum / 65535.0f, 0.0f, 100.0f);
oled.clearDisplay();
showReading(0, F("TEMPERATURE"), tempOk, temperature, F(" \xF8" "C"));
oled.drawFastHLine(0, 31, 128, SSD1306_WHITE);
showReading(35, F("RELATIVE HUMIDITY"), humOk, humidity, F(" %"));
oled.display();
}
bool sendCommand(uint8_t command)
{
Wire.beginTransmission(SENSOR_ADDR);
Wire.write(command);
return Wire.endTransmission() == 0;
}
bool validCrc(const uint8_t *data)
{
uint8_t crc = 0xFF;
for (uint8_t i = 0; i < 2; i++)
{
crc ^= data[i];
for (uint8_t bit = 0; bit < 8; bit++)
{
if (crc & 0x80) crc = (crc << 1) ^ 0x31;
else crc <<= 1;
}
}
return crc == data[2];
}
void showReading(uint8_t y, const __FlashStringHelper *label, bool valid,
float value, const __FlashStringHelper *unit)
{
oled.setTextSize(1);
oled.setCursor(0, y);
oled.print(label);
oled.setCursor(0, y + 11);
if (!valid)
{
oled.print(F("Read error"));
return;
}
oled.setTextSize(2);
oled.print(value, 1);
oled.setTextSize(1);
oled.print(unit);
}
void setup()
{
Wire.begin();
Wire.setClock(100000UL);
if (!oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR, true, false)) {while (true) {}}
oled.setTextColor(SSD1306_WHITE);
oled.cp437(true);
sendCommand(0x94);
delay(20);
}
FILES PROVIDED:
The attached ZIP file includes: the schematic, the "ino" file, the "exe" file, all subcircuits used in this project, all located in the "data" directory and the SHT45 sensor. Simulide version 1.2 or higher is required.
Uploaded files: