《Arduino 教程--第三十五课 Arduino 湿度传感器.docx》由会员分享,可在线阅读,更多相关《Arduino 教程--第三十五课 Arduino 湿度传感器.docx(7页珍藏版)》请在第壹文秘上搜索。
1、第三十五课Arduino湿度传感器在本节中,我们将学习如何运用不同的传出器连接我们的Arduino板,我们将探讨以下传感涔: 湿度传感器9HT22) 淑度传感曙(1.M35) 水位检测传感涔(简洁水触发器) PlR传感涔 超声波传感器 GPS传感黑DHT22)DHT-22(也称为AM2302)是一个数字输出.相对湿度和温度传感器.它运用电容式海度传感器和热械电阻来测Ift四月空气,并在数据引脚上发送数字估号.在本例中,你将学习如何将此性感潞与ArduinoUNO起运用。室温柔湿度将打印到申口监视器上。DHT-22传感器连接很简洁.左边的第一个引脚为3-5V电满i其次个引脚连接到数据恤人引脚,最
2、右边的引脚接地.技术细微环节电源-3-5V大电流-2.5mA-0-100,精确度为2-5%as-4080.精确度为0.5。C必需的组件你将须要以下组件;1XBreadboard面包板1XArduinoUnoR31XDHT221XIOK欧姬电阻根据电跖图连接面包板上的组件,如下图所示。RwTwnIMAWAOA2A3ASAzduinoBTRXTDOTXzm02PWM0304PWVOSPWM06PWMlWSSfPWM01M05VWMDlMrSOe7SCK)BRHT1HumidityandTemperatureSensorRHT03”:Xc:草图在计。机上打开ArduinoIDE状件.运用Arduin
3、o语古进行编码Ri制你的电路.通过单击“New”打开一个新的席图文件.ArdUin。代码/ExampletestingsketchforvariousDHThumidity/temperaturesensors钟includeDHT.hdefineDHTPIN2/whatdigitalpinwereconnectedto/Uncommentwhatevertypeyoureusing!/ItdefineDHTTYPEDHTll/DHT11ffdefineDHTTYPEDHT22/DHT22(AM2302),AM2321/Sdefinedhttypedht21/dht21(AM23i)/Conn
4、ectpin1(ontheleft)ofthesensorto+5V/NOTE:Ifusingaboardwith3.3VlogiclikeanArduinoDueconnectpin1/to3.3VinsteadofSV!/Connectpin2ofthesensortowhateveryourDHTPINis/Connectpin4(ontheright)ofthesensortoGROUND/Connecta10Kresistorfrompin2(data)topin1(power)ofthesensor/InitializeOHTsensor./Notethatolderversion
5、softhislibrarytookanoptionalthirdparameterto/tweakthetimingsforfasterprocessors.Thisparameterisnolongerneeded/asthecurrentDHTreadingalgorithmadjustsitselftoworkonfasterprocs.DHTdht(DHTPIN,DHTTYPE);voidsetup()Serial.begin(9600);Serial.println(,DHTxtest!);dht.begin();)voidloop()delay(2000);/Waitafewse
6、condsbetweenmeasurementsfloath=dht.readHumidity();Readingtemperatureorhumiditytakesabout250milliseconds!floatt=dht.readTemperature();/ReadtemperatureasCelsius(thedefault)floatf=dht.readTemperature(true);/ReadtemperatureasFahrenheit(IsFahrenheit三true)HCheckifanyreadsfailedandexitearly(totryagain).if(
7、isnan(三)isnan(t)isnan(f)Serial.print1C,FailedtoreadfromDHTsensor!);return;)/ComputeheatindexinFahrenheit(thedefault)floathif=dhtputeHeatInde(f,h);/ComputeheatindexinCelsius(isFahreheit=false)floathie=dhtPUteHeatlndex(t,h,false);Serial.print(Humidity:);Serial.print(三);Serial.print(%t);Serial.print(Te
8、mperature:);Serial.print(t);Serial.print(*C)jSerial.print(f);Serial.print(4Ff);Serial.print(Heatindex:);Serial.print(hie);Serial.print(*C);Serial.print(hi,f);Serial.printin(*F);)代码说明DHT22传感器具有四个端子连接到电路板的端f(Vcc.DATA.NC.GND),如下:DATA引脚连接到Arduino的2号用脚号VCC用脚连接到Arduino板的5伏电压GND引脚连接到Arduino板的接地我们须要在DATA和VCC引脚之间连接IOk欧姆电阴(上拉电阻一旦硬件连接完成,你须要添加DHT22冷到你的ArdUin。麻文件,如前所述.结果你将行到小口监视器上的温度和湿度显示,国2杪更新一次。