2019年1月5日 星期六

使用Blynk wemos d1 接收dht11 溫濕度02

http://arduino.esp8266.com/stable/package_esp8266com_index.json
<---------------以下複製貼上覆蓋原來的DHT11------------------>
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "自己的Blynk 碼";
char ssid[] = "wifi名稱";
char pass[] = "wifi密碼";

#define DHTPIN 2          // What digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  dht.begin();

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}

void loop()
{
  Blynk.run();
  timer.run();
}
<---------------------------------------->


硬體接線

Blynk 設定部分

加入兩個Value Display一個設定濕度與溫度







成果


沒有留言:

張貼留言

新鮮人必知的勞動權益 課後測驗

  青年職涯發展中心的服務不包括哪一項? * 3/3 職涯諮詢 模擬面試 履歷健檢 找另一半   職業適性測驗 職涯講座 團體學習 企業參訪   通訊保障及監察法(通保法)適用對象為 * 10/10 兩者皆是   兩者皆非 公務員 民間從業人員   近期社會上Mee too事件頻...