Advertisement
Siklosi_Csapda

Termosztát

Dec 14th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.84 KB | None | 0 0
  1. #define BLYNK_PRINT Serial
  2. #include "EEPROM.h"
  3.  
  4.  
  5. #include <ESP8266WiFi.h>
  6. #include <BlynkSimpleEsp8266.h>
  7. #include <DHT.h>
  8.  
  9. // You should get Auth Token in the Blynk App.
  10. // Go to the Project Settings (nut icon).
  11.  
  12. float tE;
  13. int beallitE;
  14. int beallit; //beállít változó globális
  15. int count=1;
  16. BLYNK_WRITE(V1)
  17. {
  18.     beallit = param.asInt(); // assigning incoming value from pin V1 to a variable
  19.  
  20.  
  21.   }
  22.    
  23.   // You can also use:
  24.   // String i = param.asStr();
  25.   // double d = param.asDouble();
  26.  
  27.  
  28.  
  29. char auth[] = "db1c8b0eb5354042b03bafea955cbe06";
  30.  
  31. // Your WiFi credentials.
  32. // Set password to "" for open networks.
  33. char ssid[] = "DIGI-01061597";
  34. char pass[] = "PMzvSJDW";
  35.  
  36. #define DHTPIN 2          // What digital pin we're connected to
  37.  
  38. // Uncomment whatever type you're using!
  39. #define DHTTYPE DHT11     // DHT 11
  40. //#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
  41. //#define DHTTYPE DHT21   // DHT 21, AM2301
  42.  
  43. DHT dht(DHTPIN, DHTTYPE);
  44. BlynkTimer timer;
  45.  
  46.  
  47.  
  48.  
  49.  
  50. // This function sends Arduino's up time every second to Virtual Pin (5).
  51. // In the app, Widget's reading frequency should be set to PUSH. This means
  52. // that you define how often to send data to Blynk App.
  53. float h=20;
  54. float t=5;
  55.  
  56. void sendSensor()
  57. {
  58.  
  59.  h = dht.readHumidity();
  60.  t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  61.  
  62.  
  63.  
  64.   if (isnan(h) || isnan(t)) {
  65.     Serial.println("Failed to read from DHT sensor!");
  66.     return;
  67.   }
  68.   // You can send any value at any time.
  69.   // Please don't send more that 10 values per second.
  70.   Blynk.virtualWrite(V5, h);
  71.   Blynk.virtualWrite(V6, t);
  72.  
  73.  
  74.  
  75. }
  76. //termosztát
  77. void termosz(){
  78.  // Serial.print("V1 Slider value is: ");
  79.  
  80.  
  81.  
  82.   Serial.print("t     ");
  83.   Serial.println(t);
  84.   delay(500);
  85.   Serial.print("te    ");
  86.   Serial.println(tE);
  87. if (t == tE and beallit == beallitE)
  88.  {
  89.   valt_3();
  90.  }
  91.  else {
  92.    if (t<beallit) {
  93.   valt_1();
  94.    delay(100);
  95.    valt_3();
  96.     }
  97.     if (t>beallit){
  98.       valt_2();
  99.       delay(100);
  100.       valt_3();
  101.       }
  102.   }
  103.  
  104. }
  105.  
  106. void valt_1() {
  107.  
  108.  digitalWrite(D8, HIGH);
  109.  digitalWrite(D6, LOW);
  110.   }
  111.  
  112.   void valt_2() {
  113.     digitalWrite(D6, HIGH);
  114.     digitalWrite(D8, LOW);
  115.     }
  116.    
  117.     void valt_3() {
  118.       digitalWrite(D6, LOW);
  119.       digitalWrite(D8, LOW);
  120.       }
  121.  
  122. void setup()
  123.  
  124. {
  125.   pinMode(D6, OUTPUT);
  126.   pinMode(D8, OUTPUT);
  127.   pinMode(D5, OUTPUT);
  128.   // Debug console
  129.   Serial.begin(9600);
  130.  
  131.   Blynk.begin(auth, ssid, pass);
  132.   // You can also specify server:
  133.   //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  134.   //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
  135.  
  136.   dht.begin();
  137.  
  138.   // Setup a function to be called every second
  139.   timer.setInterval(1000L, sendSensor);
  140. }
  141.  
  142. void loop()
  143. {
  144.  tE=t;
  145.  beallitE=beallit;
  146.   Blynk.run();
  147.   timer.run();
  148.  termosz();
  149.  
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement