andretafta

Blynk + DHT11

Aug 23rd, 2020
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //DHT11 And NodeMCU With Blynk
  2. //My GitHub https://github.com/manoranjan2050
  3. //My Hackster.io https://www.hackster.io/Manoranjan2050
  4. //This Video Link https://youtu.be/0dbws1i2GoE
  5. #define BLYNK_PRINT Serial
  6.  
  7.  
  8. #include <ESP8266WiFi.h>
  9. #include <BlynkSimpleEsp8266.h>
  10. #include <DHT.h>
  11.  
  12. // You should get Auth Token in the Blynk App.
  13. // Go to the Project Settings (nut icon).
  14. char auth[] = "Your Blynk Auth Code";
  15.  
  16. // Your WiFi credentials.
  17. // Set password to "" for open networks.
  18. char ssid[] = "SSID";
  19. char pass[] = "Password";
  20.  
  21. #define DHTPIN 0          // D3
  22.  
  23. // Uncomment whatever type you're using!
  24. #define DHTTYPE DHT11     // DHT 11
  25. //#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
  26. //#define DHTTYPE DHT21   // DHT 21, AM2301
  27.  
  28. DHT dht(DHTPIN, DHTTYPE);
  29. BlynkTimer timer;
  30.  
  31. // This function sends Arduino's up time every second to Virtual Pin (5).
  32. // In the app, Widget's reading frequency should be set to PUSH. This means
  33. // that you define how often to send data to Blynk App.
  34. void sendSensor()
  35. {
  36.   float h = dht.readHumidity();
  37.   float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  38.  
  39.   if (isnan(h) || isnan(t)) {
  40.     Serial.println("Failed to read from DHT sensor!");
  41.     return;
  42.   }
  43.   // You can send any value at any time.
  44.   // Please don't send more that 10 values per second.
  45.   Blynk.virtualWrite(V5, t);
  46.   Blynk.virtualWrite(V6, h);
  47. }
  48.  
  49. void setup()
  50. {
  51.   // Debug console
  52.   Serial.begin(9600);
  53.  
  54.   Blynk.begin(auth, ssid, pass);
  55.   // You can also specify server:
  56.   //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  57.   //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
  58.  
  59.   dht.begin();
  60.  
  61.   // Setup a function to be called every second
  62.   timer.setInterval(1000L, sendSensor);
  63. }
  64.  
  65. void loop()
  66. {
  67.   Blynk.run();
  68.   timer.run();
  69. }
Add Comment
Please, Sign In to add comment