Advertisement
learnelectronics

Self Contained D1 mini w/DHT11 and Lipo Demo

Sep 20th, 2017
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. /*
  2.  * Self Contained D1 mini w/DHT11 and Lipo Demo
  3.  *
  4.  * learnelectronics
  5.  * 19 Sept 2017
  6.  *
  7.  * www.youtube.com/c/learnelectronics
  8.  *
  9.  * NOTES: D1 Mini DHT11 Shield output on D4
  10.  * Blynk inputs:
  11.  * Humidity on V5
  12.  * Temperature on V6
  13.  */
  14.  
  15. /* Comment this out to disable prints and save space */
  16. #define BLYNK_PRINT Serial
  17.  
  18.  
  19. #include <SPI.h>
  20. #include <ESP8266WiFi.h>
  21. #include <BlynkSimpleEsp8266.h>
  22. #include <DHT.h>
  23.  
  24. // You should get Auth Token in the Blynk App.
  25. // Go to the Project Settings (nut icon).
  26. char auth[] = "I know that I must do what's right";
  27. char ssid[] = "As sure as Kilimanjaro rises";
  28. char pass[] = "like Olympus above the Serengeti";
  29.  
  30.  
  31. #define DHTPIN D4          // What digital pin we're connected to
  32.  
  33. // Uncomment whatever type you're using!
  34. #define DHTTYPE DHT11     // DHT 11
  35. //#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
  36. //#define DHTTYPE DHT21   // DHT 21, AM2301
  37.  
  38. DHT dht(DHTPIN, DHTTYPE);
  39. BlynkTimer timer;
  40.  
  41. // This function sends Arduino's up time every second to Virtual Pin (5).
  42. // In the app, Widget's reading frequency should be set to PUSH. This means
  43. // that you define how often to send data to Blynk App.
  44. void sendSensor()
  45. {
  46.   float h = dht.readHumidity();
  47.   float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  48.  
  49.   if (isnan(h) || isnan(t)) {
  50.     Serial.println("Failed to read from DHT sensor!");
  51.     return;
  52.   }
  53.   // You can send any value at any time.
  54.   // Please don't send more that 10 values per second.
  55.   Blynk.virtualWrite(V5, h);
  56.   Blynk.virtualWrite(V6, t);
  57. }
  58.  
  59. void setup()
  60. {
  61.   // Debug console
  62.   Serial.begin(9600);
  63.  
  64.   Blynk.begin(auth, ssid, pass);
  65.  
  66.   dht.begin();
  67.  
  68.   // Setup a function to be called every second
  69.   timer.setInterval(1000L, sendSensor);
  70. }
  71.  
  72. void loop()
  73. {
  74.   Blynk.run();
  75.   timer.run();
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement