Arduino温度报警器
时间: 2024-01-15 09:18:44 浏览: 43
以下是使用Arduino制作温度报警器的步骤:
1. 准备材料:
- Arduino UNO开发板
- DHT11温湿度传感器
- LCD1602液晶显示屏
- LCD1602转接板
- 面包板
- 连接线若干
- 蜂鸣器
2. 连接电路:
- 将DHT11传感器连接到Arduino UNO开发板上的数字引脚2。
- 将LCD1602液晶显示屏连接到Arduino UNO开发板上的I2C总线上。
- 将蜂鸣器连接到Arduino UNO开发板上的数字引脚3。
3. 编写代码:
- 使用Arduino IDE打开一个新的项目。
- 导入DHT库和Wire库。
- 初始化LCD1602液晶显示屏。
- 设置蜂鸣器引脚为输出模式。
- 在循环中读取DHT11传感器的温度值。
- 如果温度超过设定的阈值,则触发蜂鸣器报警,并在液晶显示屏上显示温度和报警信息。
4. 上传代码:
- 将Arduino UNO开发板连接到计算机上。
- 选择正确的开发板和端口。
- 点击上传按钮将代码上传到Arduino UNO开发板。
5. 测试:
- 将DHT11传感器放置在不同的温度环境中,观察液晶显示屏和蜂鸣器的反应。
以下是一个示例代码:
```arduino
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
int buzzerPin = 3;
void setup() {
dht.begin();
lcd.begin(16, 2);
lcd.print("Temperature Alarm");
lcd.setCursor(0, 1);
lcd.print("System Initializing");
delay(2000);
lcd.clear();
pinMode(buzzerPin, OUTPUT);
}
void loop() {
float temperature = dht.readTemperature();
if (temperature > 25) {
lcd.setCursor(0, 0);
lcd.print("Temperature:");
lcd.setCursor(0, 1);
lcd.print(temperature);
lcd.print("C");
digitalWrite(buzzerPin, HIGH);
delay(1000);
digitalWrite(buzzerPin, LOW);
delay(1000);
} else {
lcd.clear();
lcd.print("Temperature:");
lcd.setCursor(0, 1);
lcd.print(temperature);
lcd.print("C");
}
delay(2000);
}
```
相关推荐
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)