DHT 11 Interfacing with ESP8266 and Blynk

 



  


/* Fill-in information from Blynk Device Info here */

#define BLYNK_TEMPLATE_ID "TMPL3Kw9eDR4C"

#define BLYNK_TEMPLATE_NAME "DHT11"

#define BLYNK_AUTH_TOKEN "q_4_vmsWXHzDY3w5ll-C_5aXwFjy3qSs"


#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

#include <DHT.h>


// Your WiFi credentials.

// Set password to "" for open networks.

char ssid[] = "wifi name";

char pass[] = "wifi password";


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


#define DHTTYPE DHT11     // DHT 11

//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321

//#define DHTTYPE DHT21   // DHT 21, AM2301


DHT dht(DHTPIN, DHTTYPE); // creates and configures a DHT sensor object

BlynkTimer timer;


// This function sends Arduino's up time every second to Virtual Pin (5).


void sendSensor()

{

  float h = dht.readHumidity();

  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  Serial.println(t);

  Serial.println(h);

  if (isnan(h) || isnan(t)) // If either humidity OR temperature is invalid, This prints an error message in the Serial Monitor.

 {

    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(115200);


  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

  

  dht.begin();


  // Setup a function to be called every second

  timer.setInterval(1000L, sendSensor); // time interval in milliseconds. L means long integer

}


void loop()

{

  Blynk.run();

  timer.run();

}


Comments

Popular posts from this blog

System Bus Types, Functions, and Features

Motherboard form factor

ESP 8266- Ultrasonic Sensor Interfacing