What's the purpose of this project?
The purpose of this project is to interface the SHT35 temperature and humidity sensor with an Arduino to measure and monitor environmental conditions with high precision. The SHT35 provides accurate readings of temperature and relative humidity, making it ideal for applications such as climate monitoring, indoor air quality control, and agricultural systems. By reading real-time data, users can design systems that dynamically respond to changes in temperature and humidity, enhancing functionality and reliability in various environmental and industrial applications.
What are we going to learn in this tutorial?
In this tutorial, you’ll learn how to:
- Connect the SHT35 sensor to Arduino and establish I2C communication.
- Utilize an existing library to simplify sensor integration, enhancing your understanding of I2C data handling.
- Read accurate temperature and humidity data from the sensor, interpreting it for real-world applications.
- Implement sensor-based projects for environmental monitoring and climate control, gaining practical skills for creating responsive systems based on environmental conditions.
This hands-on guide provides valuable insights into sensor integration and real-time environmental data monitoring with Arduino.
What do we need to start this project?
As you probably know, we need some hardware and software to do this project. The titles of these hardware and software are provided to you in the table below and you can prepare/download by clicking on each of them and get ready to start.
Required hardware
|
Required software
|
---|---|
Arduino UNO
|
|
First as shown in the image below, we connect the GebraBit SHT35 module to the Arduino UNO as follows:
Then download and add the GebraBit SHT35 library to your Arduino IDE.
Required Library
|
---|
If you don’t know how to add GebraBit libraries to Arduino IDE, refer to the tutorial link below.
SHT35 library and driver
In addition to the modular design of various sensors and ICs, GebraBit tries to provide variety of structured and hardware-independent libraries in C language for the ease of users in setting up and developing software.
For this purpose, after preparing each GebraBit module, the users can refer to the “tutorial” section of the desired module and download the dedicated library, which contains the “ .h” and “ .c” file (Header and Source) and a sample training program under “GebraBit STM32F303”, “GebraBit ATMEGA32A” or “Arduino” development boards.
All the defined functions and structures in the library are commented in full detail and all the received parameters in the arguments of the functions and their return values, are briefly explained. Since the libraries are hardware independed, the user can easily add the library in any of their favorite compilers and develop it by desired microcontroller and development board.
GebraBit_SHT35.h header file
In this file, based on the datasheet of the sensor or IC, all address registers, the values of each register are defined in the form of “Enumeration”. Also, the casing of the SHT35 sensor and the configurations related to each of the SHT35 sensor internal blocks are defined in the form of a “STRUCT” with the name GebraBit_SHT35. Finally, in the Debug Session environment, all the configurations related to each block can be seen in real time.
USER REGISTER MAP
The registry map or sensor commands are defined in this section:
/************************************************
* USER REGISTER MAP *
************************************************/
#define SHT35_SOFT_RESET_TIME 5
#define SHT35_ADDRESS 0x44
#define SHT35_READOUT_PERIODIC_MEASUREMENT_RESULT 0xE000
#define SHT35_ART 0x2B32
#define SHT35_BREAK_STOP 0x3093
#define SHT35_SOFT_RESET 0x30A2
#define SHT35_HEATER_ON 0x306D
#define SHT35_HEATER_OFF 0x3066
#define SHT35_READOUT_STATUS_REGISTER 0xF32D
#define SHT35_CLEAR_STATUS_REGISTER 0x3041
/*----------------------------------------------*
* USER REGISTER MAP End *
*----------------------------------------------*/
SHT35_Ability Enum
The ability to activate or deactivate different parts of the sensor is defined in this enum:
typedef enum Ability
{
Disable = 0 ,
Enable
}SHT35_Ability;
SHT35_Single_Shot_Mode Enum
The values of this enum are used to select different sensor measurement modes in Single Shot mode:
1. typedef enum Single_Shot_Mode
2. {
3. SHT35_HIGH_REPEATABILITY_CLOCK_STRETCHING = 0x2C06 ,
4. SHT35_MEDIUM_REPEATABILITY_CLOCK_STRETCHING = 0x2C0D ,
5. SHT35_LOW_REPEATABILITY_CLOCK_STRETCHING = 0x2C10 ,
6. SHT35_HIGH_REPEATABILITY_NO_CLOCK_STRETCHING = 0x2400 ,
7. SHT35_MEDIUM_REPEATABILITY_NO_CLOCK_STRETCHING = 0x240B ,
8. SHT35_LOW_REPEATABILITY_NO_CLOCK_STRETCHING = 0x2416
9. }SHT35_Single_Shot_Mode;
10.
SHT35_Periodic_Data_Acquisition_Mode Enum
The values of this enum are used to select different sensor data acquisition modes in periodic mode:
1. typedef enum Periodic_Data_Acquisition_Mode
2. {
3. SHT35_HIGH_REPEATABILITY_0P5_MPS_FREQUENCY = 0x2032 ,
4. SHT35_MEDIUM_REPEATABILITY_0P5_MPS_FREQUENCY = 0x2024 ,
5. SHT35_LOW_REPEATABILITY_0P5_MPS_FREQUENCY = 0x202F ,
6. SHT35_HIGH_REPEATABILITY_1_MPS_FREQUENCY = 0x2130 ,
7. SHT35_MEDIUM_REPEATABILITY_1_MPS_FREQUENCY = 0x2126 ,
8. SHT35_LOW_REPEATABILITY_1_MPS_FREQUENCY = 0x212D ,
9. SHT35_HIGH_REPEATABILITY_2_MPS_FREQUENCY = 0x2236 ,
10. SHT35_MEDIUM_REPEATABILITY_2_MPS_FREQUENCY = 0x2220 ,
11. SHT35_LOW_REPEATABILITY_2_MPS_FREQUENCY = 0x222B ,
12. SHT35_HIGH_REPEATABILITY_4_MPS_FREQUENCY = 0x2334 ,
13. SHT35_MEDIUM_REPEATABILITY_4_MPS_FREQUENCY = 0x2322 ,
14. SHT35_LOW_REPEATABILITY_4_MPS_FREQUENCY = 0x2329 ,
15. SHT35_HIGH_REPEATABILITY_10_MPS_FREQUENCY = 0x2737 ,
16. SHT35_MEDIUM_REPEATABILITY_10_MPS_FREQUENCY = 0x2721 ,
17. SHT35_LOW_REPEATABILITY_10_MPS_FREQUENCY = 0x272A
18. }SHT35_Periodic_Mode;
19.
SHT35_ Command_Status Enum
To know the status of commands sent to the sensor, the values of this enum are used:
1. typedef enum Command_Status
2. {
3. LAST_COMMAND_PROCESSED = 0 ,
4. LAST_COMMAND_NOT_PROCESSED = 1
5. }SHT35_Command_Status;
6.
SHT35_ Checksum_Status Enum
This enum is used to know the checksum status:
1. typedef enum Checksum_Status
2. {
3. ECKSUM_CORRECT = 0 ,
4. LAST_WRITE_CHECKSUM_FAILED = 1
5. }SHT35_Checksum_Status;
6.
SHT35_Measurement_Time Enum
This enum is used to choose when to convert data values:
1. typedef enum Measurement_Time
2. {
3. HIGH_REPEATABILITY_15_mS = 15 ,
4. MEDIUM_REPEATABILITY_6_mS = 6 ,
5. LOW_REPEATABILITY_4_mS = 4 ,
6. }SHT35_Measurement_Time;
7.
SHT35_ Heater Enum
Using this enum, the sensor internal heater is turned off or on:
1. typedef enum Heater
2. {
3. HEATER_ENABLE = SHT35_HEATER_ON ,
4. HEATER_DISABLE = SHT35_HEATER_OFF
5. }SHT35_Heater;
6.
SHT35_Alert_Pending_Status Enum
Using this enum, the status of sensor notifications and warnings is checked:
1. typedef enum Alert_Pending_Status
2. {
3. NO_PENDING_ALERT = 0,
4. AT_LEAST_ONE_PENDING_ALERT = 1
5. } SHT35_Alert_Pending_Status;
6.
SHT35_CRC_Status Enum
Using this enum, the status of the CRC check is specified:
1. typedef enum CRC_Status
2. {
3. CRC_ERROR = 0 ,
4. CRC_OK
5. }SHT35_CRC_Status;
6.
SHT35_Reset_Status Enum
By using this enum, the sensor reset status is specified:
1. typedef enum
2. {
3. NOT_DETECTED = 0 ,
4. DETECTED
5. }SHT35_Reset_Status;
6.
SHT35 struct
1. typedef struct SHT35
2. {
3. uint8_t Register_Cache;
4. SHT35_Reset RESET;
5. uint16_t COMMAND;
6. SHT35_Single_Shot_Mode SINGLE_SHOT_MODE;
7. SHT35_Periodic_Mode PERIODIC_MODE;
8. SHT35_Measurement_Time MEASUREMENT_TIME;
9. HTU31D_Ability ART;
10. uint16_t STATUS_REGISTER;
11. SHT35_Alert_Pending_Status ALERT_PENDING;
12. SHT35_Heater ON_CHIP_HEATER;
13. SHT35_Alert HUMIDITY_ALERT;
14. SHT35_Alert TEMPERATURE_ALERT;
15. SHT35_Command_Status COMMAND_STATUS;
16. SHT35_Checksum_Status CHECKSUM;
17. uint8_t SHT35_CRC;
18. SHT35_CRC_Status CRC_CHECK;
19. uint8_t ADC_RAW_DATA[ADC_RAW_DATA_BUFFER_SIZE];
20. uint16_t RAW_TEMPERATURE;
21. uint16_t RAW_HUMIDITY;
22. float TEMPERATURE;
23. float HUMIDITY;
24. // double PARTIAL_PRESSURE;
25. // double DEW_POINT;
26. }GebraBit_SHT35;
27.
Declaration of functions
At the end of this file, all the functions for reading and writing in SHT35 registers, sensor configuration and receiving data from the sensor are declared:
1. /********************************************************
2. * Declare Read&Write SHT35 Register Values Functions *
3. ********************************************************/
4. extern void GB_SHT35_Write_Command(GebraBit_SHT35 * SHT35 , uint16_t cmd);
5. /********************************************************
6. * Declare MS5611 Configuration Functions *
7. ********************************************************/
8. extern void GB_SHT35_Soft_Reset ( GebraBit_SHT35 * SHT35 ) ;
9. extern void GB_SHT35_CRC_Check( GebraBit_SHT35 * SHT35 , uint16_t value, uint8_t crc) ;
10. extern void GB_SHT35_On_Chip_Heater ( GebraBit_SHT35 * SHT35 , SHT35_Heater heater ) ;
11. extern void GB_SHT35_Read_Serial_Number ( GebraBit_SHT35 * SHT35 ) ;
12. extern void GB_SHT35_Read_Diagnostic ( GebraBit_SHT35 * SHT35 ) ;
13. extern void GB_SHT35_Configuration(GebraBit_SHT35 * SHT35) ;
14. extern void GB_SHT35_Start_Conversion ( GebraBit_SHT35 * SHT35 ) ;
15. extern void GB_SHT35_Read_Raw_Temperature_Humidity( GebraBit_SHT35 * SHT35 ) ;
16. extern void GB_SHT35_Temperature ( GebraBit_SHT35 * SHT35 ) ;
17. extern void GB_SHT35_Humidity ( GebraBit_SHT35 * SHT35 ) ;
18. extern void GB_SHT35_Dew_Point( GebraBit_SHT35 * SHT35 ) ;
19. extern void GB_SHT35_initialize( GebraBit_SHT35 * SHT35 ) ;
20. extern void GB_SHT35_Get_Data(GebraBit_SHT35 * SHT35);
21.
GebraBit_SHT35.c source file
In this file, which is written in C language, all the functions are commented in full detail, and all the parameters received in the arguments of the functions and their return values are clearly explained so we confine to these explanations and invite users to check this file directly for more information.
Sample program in Arduino
After connecting the module to Arduino and adding the library to the IDE, go to the following path: File > Examples > GebraBit_SHT35 > Temp-Humid
Description of Sample file
Enums and functions required by GebraBit SHT35 module have been added to the structures. In the next part, a variable named SHT35_Module of the GebraBit_SHT35 structure type (this structure is in the GebraBit_SHT35 header and is explained in the GebraBit_SHT35 library description section) is defined for the configuration of the GebraBit SHT35 module:
GebraBit_SHT35 SHT35;
In the next part of the written code, using the GB_SHT35_initialize (&SHT35_Module) and GB_SHT35_Configuration (&SHT35_Module) functions, we set the GebraBit SHT35 module and finally, in the while part of the program, the data is read from the sensor and the humidity and temperature values are continuously received:
void setup() {
Wire.begin(); // Initialize the I2C bus
Serial.begin(9600); // Initialize serial communication for debugging
GB_SHT35_initialize(&SHT35); // Initialize the SHT35 sensor
GB_SHT35_Configuration(&SHT35); // Configure the SHT35 sensor
}
void loop() {
GB_SHT35_Get_Data(&SHT35); // Read data from the sensor
Serial.print("Temperature: ");
Serial.print(SHT35.TEMPERATURE);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(SHT35.HUMIDITY);
Serial.println(" %");
delay(2000); // Delay between readings
}
The Sample file code text:
#include "GebraBit_SHT35.h"
GebraBit_SHT35 SHT35;
void setup() {
Wire.begin(); // Initialize the I2C bus
Serial.begin(9600); // Initialize serial communication for debugging
GB_SHT35_initialize(&SHT35); // Initialize the SHT35 sensor
GB_SHT35_Configuration(&SHT35); // Configure the SHT35 sensor
}
void loop() {
GB_SHT35_Get_Data(&SHT35); // Read data from the sensor
Serial.print("Temperature: ");
Serial.print(SHT35.TEMPERATURE);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(SHT35.HUMIDITY);
Serial.println(" %");
delay(2000); // Delay between readings
}
Connect your arduino to computer and select your Arduino Board
Then Verify and Upload the Sample code
After uploading the code, open the serial monitor and you can see the luminosity values.
In the following, you can download the GebraBit_SHT35 Library, the schematic of the modules and the “SHT35 datasheet”.
Program output video
The video of the module operation will be uploaded soon