借助arduino uno板,通过esp8266与LCD1602和Blynk服务器同步显示温湿度

#define BLYNK_PRINT Serial
#include 
#include 
#include 
#include 
#include 
#define DHTPIN 8
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#define ESP8266_BAUD 115200
BlynkTimer timer;
ESP8266 wifi(&Serial);

float t;
float h;
char auth[] = "0c9e07451226439cb4047f7d9bbdb30b"; 
char ssid[] = "kang";
char pass[] = "12345678";
LiquidCrystal mylcd(12,11,5,4,3,2);
void myTimerEvent() {
  t = dht.readTemperature();
  h = dht.readHumidity();


  mylcd.setCursor(0, 0);
  mylcd.print("TEMP(C):");
  mylcd.setCursor(0, 1);
  mylcd.print("HUMI(%):");
  mylcd.setCursor(12, 0);
  mylcd.setCursor(10,0);
  mylcd.print(t);
  mylcd.setCursor(10,1);
  mylcd.print(h);
  
  Blynk.virtualWrite(V0,h );
  Blynk.virtualWrite(V1,t );
   }
void led()
{
  if (t >= 25 || t <= 15) {
    digitalWrite(13,HIGH);
    delay(2000);
    digitalWrite(13,LOW);
  } //红灯亮起
  else if (h <= 35 || h >= 65) {
    digitalWrite(10,HIGH);
    delay(2000);
    digitalWrite(10,LOW);
  } //蓝灯亮起
  else if ((t < 25 && t > 15) && (h > 35 && h < 65)) {
    digitalWrite(9,HIGH);
    delay(2000);
    digitalWrite(9,LOW);
  }//绿灯亮起
  }
void setup()
{
 Serial.begin(9600);
 delay(10);
 mylcd.begin(16,2);
 dht.begin();
 Serial.begin(ESP8266_BAUD);
 delay(10);
 
 pinMode(8,OUTPUT);//DH11传感器
 pinMode(9,OUTPUT);//三个led灯
 pinMode(10,OUTPUT);
 pinMode(13,OUTPUT);

 Blynk.begin(auth, wifi, ssid, pass, "116.62.49.166",8080);
 timer.setInterval(1000L,myTimerEvent);
}
void loop()
{
 led();
 Blynk.run();
 timer.run();
} 

深坑:出了一个问题,要不就是1602显示,要不就是只能连接服务器。
解决办法:当esp8266连接服务器后,lcd1602才会显示温湿度值。
arduino 1.85配置好各类库的版本,链接:https://pan.baidu.com/s/15j8fhZ_MT4JJDsmxgecvbA
提取码:mj54

你可能感兴趣的:(创客)