搜索代码

DHT22 温湿度在 Arduino RJT43 的 7 段显示器上

DHT22 温湿度在 Arduino RJT43 的 7 段显示器上

该项目演示了如何使用Arduino构建一个简单而有效的系统,以在7段显示器上显示温度和湿度读数。该设置适用于需要监测环境条件的各种应用。该项目将DHT22温湿度传感器与TM1637 7段显示器结合在一起,提供清晰且易于读取的输出。

DHT22 sensor with PCB-1
Arduino wriing DHT11 PCB module  module with TM1637

项目创意:

  • 监测家庭环境以实现最佳舒适度。
  • 在温室或生态瓶中跟踪条件。
  • 搭建一个基本的气象站。
  • 在数据记录项目中显示温度和湿度。

硬件/组件

要构建此项目,您需要以下组件:

  • Arduino Uno(或兼容板)
  • DHT22 温湿度传感器
  • TM1637 七段显示器
  • 连接电线
  • 面包板(可选,但推荐使用)

布线指南

Arduino wriing DHT11 PCB module  module with TM1637
Arduino wriing DHT11 PCB module module with TM1637
Arduino wriing DHT11 bare module  module with TM1637
Arduino wriing DHT11 bare module module with TM1637
Arduino wriing DHT11 bare module  module with TM1637
Arduino wriing DHT11 bare module module with TM1637

接线很简单。请参考视频(在视频中的 01:51)以获取视觉指导。主要连接为:

  • TM1637 显示器:VCC连接到5V,GND连接到GND,CLK连接到Arduino引脚2,DIO连接到Arduino引脚3(视频中的时间是02:00)。
  • DHT22传感器:VCC 接到 5V,GND 接到 GND,DATA 接到 Arduino 引脚 9(视频中的时间是 02:20)。请注意,视频中使用 Arduino 引脚 8 为传感器提供 5V(视频中的时间是 02:41)。

代码解释

Arduino代码使用了两个库:TM1637Display用于七段显示器,DHT用于DHT22传感器。代码的可配置参数主要位于开头:


// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3
#define DHTPIN 9     // DHT22 data pin
#define DHTTYPE DHT22   // DHT sensor type

这些行定义了连接到显示屏和DHT22传感器的Arduino引脚。如果您使用不同的引脚,您可能需要调整这些设置。getTemp()在视频的07:03处,函数是关键。通过传递字符串参数,它使您能够从DHT22传感器检索不同的值:


float getTemp(String req) {
  // ... (Sensor reading code) ...
  if(req =="c"){ return t; } // Celsius
  else if(req =="f"){ return f; } // Fahrenheit
  // ... (Other options for Kelvin, humidity, heat index) ...
}

此功能简化了从传感器读取不同数据(摄氏度、华氏度、湿度、热指数)。主循环使用此功能获取数据并在七段显示器上显示,将浮点值四舍五入为整数以便于显示(视频中在07:14)。

现场项目/演示

视频(在00:32的录像中)展示了该项目的现场演示。7段显示器清楚地显示了华氏温度。视频还演示了如何修改代码以显示摄氏度、开尔文、湿度和热指数值(在08:21的录像中)。

章节

  • [00:06] 引言和项目概述
  • [00:53] 入门和组件概述
  • [01:51] 连接TM1637显示屏
  • [02:20] 接线 DHT22 传感器
  • [03:14] 代码说明:TM1637 设置
  • [04:00] 代码说明:DHT22 设置
  • [05:54] 代码说明:主循环和显示功能
  • [07:03] 代码说明:getTemp() 函数
  • [08:21] 演示和不同的输出选项

图像

DHT22 sensor with PCB-1
DHT22 sensor with PCB-1
DHT22 with PCB red
DHT22 with PCB red
DHT22 sensor no PCB
DHT22 sensor no PCB
Arduino wriing DHT11 PCB module  module with TM1637
Arduino wriing DHT11 PCB module module with TM1637
Arduino wriing DHT11 PCB module  module with TM1637
Arduino wriing DHT11 PCB module module with TM1637
Arduino wriing DHT11 bare module  module with TM1637
Arduino wriing DHT11 bare module module with TM1637
Arduino wriing DHT11 bare module  module with TM1637
Arduino wriing DHT11 bare module module with TM1637
56-Arduino code and video for a DHT12 Temperature and Humidity Sensor with TM1637 Display
语言: C++
This code has not been parsed yet. Please return to the admin panel to parse it.

资源与参考

尚无可用资源。

文件📁

Arduino 库(zip 格式)

Fritzing 文件

用户手册