Arduino 教程Arduino 濕傳感器_第1頁(yè)
Arduino 教程Arduino 濕傳感器_第2頁(yè)
Arduino 教程Arduino 濕傳感器_第3頁(yè)
Arduino 教程Arduino 濕傳感器_第4頁(yè)
Arduino 教程Arduino 濕傳感器_第5頁(yè)
已閱讀5頁(yè),還剩1頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、第三十五課 Arduino 濕度傳感器在本節(jié)中,我們將學(xué)習(xí)如何使用不同的傳感器連接我們的Arduino板。我們將討論以下傳感器:· 濕度傳感器(DHT22)· 溫度傳感器(LM35)· 水位檢測(cè)傳感器(簡(jiǎn)單水觸發(fā)器)· PIR傳感器· 超聲波傳感器· GPS濕度傳感器(DHT22)DHT-22(也稱(chēng)為AM2302)是一個(gè)數(shù)字輸出,相對(duì)濕度和溫度傳感器。它使用電容式濕度傳感器和熱敏電阻來(lái)測(cè)量周?chē)諝?,并在?shù)據(jù)引腳上發(fā)送數(shù)字信號(hào)。在本例中,你將學(xué)習(xí)如何將此傳感器與Arduino UNO一起使用。室溫和濕度將打印到串口監(jiān)視器上。DHT-22

2、傳感器連接很簡(jiǎn)單。左邊的第一個(gè)引腳為3-5V電源,第二個(gè)引腳連接到數(shù)據(jù)輸入引腳,最右邊的引腳接地。技術(shù)細(xì)節(jié)· 電源 - 3-5V· 最大電流 - 2.5mA· 濕度 - 0-100,精確度為2-5· 溫度 - 40至80°C,精確度為±0.5°C必需的組件你將需要以下組件:· 1 × Breadboard 面包板· 1 × Arduino Uno R3· 1 × DHT22· 1 × 10K歐姆電阻程序按照

3、電路圖連接面包板上的組件,如下圖所示。草圖在計(jì)算機(jī)上打開(kāi)Arduino IDE軟件。使用Arduino語(yǔ)言進(jìn)行編碼控制你的電路。通過(guò)單擊“New”打開(kāi)一個(gè)新的草圖文件。Arduino代碼/ Example testing sketch for various DHT humidity/temperature sensors#include "DHT.h"#define DHTPIN 2 / what digital pin we're connected to/ Uncomment whatever type you're using!/#define DH

4、TTYPE DHT11 / DHT 11#define DHTTYPE DHT22 / DHT 22 (AM2302), AM2321/#define DHTTYPE DHT21 / DHT 21 (AM2301)/ Connect pin 1 (on the left) of the sensor to +5V/ NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1/ to 3.3V instead of 5V!/ Connect pin 2 of the sensor to whatever you

5、r DHTPIN is/ Connect pin 4 (on the right) of the sensor to GROUND/ Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor/ Initialize DHT sensor./ Note that older versions of this library took an optional third parameter to/ tweak the timings for faster processors. This parameter is

6、 no longer needed/ as the current DHT reading algorithm adjusts itself to work on faster procs.DHT dht(DHTPIN, DHTTYPE);void setup() Serial.begin(9600); Serial.println("DHTxx test!"); dht.begin();void loop() delay(2000); / Wait a few seconds between measurements float h = dht.readHumidity(

7、); / Reading temperature or humidity takes about 250 milliseconds! float t = dht.readTemperature(); / Read temperature as Celsius (the default) float f = dht.readTemperature(true); / Read temperature as Fahrenheit (isFahrenheit = true) / Check if any reads failed and exit early (to try again). if (i

8、snan(h) | isnan(t) | isnan(f) Serial.println("Failed to read from DHT sensor!"); return; / Compute heat index in Fahrenheit (the default) float hif = puteHeatIndex(f, h); / Compute heat index in Celsius (isFahreheit = false) float hic = puteHeatIndex(t, h, false); Serial.print ("Humid

9、ity: "); Serial.print (h); Serial.print (" %t"); Serial.print ("Temperature: "); Serial.print (t); Serial.print (" *C "); Serial.print (f); Serial.print (" *Ft"); Serial.print ("Heat index: "); Serial.print (hic); Serial.print (" *C "); Serial.print (hif); Serial.println (" *F");代碼說(shuō)明DHT22傳感器具有四個(gè)端子連接到電路板的端子(Vcc,DATA,NC,GND),如下:· DATA引腳連接到Arduino的2號(hào)引腳號(hào)· Vcc引腳

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論