Arduino 温湿度传感器DHT11模块实验

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

Arduino)¦hDHT11!WžŒQ ˆDHT11„KÕ Õ†N*  ;/—† Í¥ Ȏ~0Wï(„“–H/DHT11.h‡ö1.#ifndef__DHT11_H__2.#define__DHT11_H__3.#includeArduino.h4.//DHT11IO¾n5.#defineDHT11_DQ26.#defineDHT11_DQ_0digitalWrite(DHT11_DQ,LOW)7.#defineDHT11_DQ_1digitalWrite(DHT11_DQ,HIGH)8.9.//ýpØÏð10.externvoidDHT11_Init();11.externunsignedcharDHT11_Read_Byte();12.externvoidDHT11_Read();13.14.externunsignedcharHUMI_Buffer_Int;15.externunsignedcharTEM_Buffer_Int;16.17.#endifv!/DHT11.cpp‡ö1.#includeDHT11.h2.//šIØÏ3.unsignedcharHUMI_Buffer_Int=0;4.unsignedcharTEM_Buffer_Int=0;5.//****************************************************6.//ËDHT117.//****************************************************8.voidDHT11_Init()9.{10.pinMode(DHT11_DQ,OUTPUT);11.DHT11_DQ_0;//ÉN;¿ ÑËá÷12.delay(30);//öö'Ž18ms å¿DHT11ýÀK0Ëá÷13.DHT11_DQ_1;14.delayMicroseconds(40);//I…DHT11͔15.pinMode(DHT11_DQ,INPUT);16.while(digitalRead(DHT11_DQ)==HIGH);17.delayMicroseconds(80);//DHT11Ñú͔ ÉN;¿80us18.if(digitalRead(DHT11_DQ)==LOW);19.delayMicroseconds(80);//DHT11ÉØ;¿80usËÑpn20.}21.22.//****************************************************23.//û*W‚DHT11pn24.//****************************************************25.unsignedcharDHT11_Read_Byte()26.{27.unsignedchari,dat=0;28.unsignedintj;29.pinMode(DHT11_DQ,INPUT);30.for(i=0;i8;i++)31.{32.if(digitalRead(DHT11_DQ)==LOW)33.{34.while(digitalRead(DHT11_DQ)==LOW);//I…50us35.delayMicroseconds(30);//$­Ø5s„íöô å$špn/0Ø/136.if(digitalRead(DHT11_DQ)==HIGH)37.dat|=(1(7-i));//ØM(M NM(38.while(digitalRead(DHT11_DQ)==HIGH);//pn1 I… M„¥639.}40.}41.returndat;42.}43.44.//****************************************************45.//ûÖ)¦ X(TEM_BufferŒHUMI_Buffer46.//****************************************************47.voidDHT11_Read()48.{49.DHT11_Init();50.HUMI_Buffer_Int=DHT11_Read_Byte();//ûÖ¦„tp51.DHT11_Read_Byte();//ûÖ¦„p52.TEM_Buffer_Int=DHT11_Read_Byte();//ûÖ)¦„tp53.DHT11_Read_Byte();//ûÖ)¦„p54.DHT11_Read_Byte();//ûÖ!ŒŒ55.delayMicroseconds(50);//DHT11ÉN;¿50us56.pinMode(DHT11_DQ,OUTPUT);57.DHT11_DQ_1;//Ê;¿58.}/; ‡ö1.#includeArduino.h2.#includeDHT11.h3.4.voidsetup()//Arduino Ë (ÙÌ ê(:öÐL!5.{6.Serial.begin(9600);//¾n¯„ây‡:96007.DHT11_Read();//ûÖ)¦8.delay(200);//I…h3š9.}10.11.voidloop()//Arduino „; è ª¯ÐL…è 12.{13.DHT11_Read();//ûÖ)¦14.Serial.print(HUMI=);15.Serial.print(HUMI_Buffer_Int);16.Serial.println(%RH);17.Serial.print(TMEP=);18.Serial.print(TEM_Buffer_Int);19.Serial.println(C);20.delay(1000);//öö1s21.} *‡öÝX( *‡ö9sï

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功