找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 8078|回復(fù): 5
打印 上一主題 下一主題
收起左側(cè)

arduino lcd dht11值測出來一直顯示nan?

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:735294 發(fā)表于 2020-5-2 18:01 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
為什么我的溫濕度的值測出來一直顯示nan?有大佬可以幫忙解決一下嗎?
這是我的代碼:
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal.h>
#define DHTPIN 8
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
   //put your setup code here, to run once:
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("start");
  delay(1000);
  dht.begin();
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.println();
}
void loop() {
  
  // put your main code here, to run repeatedly:
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  Serial.println("\n");
  lcd.setCursor(0, 0);
  lcd.print("Hum:");
  lcd.setCursor(7, 0);
  lcd.print(h);
  lcd.setCursor(11, 0);
  lcd.print("%");
  lcd.setCursor(0, 1);
  lcd.print("Temp:");
  lcd.setCursor(7, 1);
  lcd.print(t);
  lcd.setCursor(11,1);
  lcd.print((char)223);      //液晶顯示“°”
  lcd.print("C");           //液晶顯示“C”
  Serial.print("Humidity: ");//濕度
  Serial.println(h);
  Serial.print("Temperature: ");//溫度
  Serial.print(t);
  Serial.println(" ℃ ");
  delay(2000);
}


51hei圖片_20200502164009.jpg (92.79 KB, 下載次數(shù): 103)

51hei圖片_20200502164009.jpg

51hei圖片_20200502164001.jpg (129.81 KB, 下載次數(shù): 120)

51hei圖片_20200502164001.jpg
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:762956 發(fā)表于 2020-5-27 22:27 來自手機(jī) | 只看該作者
我用示例沒問題,自己寫一個就是nan
回復(fù)

使用道具 舉報

板凳
ID:206950 發(fā)表于 2020-6-12 09:18 | 只看該作者
同問 我也是這個問題,溫濕度都是NAN
回復(fù)

使用道具 舉報

地板
ID:419968 發(fā)表于 2020-6-12 15:48 | 只看該作者
把 h t 轉(zhuǎn)換成字符串
回復(fù)

使用道具 舉報

5#
ID:868373 發(fā)表于 2020-12-26 16:52 | 只看該作者
我剛試了,用A5引腳就可以
回復(fù)

使用道具 舉報

6#
ID:868373 發(fā)表于 2020-12-26 16:54 | 只看該作者
用A2引腳就可以了,A5也行
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表