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 SDL Data
Yellow SDA Clock

Tutorial

Requirements

Connection Diagram

Sample Code

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

Read Temperature & Humidity Values

#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(&reg, 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

FAQ

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

More Documents

DFshopping_car1.png Get I2C Temperature & Humidity Sensor (Stainless Steel Shell) from DFRobot Store or DFRobot Distributor.

Turn to the Top