網站首頁 編程語言 正文
獲取驅動庫
首先,我們利用arduino的IDE獲取溫濕度傳感器的驅動庫,庫管理器中搜索dht11即可。
如果發現有其他依賴的庫需要安裝,也一起安裝吧!
測試驅動庫
安裝好了之后,我們就可以在IDE的實例庫中找到測試實例
打開實例,編譯一次,發現沒有問題,那么說明我們的驅動庫下載好了。接下來我們就可以打開proteus繪制電路圖,來仿真了。
proteus仿真
繪制電路圖
代碼
代碼為測試dht11的代碼,即驅動實例庫中自帶:
#include "DHT.h"
#define DHTPIN 8 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
}
仿真
原文鏈接:https://blog.csdn.net/haigear/article/details/125984195
相關推薦
- 2022-07-01 Python數據可視化繪圖實例詳解_python
- 2022-06-06 CSS3動畫:wifi 焦點擴散漸變
- 2022-07-01 iOS?DispatchSourceTimer?定時器的具體使用_IOS
- 2023-07-22 Redis使用教程之jedis客戶端sendCommand方法的byte[]入參,防止混淆strin
- 2022-05-09 Python數據結構與算法中的棧詳解(1)_python
- 2022-12-24 C++中析構函數為何是虛函數_C 語言
- 2022-08-02 Android開發自定義雙向SeekBar拖動條控件_Android
- 2022-12-27 K8S集群范圍使用imagePullSecret示例詳解_云和虛擬化
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支