Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1.  
  2.  
  3. #define BLYNK_PRINT Serial // Comment this out to disable prints and save space
  4. #include <SPI.h>
  5. #include <ESP8266WiFi.h>
  6. #include <BlynkSimpleEsp8266.h>
  7. #include <SimpleTimer.h>
  8. #include <DHT.h>
  9.  
  10. // You should get Auth Token in the Blynk App.
  11. // Go to the Project Settings (nut icon).
  12. char auth[] = "xxxxxxxxxxxxxxxxxxxxxx";
  13.  
  14. // Your WiFi credentials.
  15. // Set password to "" for open networks.
  16. char ssid[] = "xxxx";
  17. char pass[] = "xxxxxxxx";
  18.  
  19. #define DHTPIN 4 // What digital pin we're connected to
  20.  
  21. // Uncomment whatever type you're using!
  22. #define DHTTYPE DHT11 // DHT 11
  23. //#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
  24. //#define DHTTYPE DHT21 // DHT 21, AM2301
  25.  
  26. DHT dht(DHTPIN, DHTTYPE);
  27. SimpleTimer timer;
  28.  
  29. // This function sends Arduino's up time every second to Virtual Pin (5).
  30. // In the app, Widget's reading frequency should be set to PUSH. This means
  31. // that you define how often to send data to Blynk App.
  32. void sendSensor()
  33. {
  34. float h = dht.readHumidity();
  35. float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  36.  
  37. if (isnan(h) || isnan(t)) {
  38. Serial.println("Failed to read from DHT sensor!");
  39. return;
  40. }
  41. // You can send any value at any time.
  42. // Please don't send more that 10 values per second.
  43. Blynk.virtualWrite(V5, h);
  44. Blynk.virtualWrite(V6, t);
  45. }
  46.  
  47. void setup()
  48. {
  49. Serial.begin(9600); // See the connection status in Serial Monitor
  50. Blynk.begin(auth, ssid, pass);
  51.  
  52. dht.begin();
  53.  
  54. // Setup a function to be called every second
  55. timer.setInterval(1000L, sendSensor);
  56. }
  57.  
  58. void loop()
  59. {
  60. Blynk.run(); // Initiates Blynk
  61. timer.run(); // Initiates SimpleTimer
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement