Advertisement
hessevalentino

Blink-WEMOS mini- DHT11

Jan 29th, 2022
2,400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*************************************************************
  2.  
  3.   This example shows how value can be pushed from Arduino to
  4.   the Blynk App.
  5.  
  6.   WARNING :
  7.   For this example you'll need Adafruit DHT sensor libraries:
  8.     https://github.com/adafruit/Adafruit_Sensor
  9.     https://github.com/adafruit/DHT-sensor-library
  10.  
  11.   App project setup:
  12.     Value Display widget attached to V5
  13.     Value Display widget attached to V6
  14.  *************************************************************/
  15.  
  16. // Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
  17. // See the Device Info tab, or Template settings
  18.  
  19. #define BLYNK_TEMPLATE_ID           "TMPL5H3TsZll"
  20. #define BLYNK_DEVICE_NAME           "Quickstart Device"
  21. #define BLYNK_AUTH_TOKEN            "j57608UnMlDwS6ov3VZHt5yJuFlDNw1C"
  22.  
  23.  
  24. // Comment this out to disable prints and save space
  25. #define BLYNK_PRINT Serial
  26.  
  27. #include <Arduino.h>
  28. #include <ESP8266WiFi.h>
  29. #include <WiFiClient.h>
  30. #include <BlynkSimpleEsp8266.h>
  31. #include <Adafruit_Sensor.h>
  32. #include <DHT.h>
  33.  
  34.  
  35.  
  36. char auth[] = BLYNK_AUTH_TOKEN;
  37.  
  38. // Your WiFi credentials.
  39. // Set password to "" for open networks.
  40. char ssid[] = "NAMEwifi";
  41. char pass[] = "PASSWD";
  42.  
  43. #define DHTPIN 2          // What digital pin we're connected to
  44.  
  45. // Uncomment whatever type you're using!
  46. #define DHTTYPE DHT11     // DHT 11
  47. //#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
  48. //#define DHTTYPE DHT21   // DHT 21, AM2301
  49.  
  50. DHT dht(DHTPIN, DHTTYPE);
  51. BlynkTimer timer;
  52.  
  53. // This function sends Arduino's up time every second to Virtual Pin (5).
  54. // In the app, Widget's reading frequency should be set to PUSH. This means
  55. // that you define how often to send data to Blynk App.
  56. void sendSensor()
  57. {
  58.   float h = dht.readHumidity();
  59.   float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  60.  
  61.   if (isnan(h) || isnan(t)) {
  62.     Serial.println("Failed to read from DHT sensor!");
  63.     return;
  64.   }
  65.   // You can send any value at any time.
  66.   // Please don't send more that 10 values per second.
  67.   Blynk.virtualWrite(V5, h);
  68.   Blynk.virtualWrite(V6, t);
  69. }
  70.  
  71. void setup()
  72. {
  73.   // Debug console
  74.   Serial.begin(115200);
  75.  
  76.   Blynk.begin(auth, ssid, pass);
  77.   // You can also specify server:
  78.   //Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
  79.   //Blynk.begin(auth, ssid, pass, IPAddress(192,168,0,154), 8080);
  80.  
  81.   dht.begin();
  82.  
  83.   // Setup a function to be called every second
  84.   timer.setInterval(1000L, sendSensor);
  85. }
  86.  
  87. void loop()
  88. {
  89.   Blynk.run();
  90.   timer.run();
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement