The Arduino wiring and code for the SHT40, SHT41 and the SHT45 are identical!
- If you are running a Feather (3.3V), connect Feather 3V to board VIN
- If you are running a 5V Arduino (Uno, etc.), connect Arduino 5V to board VIN
- Connect Feather or Arduino GND to board GND
- Connect Feather or Arduino SCL to board SCL
- Connect Feather or Arduino SDA to board SDA
The final results should resemble the illustration above, showing an Adafruit Metro development board.
Installation
You can install the Adafruit SHT4X Library for Arduino using the Library Manager in the Arduino IDE:
Click the Manage Libraries ... menu item, search for Adafruit SHT4X, and select the Adafruit SHT4X library:
Then follow the same process for the Adafruit BusIO library.
Load Example
Open up File -> Examples -> Adafruit SHT4X -> SHT4test and upload to your Arduino wired up to the sensor.
Upload the sketch to your board and open up the Serial Monitor (Tools->Serial Monitor). You should see the the values for temperature and humidity.
Example Code
The following example code is part of the standard library, but illustrates how you can retrieve sensor data from the SHT40 for the temperature and humidity values:
/*************************************************** This is an example for the SHT4x Humidity & Temp Sensor Designed specifically to work with the SHT4x sensor from Adafruit ----> https://www.adafruit.com/products/4885 These sensors use I2C to communicate, 2 pins are required to interface ****************************************************/ #include "Adafruit_SHT4x.h" Adafruit_SHT4x sht4 = Adafruit_SHT4x(); void setup() { Serial.begin(115200); while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens Serial.println("Adafruit SHT4x test"); if (! sht4.begin()) { Serial.println("Couldn't find SHT4x"); while (1) delay(1); } Serial.println("Found SHT4x sensor"); Serial.print("Serial number 0x"); Serial.println(sht4.readSerial(), HEX); // You can have 3 different precisions, higher precision takes longer sht4.setPrecision(SHT4X_HIGH_PRECISION); switch (sht4.getPrecision()) { case SHT4X_HIGH_PRECISION: Serial.println("High precision"); break; case SHT4X_MED_PRECISION: Serial.println("Med precision"); break; case SHT4X_LOW_PRECISION: Serial.println("Low precision"); break; } // You can have 6 different heater settings // higher heat and longer times uses more power // and reads will take longer too! sht4.setHeater(SHT4X_NO_HEATER); switch (sht4.getHeater()) { case SHT4X_NO_HEATER: Serial.println("No heater"); break; case SHT4X_HIGH_HEATER_1S: Serial.println("High heat for 1 second"); break; case SHT4X_HIGH_HEATER_100MS: Serial.println("High heat for 0.1 second"); break; case SHT4X_MED_HEATER_1S: Serial.println("Medium heat for 1 second"); break; case SHT4X_MED_HEATER_100MS: Serial.println("Medium heat for 0.1 second"); break; case SHT4X_LOW_HEATER_1S: Serial.println("Low heat for 1 second"); break; case SHT4X_LOW_HEATER_100MS: Serial.println("Low heat for 0.1 second"); break; } } void loop() { sensors_event_t humidity, temp; uint32_t timestamp = millis(); sht4.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data timestamp = millis() - timestamp; Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C"); Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH"); Serial.print("Read duration (ms): "); Serial.println(timestamp); delay(1000); }
Page last edited January 22, 2025
Text editor powered by tinymce.