Skip to content

Repository for Sensirion humidity and temperature sensor support on Arduino

License

Notifications You must be signed in to change notification settings

arduino-hmueller01/arduino-sht

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

arduino-sht

Repository for Sensirion humidity and temperature sensor support on Arduino

Supported sensors:

  • SHTC1
  • SHTC3
  • SHTW1
  • SHTW2
  • SHT2x (SHT20, SHT21, SHT25)
  • SHT3x-DIS (I2C)
  • SHT3x-ARP (ratiometric analog voltage output)
  • SHT85
  • SHT4x

For sht3x and sht4x there are specific drivers available in separate repositories.

Installation

The recommended way to install arduino-sht is through the Library Manager of the Arduino IDE. To access it, go to the Tools menu and select Manage Libraries..., and search for the library name there.

If you prefer to install it manually, you can download either via git or from the releases page and place it in your Arduino/libraries directory. After restarting the Arduino IDE, you will see the new SHTSensor menu items under libraries and examples.

Integrating it into your sketch

Assuming you installed the library as described above, the following steps are necessary:

  1. Import the Wire library like this: From the menu bar, select Sketch > Import Library > Wire
  2. Import the arduino-sht library: From the menu bar, select Sketch > Import Library > arduino-sht
  3. Create an instance of the SHTSensor class (SHTSensor sht;)
  4. In setup(), make sure to init the Wire library with Wire.begin()
  5. Also in setup(), call sht.init()
  6. If you want to use the serial console, remember to initialize the Serial library with Serial.begin(9600)
  7. Call sht.readSample() in the loop() function, which reads a temperature and humidity sample from the sensor
  8. Use sht.getHumidity() and sht.getTemperature() to get the values from the last sample

Important: getHumidity() and getTemperature() do not read a new sample from the sensor, but return the values read last. To read a new sample, make sure to call readSample()

Using an custom or alternative I2C port/Wire instance

Some Arduino boards have multiple predefined I2C ports; generally, the second port will be called Wire1.

The arduino-sht library allows to use an alternative interface; to do so, pass the port you want to use as an argument to sht.init(), like this:

  if (sht.init(Wire1)) {
      Serial.print("init(): success\n");
  } else {
      Serial.print("init(): failed\n");
  }

Example projects

See example project sht-autodetect

Usage with multiple SHT31 sensors

See example project multiple-sht-sensors

About

Repository for Sensirion humidity and temperature sensor support on Arduino

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 99.7%
  • C 0.3%