I2C Temperature & Humidity Sensor (Stainless Steel Shell) Wiki - DFRobot

Introduction

This I2C digital temperature & humidity sensor offers high accuracy of ±3.0RH% for humidity and ±0.5℃ for temperature, and features user-programmable humidity & temperature alarm function.
Its housing is made of 304 stainless steel to ensure good impact resistance, heat resistance, low temperature and chemical resistance. The sensor output is designed as DuPont 2.54 connector for easy wiring. Also, there are two built-in 4.7K pull-up resistors and one 100nF filtering capacitor so the sensor can be directly used with microcontrollers like Arduino.
This temperature & humidity sensor can be applied to electronic, medical, automotive, industrial, weather, and other fields, including home appliances like HVAC, dehumidifiers and refrigerators, testing & inspection equipment, and other relevant temperature & humidity measurements and controls.

Features

Specification

Pinout

Color Label Description
Red VCC +
Black GND -
White/Green SDL Data
Yellow SDA Clock

note:If the SCL is white, the chip signal is CHT8305; If the SCL is green, the chip model is CHT832X

Tutorial

Requirements

Connection Diagram

Sample Code(CHT8305)

Download and install the Arduino Library (About how to install the library?)

#include "Wire.h"
#define address 0x40
char dtaUart[15];
char dtaLen = 0;
uint8_t Data[100] = {0};
uint8_t buff[100] = {0};
void setup()
{
  Serial.begin(9600);
  Wire.begin();
}
uint8_t buf[4] = {0};
uint16_t data, data1;
float temp;
float hum;
void loop()
{
  readReg(0x00, buf, 4);
  data = buf[0] << 8 | buf[1];
  data1 = buf[2] << 8 | buf[3];
  temp = ((float)data * 165 / 65535.0) - 40.0;
  hum =  ((float)data1 / 65535.0) * 100;
  Serial.print("temp(C):");
  Serial.print(temp);
  Serial.print("\t");
  Serial.print("hum(%RH):");
  Serial.println(hum);
  delay(500);
}
uint8_t readReg(uint8_t reg, const void* pBuf, size_t size)
{
  if (pBuf == NULL) {
    Serial.println("pBuf ERROR!! : null pointer");
  }
  uint8_t * _pBuf = (uint8_t *)pBuf;
  Wire.beginTransmission(address);
  Wire.write(®, 1);
  if ( Wire.endTransmission() != 0) {
    return 0;
  }
  delay(20);
  Wire.requestFrom(address, (uint8_t) size);
  for (uint16_t i = 0; i < size; i++) {
    _pBuf[i] = Wire.read();
  }
  return size;
}

Result

Sample Code(CHT832X)

#include <Wire.h>
#define SENSOR_ADDR 0x44  

void setup() {
  Serial.begin(9600);
  Wire.begin();           
  delay(100);             
}

void loop() {
  Wire.beginTransmission(SENSOR_ADDR);
  Wire.write(0x24);       
  Wire.write(0x00);       
  int error = Wire.endTransmission();

  if (error != 0) {
    Serial.println("Command sending failed!");
    return;
  }

  delay(60);              


  Wire.requestFrom(SENSOR_ADDR, 6);
  if (Wire.available() == 6) {
    // Read temperature data
    uint16_t temp_raw = (Wire.read() << 8) | Wire.read();
    Wire.read();         

    // Read humidity data
    uint16_t humi_raw = (Wire.read() << 8) | Wire.read();
    Wire.read();          

    float temperature = -45.0 + 175.0 * (temp_raw / 65535.0);
    float humidity = 100.0 * (humi_raw / 65535.0);


    Serial.print("temperature: ");
    Serial.print(temperature, 2);
    Serial.print("°C \thumidity: ");
    Serial.print(humidity, 2);
    Serial.println(" %RH");
  } else {
    Serial.println("Data read failed!");
  }

  delay(500);          
}

Result

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents