2017年10月15日 星期日

NodeMcu Blynk Wireless Temperature, Humidity DHT 11 Sensor





/* NodeMCU Pin assigment 
  GPIO Pin  I/O Index Number
  GPIO0  3   GPIO1  10 GPIO2  4    GPIO3  9     GPIO4  2   GPIO5   1   GPIO6  N/A  GPIO7  N/A
  GPIO8  N/A GPIO9  11 GPIO10  12  GPIO11   N/A GPIO12  6  GPIO13  7   GPIO14   5  GPIO15   8   GPIO16   0 */

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>           // including the library of DHT11 temperature and humidity sensor
#include <Adafruit_Sensor.h>
#include <DHT_U.h>
#include <SimpleTimer.h>   //including the library of SimpleTimer
#define DHTTYPE DHT11      // DHT 11

#define dht_dpin 14
DHT dht(dht_dpin, DHTTYPE); 
SimpleTimer timer;
//char auth[] = "Your Auth. Key";            // You should get Auth Token in the Blynk App.
                                           // Go to the Project Settings (nut icon).
const char auth[] = "bd2c91fd614b4d478c780881d06b75b6";
const char ssid[] = "74170287";    // Your WiFi credentials.
const char pass[] = "24063173";  // Set password to "" for open networks.

float t;                                   // Declare the variables 
float h;

void setup()
{
    Serial.begin(9600);// Debug console
    Blynk.begin(auth, ssid, pass);
    dht.begin();
    timer.setInterval(2000, sendUptime);
}

void sendUptime()
{
  
  float h = dht.readHumidity();
  float t = dht.readTemperature(); 
  Serial.println("Humidity and temperature\n\n");
  Serial.print("Current humidity = ");
  Serial.print(h);
  Serial.print("%  ");
  Serial.print("temperature = ");
  Serial.print(t); 
  Blynk.virtualWrite(V0, t);
  Blynk.virtualWrite(V1, h);
  
}

void loop()
{
  Blynk.run();
  timer.run();
}

沒有留言:

張貼留言

Node-Red & ModeBus FC=1

Node-Red & ModeBus FC=1 write address=0..7   8bits read address=16..23 8bits  [{"id":"cf7c1253d4d997dd","type&q...