Advertisement
Guest User

Untitled

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