AS7341可见光传感器

简介

SHT4X是业内知名的Sensirion公司推出的第四代数字温湿度传感器系列。传承了盛思锐湿度和温度传感器在业界有口皆碑的质量和可靠性,SHT40 可在广阔的测量范围内提供始终如一的高精确度,为用户带来最佳的性价比。
SHT40凭借宽电源电压范围 (3.3 – 5 V) 和顶尖精度(±1.8% 相对湿度,±0.2℃),它拥有更出色的灵活性。
SHT40可以测量 0 至 100% 的相对湿度以及 -40℃ 至 125℃ 的温度,可以达到 ±1.8%的湿度精度和 ±0.2℃温度精度。
SHT40集成可变功率加热器,在冷凝环境也可以正常工作。
凭借 3.3 V 至 5 V 的宽电源电压以及低于0.15mA的低功耗模式,SHTC40非常适合移动和电池驱动型应用,可以非常容易的集成到智能楼宇、天气站、仓库存储、养殖、孵化等应用场景中。

特性

  • 高精度
  • 低功耗
  • 体积小
  • 响应快

应用场景

  • 智能楼宇、家具
  • 天气站
  • 仓库存储
  • 动物、植物养殖
  • 动物孵化箱
  • 植物种子发芽箱

技术规格

  • 通信接口:I2C
  • 工作电压:3.3V-5V
  • 工作电流:0.34mA(3.3v) / 0.43mA(5v)
  • 湿度测量范围:0~100%相对湿度
  • 湿度测量精度: ±1.8%
  • 温度测量范围:-40~+125℃(-40~+275℉)
  • 温度测量精度:±0.2℃
  • 响应时间:8S(tau63%)
  • 模块尺寸:14*17mm
  • 安装孔尺寸:M2(2mm)
  • 安装孔间距:10mm

引脚说明

序号 丝印 功能描述
1 VCC 电源正极
2 GND 电源负极
3 SCL I2C时钟线
4 SDA I2C数据线

使用教程

准备

关于如何安装库文件,点击链接

  • 主要API接口函数列表

  /**
   * @brief  对主控板的IIC进行了初始化
   */
  void begin();

  /**
   * @brief  获取温度数据
   * @return 温度值,单位:摄氏度
   */
  float getTemperature();

  /**
   * @brief  获取湿度数据
   * @return 湿度值,单位:%RH
   */
  float getHumidity();

  /**
   * @brief  获取温湿度数据
   * @param   tem  存放温度数据的引用
   * @param   hum  存放湿度数据的引用
   */
  void  getTemHum(float &tem, float &hum);

  /**
   * @brief  设置传感器工作模式
   * @param  mode  传感器的工作模式
   * @n            SHTC3:
   * @n                    PRECISION_HIGH_CLKSTRETCH_ON                              Clock Stretching Enabled 
   * @n                    PRECISION_HIGH_CLKSTRETCH_OFF                             Clock Stretching Disabled 
   * @n                    PRECISION_LOW_CLKSTRETCH_ON                               Clock Stretching Enabled & Low Power
   * @n                    PRECISION_LOW_CLKSTRETCH_OFF                              Clock Stretching Disabled & Low Power
   * @n            SHT40:
   * @n                    PRECISION_HIGH_HEATER_OFF                                 measure T & RH with high precision (high repeatability) 
   * @n                    PRECISION_MID_HEATER_OFF                                  measure T & RH with medium precision (medium repeatability)
   * @n                    PRECISION_LOW_HEATER_OFF                                  measure T & RH with lowest precision (low repeatability) 
   * @n                    PRECISION_HIGH_HEATER_1S                                  activate highest heater power & high precis. meas. (typ. 200mW @ 3.3V) for 1s 
   * @n                    PRECISION_HIGH_HEATER_100MS                               activate highest heater power & high precis. meas. (typ. 200mW @ 3.3V) for 0.1s
   * @n                    PRECISION_MID_HEATER_1S                                   activate medium heater power  & high precis. meas. (typ. 110mW @ 3.3V) for 1s 
   * @n                    PRECISION_MID_HEATER_100MS                                activate medium heater power  & high precis. meas. (typ. 110mW @ 3.3V) for 0.1s 
   * @n                    PRECISION_LOW_HEATER_1S                                   activate lowest heater power  & high precis. meas. (typ. 20mW @ 3.3V) for 1s 
   * @n                    PRECISION_LOW_HEATER_100MS                                activate lowest heater power  & high precis. meas. (typ. 20mW @ 3.3V) for 0.1s 
   */
   void setMode(uint16_t mode) ;

  /**
   * @brief  获取传感器的唯一标识符
   * @return 获取成功返回传感器的唯一标识符,失败返回0
   */
   uint32_t getDeviceID();

  /**
   * @brief  software reset
   */
   void softwareReset() ;

  /**
   * @brief  Obtain raw data of temperature and humidity
   * @param  temp Pointer to the address of the original value of the temperature
   * @param  hun   Pointer to the address of the original value of the humidity
   * @return Is the data obtained correct? return true  The data is correct ; return false  The data  is incorrect
   */
   bool getTandRHRawData(uint16_t *temp, uint16_t *hum);

接线图

样例代码 - 读取数据

烧录程序,获取当前的温度与湿度数据

/*!
 * @file temperatureAndHumidity.ino
 * @brief Measurement of temperature and humidity
 * @n 本传感器可测量温湿度数据,温度的测量范围在-40~125 ℃ ,湿度的测量范围在 0~100 %RH。
 * @n 本传感器提供高、中、低,三种测量精度,还提供了高、中、低,三种加热功率对片上加热器进行加热。
 * @n 使用加热器的主要情景:
 * @n 1、Removal of condensed / spray water on the sensor surface. Although condensed water is not a reliability / quality problem to the sensor, it will however make the sensor nonresponsive to RH changes in the air as long as there is liquid water on the surface.
 * @n 2、Creep-free operation in high humid environments. Periodic heating pulses allow for creepSTXfree high-humidity measurements for extended times.
 * @n 实验现象 每次1秒钟测量一次温湿度数据并且通过串口打印,当湿度超过80%RH时,启动一次加热器。
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (https://www.dfrobot.com)
 * @licence     The MIT License (MIT)
 * @author [yangfeng]<feng.yang@dfrobot.com>
 * @version  V1.0
 * @date  2021-03-19
 * @get from https://www.dfrobot.com
 * @url  https://github.com/DFRobot/DFRobot_SHT
 */
#include"DFRobot_SHT40.h"

/** 
 *  对于SHT40传感器这里支持两种型号,第一种是SHT40_AD1B, 第二种是SHT40_BD1B,这两种型号对应不同的IIC设备地址,这里对它们进行了封装,用户可传入如下两种参数
 *  型号为SHT40_AD1B的传感器使用:    SHT40_AD1B_IIC_ADDR
 *  型号为SHT40_AD1B的传感器使用:    SHT40_BD1B_IIC_ADDR
 */
DFRobot_SHT40 SHT40(SHT40_AD1B_IIC_ADDR); 


uint32_t id = 0;
float temperature, humidity;

void setup() {

  Serial.begin(9600);
  SHT40.begin();

  while((id = SHT40.getDeviceID()) == 0){
    Serial.println("ID retrieval error, please check whether the device is connected correctly!!!");
    delay(1000);
  }

  delay(1000);
  Serial.print("id :0x"); Serial.println(id, HEX);

}

void loop() {
  /**
   *    mode 用来配置传感器的工作模式
   *                  PRECISION_HIGH                       measure T & RH with high precision (high repeatability) 
   *                  PRECISION_MID                        measure T & RH with medium precision (medium repeatability)
   *                  PRECISION_LOW                        measure T & RH with lowest precision (low repeatability) 
   */
  temperature = SHT40.getTemperature(/*mode = */PRECISION_HIGH);
  /**
   *    mode 用来配置传感器的工作模式
   *                  PRECISION_HIGH                       measure T & RH with high precision (high repeatability) 
   *                  PRECISION_MID                        measure T & RH with medium precision (medium repeatability)
   *                  PRECISION_LOW                        measure T & RH with lowest precision (low repeatability) 
   */
  humidity = SHT40.getHumidity(/*mode = */PRECISION_HIGH);

  if(temperature == MODE_ERR){
    Serial.println("Incorrect mode configuration to get temperature");
  } else{
    Serial.print("Temperature :"); Serial.print(temperature); Serial.println(" C");
  }
  if(humidity == MODE_ERR){
    Serial.println("The mode for getting humidity was misconfigured");
  } else{
    Serial.print("Humidity :"); Serial.print(humidity); Serial.println(" %RH");
  }

  /**
   *    mode 用来配置传感器的工作模式
   *                  PRECISION_HIGH                       measure T & RH with high precision (high repeatability) 
   *                  PRECISION_MID                        measure T & RH with medium precision (medium repeatability)
   *                  PRECISION_LOW                        measure T & RH with lowest precision (low repeatability) 
   */
  //if(SHT40.getTemHum(temperature,humidity,PRECISION_HIGH)){
  //  Serial.print("Temperature :"); Serial.print(temperature); Serial.println(" C");
  //  Serial.print("Humidity :"); Serial.print(humidity); Serial.println(" %RH");
  //} else{
  //  Serial.println("Pattern configuration error");
  //}
  if(humidity > 80){
  /**
   *    mode 用来配置传感器的工作模式
   *                  POWER_CONSUMPTION_H_HEATER_1S                        activate highest heater power & high precis. meas. for 1s 
   *                  POWER_CONSUMPTION_H_HEATER_100MS                     activate highest heater power & high precis. meas. for 0.1s
   *                  POWER_CONSUMPTION_M_HEATER_1S                         activate medium heater power  & high precis. meas. for 1s 
   *                  POWER_CONSUMPTION_M_HEATER_100MS                      activate medium heater power  & high precis. meas. for 0.1s 
   *                  POWER_CONSUMPTION_L_HEATER_1S                         activate lowest heater power  & high precis. meas. for 1s 
   *                  POWER_CONSUMPTION_L_HEATER_100MS                      activate lowest heater power  & high precis. meas. for 0.1s 
   */
    SHT40.enHeater(/*mode = */POWER_CONSUMPTION_H_HEATER_1S);
  }
  delay(1000);

  Serial.println("----------------------------------------");
}

结果

打开串口显示当前的温度和湿度数据

SEN0364result1

常见问题

还没有客户对此产品有任何问题,欢迎通过qq或者论坛联系我们!

更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖。

更多

DFshopping_car1.png DFRobot商城购买链接