风筝
发表于: 2020-4-13 19:05:01 | 显示全部楼层

在本篇文章中,我们将使用SHT3x传感器和Arduino设计湿度计和温度计。我们将把SHT31湿度和温度传感器与Arduino连接,并在1602 LCD显示屏上显示温度和湿度值。


与其他温度传感器(例如LM35、热敏电阻、DS18B20和DHT11 / DHT22)相比,SHT3x传感器是用于测量湿度和温度参数的最准确、最精确的传感器。因此SHT3x的高精度和高灵敏度可用于工业应用。其相对湿度工作范围为0 – 100%,温度工作范围为-40°至+ 125°C(-40°至+ 257°F)。

Interfacing-SHT3x-Arduino.jpg


所需的组件

●    Arduino UNO开发板

●    SHT3x湿度和温度传感器

●    1602 LCD显示屏

●    面包板

●    连接线


Sensirion SHT3x系列温湿度传感器

新的数字SHT3x湿度传感器系列将传感器技术提升到了一个新的高度。作为SHT2x系列的后继产品,它确定了湿度传感器的下一个行业标准。 SHT3x湿度传感器系列包括湿度传感器的低成本版本SHT30、湿度传感器的标准版本SHT31以及湿度传感器的高端版本SHT35。 SHT3x湿度传感器系列结合了多种功能和各种接口(I2C、模拟电压输出)以及易于使用的非常宽的工作电压范围(2.15至5.5 V)。 SHT3x湿度传感器可提供大容量和小容量两种型号。

SHT3x-Sensor.png


其功能包括:

●    高可靠性和长期稳定性

●    专为批量生产而设计

●    高处理能力

●    低信号噪声

●    输出:I2C,电压输出

●    电源电压范围:2.4至5.5V

●    RH工作范围:0-100%RH

●    温度工作范围:-40°至+ 125°C

●    RH响应时间:8秒


连接电路图

如下图所示组装电路:

Circuit-Diagram-1.jpg


将LCD引脚4、6、11、12、13、14分别连接到Arduino 12、11、5、4、3、2数字引脚。

将SHT31的SDA和SCL引脚分别连接到Arduino的SDA和SCL引脚,即分别为A4和A5。


源代码/程序

以下是用于将SHT3x与Arduino连接以读取湿度和温度的源代码。复制代码并将其上传到Arduino开发板。您需要SHT3x传感器库。从这里下载库:SHT31库

  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd (12,11,5,4,3,2);
  3. #include <Arduino.h>
  4. #include <Wire.h>
  5. #include "Adafruit_SHT31.h"

  6. Adafruit_SHT31 sht31 = Adafruit_SHT31();
  7. byte degree[8] =
  8. {
  9. 0b00011,
  10. 0b00011,
  11. 0b00000,
  12. 0b00000,
  13. 0b00000,
  14. 0b00000,
  15. 0b00000,
  16. 0b00000
  17. };

  18. void setup() {
  19. Serial.begin(9600);
  20. lcd.begin(16,2);
  21. lcd.createChar(1, degree);

  22. while (!Serial)
  23. delay(10); // will pause Zero, Leonardo, etc until serial console opens

  24. Serial.println("SHT31 test");
  25. if (! sht31.begin(0x44)) { // Set to 0x45 for alternate i2c addr
  26. Serial.println("Couldn't find SHT31");
  27. while (1) delay(1);
  28. }
  29. }

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

  33. if (! isnan(t)) { // check if 'is not a number'
  34. Serial.print("Temp *C = "); Serial.println(t);
  35. lcd.print("Temp = ");
  36. lcd.print(t);
  37. lcd.write(1);
  38. lcd.print("C");
  39. } else {
  40. Serial.println("Failed to read temperature");
  41. lcd.print("Temperature Error");
  42. }

  43. if (! isnan(h)) { // check if 'is not a number'
  44. Serial.print("Hum. % = "); Serial.println(h);
  45. lcd.setCursor (0,1);
  46. lcd.print("Hum. = ");
  47. lcd.print(h);
  48. lcd.print(" %");
  49. } else {
  50. Serial.println("Failed to read humidity");
  51. lcd.setCursor (0,1);
  52. lcd.print("Humidity Error");
  53. }
  54. Serial.println();
  55. delay(1000);
  56. lcd.clear();
  57. }
复制代码

跳转到指定楼层
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题 700 | 回复: 1479



手机版|

GMT+8, 2024-3-29 07:37 , Processed in 0.149997 second(s), 6 queries , Gzip On, MemCache On. Powered by Discuz! X3.5

YiBoard一板网 © 2015-2022 地址:河北省石家庄市长安区高营大街 ( 冀ICP备18020117号 )

快速回复 返回顶部 返回列表