资讯详情

SHT31温湿度传感器模块测量温度和湿度

目录

  • 一、简介
  • 二、使用前准备
  • 三、 测试方法
  • 四、实验现象
  • 五、总结

原文链接:https://www.yourcee.com/newsinfo/2929180.html

一、简介

SHT31数字温湿度传感器模块是新一代温湿度传感器,宽电压2.4~5.5V供电,采用IIC通信速度高达1MHz,湿度精度为±2 %RH ,温度精度为0.3 ℃,工作电流为800μA 。 在这里插入图片描述

原理框图
名称 描述
VCC 电源2.4~5.5V
GND 接地
SCL IIC串行时钟线/串行时钟线/SPI串行时钟端口
SDA IIC串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/串行数据线/SPI串行数据输入

二、使用前准备

SHT31数字温湿度传感器模块 I2C GY-SHT31-D环境检测

原装 uno r3开发板 编程 Atmega328P AVR 8位单片机

USB2.0打印机数据线高速方口连接转接线 A公对B公

杜邦线
SHT31数字温湿度传感器模块 I2C GY-SHT31-D环境检测 1个
原装 uno r3开发板 编程 Atmega328P AVR 8位单片机 1个
USB2.0打印机数据线高速方口连接转接线 A公对B公 1条
杜邦线 若干

三、 测试方法

用USB2.0打印机数据线高速方口连接转接线A公 uno r3开发板 编程 Atmega328P AVR 8位单片机连接在一起。原装 uno r3开发板 编程 Atmega328P AVR 8位单片机和SHT如下图所示

5V —— VCC GND —— GND SCL —— SCL SDA —— SDA 安装Arduino IDE,打开ArduinoIDE,点击项目然后点击加载库,搜索库管理器SHT31点击安装,如下图所示 点击文件,点击示例【Adafruit SHT31 Library】和【SHT31test】,最后点击上传,如下图所示 代码如下

/*************************************************** This is an example for the SHT31-D Humidity & Temp Sensor Designed specifically to work with the SHT31-D sensor from Adafruit ----> https://www.adafruit.com/products/2857 These sensors use I2C to communicate, 2 pins are required to interface ****************************************************/   #include <Arduino.h> #include <Wire.h> #include "Adafruit_SHT31.h"  bool enableHeater = false; uint8_t loopCnt = 0;  Adafruit_SHT31 sht31 = Adafruit_SHT31();  void setup() { 
           Serial.begin(9600);    while (!Serial)     delay(10);     // will pause Zero, Leonardo, etc until serial console opens    Serial.println("SHT31 test");
  if (! sht31.begin(0x44)) { 
           // Set to 0x45 for alternate i2c addr
    Serial.println("Couldn't find SHT31");
    while (1) delay(1);
  }

  Serial.print("Heater Enabled State: ");
  if (sht31.isHeaterEnabled())
    Serial.println("ENABLED");
  else
    Serial.println("DISABLED");
}


void loop() { 
        
  float t = sht31.readTemperature();
  float h = sht31.readHumidity();

  if (! isnan(t)) { 
          // check if 'is not a number'
    Serial.print("Temp *C = "); Serial.print(t); Serial.print("\t\t");
  } else { 
         
    Serial.println("Failed to read temperature");
  }
  
  if (! isnan(h)) { 
          // check if 'is not a number'
    Serial.print("Hum. % = "); Serial.println(h);
  } else { 
         
    Serial.println("Failed to read humidity");
  }

  delay(1000);

  // Toggle heater enabled state every 30 seconds
  // An ~3.0 degC temperature increase can be noted when heater is enabled
  if (loopCnt >= 30) { 
        
    enableHeater = !enableHeater;
    sht31.heater(enableHeater);
    Serial.print("Heater Enabled State: ");
    if (sht31.isHeaterEnabled())
      Serial.println("ENABLED");
    else
      Serial.println("DISABLED");

    loopCnt = 0;
  }
  loopCnt++;
}

四、实验现象

程序下载进去之后,显示温度30℃,湿度47%RH。

五、总结

波特率要选择正确,否则不会有有读数显示出来的。

标签: t7560温度传感器的精确度表电源传感器模块传感器连接can温度湿度传感器iict44传感器humidity传感器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台