Facebook
From Abrupt Elephant, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 359
  1. #include <SimpleTimer.h>
  2. #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
  3. #include <ESP8266WiFi.h>
  4. #include <BlynkSimpleEsp8266.h>
  5. #include <OneWire.h>
  6. #include <DallasTemperature.h>
  7. #include <LiquidCrystal_I2C.h>
  8. LiquidCrystal_I2C  lcd(0x27,2,1,0,4,5,6,7);
  9. #define BACKLIGHT_PIN 3
  10. #define ONE_WIRE_BUS 2        // This is the ESP8266 pin
  11. OneWire oneWire(ONE_WIRE_BUS);
  12. DallasTemperature sensors(&oneWire);
  13.  
  14. DeviceAddress tempSensor1 = { 0x28, 0xFF, 0xD5, 0x1B, 0x80, 0x16, 0x05, 0x73 }; // Adres temperatury #1
  15. DeviceAddress tempSensor2 = { 0x28, 0xFF, 0x72, 0x55, 0x80, 0x16, 0x05, 0xE4  }; // Adres temperatury #2
  16.  
  17.  
  18. char auth[] = "xxxx";  // Kod BLYNK
  19. char ssid[] = "xxxx";  // Login WIFI
  20. char pass[] = "";    // Hasło WIFI
  21.  
  22. SimpleTimer timer;
  23. int pin = D2; // Pin cyfrowy krancówka
  24. WidgetLED led1(V3); // Pin wirtualny krancowy
  25. int pin2 = D3; // Pin cyfrowy krancówka
  26. WidgetLED led2(V4); // Pin wirtualny krancowy
  27. int pin3 = D4; // Pin cyfrowy krancówka
  28. WidgetLED led3(V5); // Pin wirtualny krancowy
  29.  
  30. int tempC1, tempC2;         // Variables for storing temperatures
  31. BLYNK_CONNECTED() {
  32.     Blynk.syncAll();
  33. }
  34. void setup()
  35. {
  36.   Serial.begin(9600);
  37.   Blynk.begin(auth, ssid, pass);
  38.  
  39.   while (Blynk.connect() == false) {
  40.     // Wait until connected
  41.     lcd.begin (16,2);
  42.  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  43.  lcd.setBacklight(HIGH);
  44.  
  45.   lcd.setCursor(0, 0);
  46.   lcd.print("Temp:");
  47.     lcd.setCursor(11, 0);
  48.   lcd.print(" ");
  49.   lcd.write(0xDF);                    // Znak stopnia
  50.   lcd.print("C ");
  51.   }
  52.  
  53.   sensors.begin();
  54.   timer.setInterval(1000L, brama1); //Sprawdzanie stanu
  55.   timer.setInterval(1000L, brama2); //Sprawdzanie stanu
  56.   timer.setInterval(1000L, brama3); //Sprawdzanie stanu
  57.   sensors.setResolution(tempSensor1, 9);   // More on resolutions: http://www.homautomation.org/2015/11/17/ds18b20-how-to-change-resolution-9101112-bits/
  58.   sensors.setResolution(tempSensor2, 9);
  59.   // These timers are used so that data does not flood Blynk
  60.   timer.setInterval(5000L, sendSensor1);  //  Czas pomiaru temperatury #1
  61.   timer.setInterval(5000L, sendSensor2);  //  Czas pomiaru temperatury #2
  62. }
  63.  
  64. void loop()
  65. {
  66.   Blynk.run();
  67.   timer.run();
  68. }
  69.  
  70.  
  71.  
  72. void sendSensor1() {
  73.   sensors.requestTemperatures();                // Polls the sensors
  74.   tempC1 = sensors.getTempC(tempSensor1);  // C - celsjusza / F - fahrenheita
  75.  
  76.   Blynk.virtualWrite(1, tempC1);  // 1 Pin wirtualny
  77. }
  78.  
  79. void sendSensor2()
  80. {
  81.   sensors.requestTemperatures();
  82.   tempC2 = sensors.getTempC(tempSensor2);
  83.  
  84.   Blynk.virtualWrite(2, tempC2);  // 2 Pin wirtualny
  85. }
  86.   void brama1()
  87. {
  88. if(digitalRead(pin) == 1){
  89.   led1.on();
  90. }
  91. else{
  92.   led1.off();
  93. }
  94. }
  95. void brama2()
  96. {
  97. if(digitalRead(pin2) == 1){
  98.   led2.on();
  99. }
  100. else{
  101.   led2.off();
  102. }
  103. }
  104. void brama3()
  105. {
  106. if(digitalRead(pin3) == 1){
  107.   led3.on();
  108. }
  109. else{
  110.   led3.off();
  111. }
  112. }
  113. void temperatura()
  114. {
  115. float temperature = getTemp();
  116.   Serial.println(temperature);
  117.   lcd.setCursor(6, 0);
  118.   lcd.print(temperature);
  119.  
  120.  
  121.   delay(1000); //just here to slow down the output so it is easier to read
  122.  
  123. }
  124. >