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

  • 51
  • 0
  • 约3.28千字
  • 约 4页
  • 2019-10-18 发布于广东
  • 举报
Arduino DHT11 DHT11 N DHT11.h 1. #ifndef __DHT11_H__ 2. #define __DHT11_H__ 3. #include Arduino.h 4. //DHT11 IO 5. #define DHT11_DQ 2 6. #define DHT11_DQ_0 digitalWrite(DHT11_DQ,LOW) 7. #define DHT11_DQ_1 digitalWrite(DHT11_DQ,HIGH) 8. 9. // 10. extern void DHT11_Init(); 11. extern unsigned char DHT11_Read_Byte(); 12. extern void DHT11_Read(); 13. 14. extern unsigned char HUMI_Buffer_Int; 15. extern unsigned char TEM_Buffer_Int; 16. 17. #endif DHT11.cpp 1. #include DHT11.h 2. // 3. unsigned char HUMI_Buffer_Int = 0; 4. unsigned char TEM_Buffer_Int = 0; 5. //**************************************************** 6. //DHT11 7. //**************************************************** 8. void DHT11_Init() 9. { 10. pinMode(DHT11_DQ,OUTPUT); 11. DHT11_DQ_0; // 12. delay(30); // 18ms DHT11 13. DHT11_DQ_1; 14. delayMicroseconds(40); // DHT11 15. pinMode(DHT11_DQ,INPUT); 16. while(digitalRead(DHT11_DQ) == HIGH); 17. delayMicroseconds(80); //DHT11 80us 18. if(digitalRead(DHT11_DQ) == LOW); 19. delayMicroseconds(80); //DHT11 80us 20. } 21. 22. //**************************************************** 23. //DHT11 24. //**************************************************** 25. unsigned char DHT11_Read_Byte() 26. { 27. unsigned char i,dat = 0; 28. unsigned int j; 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); // 50us 35. delayMicroseconds(30); //01 36. if(digitalRead(DHT11_DQ) == HIGH) 37. dat |= (1(7-i)); // 38. while(digitalRead(DHT11_DQ) == HIGH); //1 39.

文档评论(0)

1亿VIP精品文档

相关文档