Guest User

Untitled

a guest
Jul 7th, 2021
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1.  
  2. /* Comment this out to disable prints and save space */
  3. #define BLYNK_PRINT Serial
  4.  
  5.  
  6. #include <ESP8266WiFi.h>
  7. #include <BlynkSimpleEsp8266.h>
  8. #include <DHT.h>
  9.  
  10. #define BLYNK_PRINT Serial // Comment this out to disable prints and save space
  11.  
  12. // You should get Auth Token in the Blynk App.
  13. // Go to the Project Settings (nut icon).
  14. char auth[] = "xxxxxxxxxx";
  15.  
  16.  
  17. // Your WiFi credentials.
  18. // Set password to "" for open networks.
  19. char ssid[] = "xxxx";
  20. char pass[] = "xxxx";
  21.  
  22.  
  23. #define DHTPIN 4 // What digital pin we're connected to
  24. #define DHTTYPE DHT11 // DHT 22, AM2302, AM2321
  25.  
  26.  
  27. DHT dht(DHTPIN, DHTTYPE);
  28. BlynkTimer timer;
  29.  
  30. // MW: Declare variable out here so they can be accessed in other sub-function, such as checkDelayTimer. I think if you declare them inside the sub-function it is only accessible there. So these would be called global variables.
  31. float h = 0;
  32. float t = 0;
  33. int delayCountdown = 0; // Use this for countdown timing
  34.  
  35.  
  36. void sendSensor()
  37. {
  38. h = dht.readHumidity();
  39. t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  40.  
  41.  
  42. Serial.print(t);
  43. Serial.print(h);
  44.  
  45. // You can send any value at any time.
  46. // Please don't send more that 10 values per second.
  47. Blynk.virtualWrite(V5, t);
  48. Blynk.virtualWrite(V6, h);
  49.  
  50. void checkTemp()
  51. {
  52. if ( (t > 30) && (delayCountdown == 0) );
  53. {
  54. delayCountdown = 60;
  55. digitalWrite(5, LOW);
  56. Blynk.virtualWrite(V2, LOW);
  57. }
  58.  
  59.  
  60. if (delayCountdown == 1);
  61. {
  62. digitalWrite(5, HIGH);
  63. Blynk.virtualWrite(V2, HIGH);
  64. }
  65.  
  66. if (delayCountdown > 0);
  67. {
  68. delayCountdown--;
  69. }
  70.  
  71.  
  72. }
  73.  
  74. void setup()
  75. {
  76. // Debug console
  77. Serial.begin(9600);
  78. Blynk.begin(auth, ssid, pass);
  79. dht.begin(); // Start DHT22 communication
  80.  
  81. // Setup a function to be called every second
  82. timer.setInterval(1000L, sendSensor);
  83. timer.setInterval(1000L, checkTemp); // MW: Check temp and how much time has passed every second so we don't block the main loop from running
  84.  
  85. pinMode (5, OUTPUT);
  86. }
  87.  
  88. BLYNK_WRITE(V2) {
  89. int buttonState = param.asInt();
  90. digitalWrite(13, buttonState); // Just do manual on and off here
  91. }
  92.  
  93. void loop()
  94. {
  95. Blynk.run();
  96. timer.run();
  97. }
Advertisement
Add Comment
Please, Sign In to add comment