arduino
实现环境温湿度检测
涉及模块:DHT11模块,LCD1602A
接线图
LCD参考前面设计
实验代码
#include <dht11.h>#include <LiquidCrystal.h>#define DHT11PIN 8dht11 DHT11;LiquidCrystal lcd(12, 11, 5, 4, 3, 2);void setup() {pinMode(DHT11PIN,OUTPUT);// set up the LCD's number of columns and rows:lcd.begin(16, 2);}void loop() {while(1){int chk = DHT11.read(DHT11PIN);lcd.setCursor(-1, 0);lcd.print(" Tep: ");lcd.print((float)DHT11.temperature, 2);lcd.print(" C");lcd.setCursor(-1, 1);lcd.print(" Hum: ");lcd.print((float)DHT11.humidity, 2);lcd.print(" %");delay(200);}}