• 做一个物联网温湿度传感器(一)SHT30传感器介绍


    摘要:本文介绍物联网项目设计时常用的传感器之一——温湿度传感器。以SHT30传感器为例。

    在阿里云物联网HaaS开发案例中,有一个全自动加湿器,使用的是SHT30温湿度传感器。就是下面这个案例。

     该传感器的外观有很多种,最常见的是这种电路板式的。

     

     还有这种带有外壳的,核心的器件都是相同的。驱动也是相同的。

     供电电压是2.4V到5.5V,所以常见的arduino控制器以及ESP32等都是可以用的。

     引脚定义如下图所示。通信协议选择IIC协议。

     通信时序图如下所示。

     下面用arduino来测试一下,具体连线如下图所示,供电采用3.3V。用5V也没关系,不会烧掉芯片。请注意用UNO,这个板子上没有专用的SCL SDA接线柱,然后它是用的A4复用为SDA,A5复用为SCL。

     

     

    arduino版本

     驱动直接下载库

     编程的源代码如下所示。

    1. //本程序是用UNO连接温湿度传感器SHT30
    2. //供电用3.3V
    3. //传感器的SCL连接UNO的A5
    4. //传感器的SDA连接UNO的A4
    5. //串口波特率是9600
    6. //温湿度传感器的库,选择Adafruit_SHT31
    7. #include
    8. #include
    9. #include "Adafruit_SHT31.h"
    10. Adafruit_SHT31 sht31 = Adafruit_SHT31();
    11. void setup() {
    12. Serial.begin(9600);
    13. while (!Serial)
    14. delay(10); // will pause Zero, Leonardo, etc until serial console opens
    15. Serial.println("SHT31 test");
    16. if (! sht31.begin(0x44)) { // Set to 0x45 for alternate i2c addr
    17. Serial.println("Couldn't find SHT31");
    18. while (1) delay(1);
    19. }
    20. }
    21. void loop() {
    22. float t = sht31.readTemperature();
    23. float h = sht31.readHumidity();
    24. if (! isnan(t)) { // check if 'is not a number'
    25. Serial.print("Temp *C = "); Serial.println(t);
    26. } else {
    27. Serial.println("Failed to read temperature");
    28. }
    29. if (! isnan(h)) { // check if 'is not a number'
    30. Serial.print("Hum. % = "); Serial.println(h);
    31. } else {
    32. Serial.println("Failed to read humidity");
    33. }
    34. Serial.println();
    35. delay(1000);
    36. }

    使用arduino自带的串口显示数据

     使用arduino调试,读取出来正确的温湿度之后,这些数据就可以作为参考,下一步使用ESP32来调试,并且将温湿度上传到阿里云物联网平台上。

     

    敬请期待。

     

  • 相关阅读:
    赛力斯上半年营收124亿亏17亿:与华为深度捆绑 已推两款车型
    10个PyCharm常用的免费插件,让开发迅速飙升
    MyBatisPlus入门学习笔记
    中国雪深长时间序列数据集(1979-2020)
    About Statistical Distributions
    传输层 选择性确认 SACK
    初识设计模式 - 迭代器模式
    算法竞赛入门【码蹄集进阶塔335题】(MT2321-2325)
    10分钟理解React生命周期
    vue3 tsx 项目中使用 Antv/G2 实现多线折线图
  • 原文地址:https://blog.csdn.net/youngwah292/article/details/126674049