Termostat na 5szt DS

SOYER
Posts: 1060
Joined: Wed Aug 10, 2022 12:29 pm
Location: Kryry

Post

Cześć, na prośbę wklejam szkic do jednego z moich termostatów:

https://www.youtube.com/watch?v=qj_k_xXImMw

Code: Select all

#include <Wire.h> 
#include <SuplaDevice.h>
#include <supla/sensor/DS18B20.h>
#include <supla/control/relay.h>
#include <supla/network/esp_wifi.h>
 Supla::ESPWifi wifi("xx, "xx");

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Timers.h>
#include "ESPRotary.h"
#include <LiquidCrystal_I2C.h>
#include "Button2.h"

byte stopien[8] ={ // stopień
                      B01100,
                      B10010,
                      B10010,
                      B01100,
                      B00000,
                      B00000,
                      B00000,
                      B00000
                     };
                     
#define ROTARY_PIN1  D6
#define ROTARY_PIN2 D0
#define BUTTON_PIN  D7
// this number depends on your rotary encoder
#define CLICKS_PER_STEP 4 
ESPRotary r;
Button2 b;


LiquidCrystal_I2C lcd(0x27, 16, 2); 

int t1;
int t2;
int t3;
int t4;
int t5;
int tempMin = 25;
int tempMax = 27;
int przek1 = 0;
int tempUst = 0;
int wyslanoON = 0;
int wyslanoOFF = 0;
boolean lewy = false;
boolean prawy = false;

OneWire oneWire0(D3);//D1
DallasTemperature t123(&oneWire0);
DeviceAddress ds1 = {0x28, 0xC4, 0xC6, 0x57, 0x04, 0xE1, 0x3C, 0x8F};
DeviceAddress ds2 = {0x28, 0x3E, 0xBD, 0x57, 0x04, 0xE1, 0x3C, 0x2F};
DeviceAddress ds3 = {0x28, 0x85, 0x51, 0x57, 0x04, 0xE1, 0x3C, 0x2B};

OneWire oneWire1(D4);//D2
DallasTemperature t45(&oneWire1);

DeviceAddress ds4 = {0x28, 0xE2, 0x88, 0x57, 0x04, 0xE1, 0x3C, 0xC0};
DeviceAddress ds5 = {0x28, 0x73, 0xF6, 0x57, 0x04, 0xE1, 0x3C, 0x89};

Timer sekund30;
Timer sekund3;
Timer sekund10;

enum PIERWSZE {JEDEN=1,DWA,TRZY,CZTERY,PIEC,SZESC,SIEDEM,OSIEM,DZIEWIEC,DZIESIEC,JEDENASCIE,DWANASCIE,TRZYNASCIE,CZTERNASCIE,PIETNASCIE,SZESNASCIE};
int menu_1=JEDEN;

Supla::Control::Relay *relay1 = nullptr;

void setup() {
  Serial.begin(9600);
  sekund30.begin(29898);
  sekund3.begin(2997);
  sekund10.begin(60111);
  r.begin(ROTARY_PIN1, ROTARY_PIN2, CLICKS_PER_STEP);
  r.setLeftRotationHandler(showDirection);
  r.setRightRotationHandler(showDirection);

  b.begin(BUTTON_PIN);
  b.setTapHandler(click);
  b.setLongClickHandler(resetPosition);
  b.setLongClickTime(3000);
  b.setDoubleClickTime(700);
  b.setTripleClickHandler(tripleClick);

  Wire.begin(4, 5); //4, 5
 // Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
  char GUID[SUPLA_GUID_SIZE] = {xxx};

  // Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
  char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {xxx};

  new Supla::Sensor::DS18B20(D3, ds1);
  new Supla::Sensor::DS18B20(D3, ds2);
  new Supla::Sensor::DS18B20(D3, ds3);
  new Supla::Sensor::DS18B20(D4, ds4);
  new Supla::Sensor::DS18B20(D4, ds5);

  relay1 = new Supla::Control::Relay(D5, false);
  //auto relay2 = new Supla::Control::Relay(D8, false);
  SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    "svrxx.supla.org",  // SUPLA server address
                    "xxx@wp.pl",   // Email address used to login to Supla Cloud
                    AUTHKEY); 
t123.begin();     
t45.begin();   

dsSTART();
lcd.init();
lcd.backlight();
lcd.createChar(0, stopien);

}
void loop() {

SuplaDevice.iterate();
ds();
relayOnOff();
menu_glowne();
r.loop();
b.loop();
}


// on left or right rotation
void showDirection(ESPRotary& r) {
     if(r.getDirection() == left){
     // lewy = true;
     if(menu_1==SZESC){
        menu_1=DZIEWIEC;
        lcd.clear();
       }
       else if(menu_1==SIEDEM)  {
        if(tempUst > (tempMin+2)){
          tempUst = tempUst-1;
        }
       }
       else if(menu_1==DZIESIEC){
        if(tempUst>10){
          tempUst = tempUst-1;
        }
       }
       
   // Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!LEWO");
  }
  if(r.getDirection() == right){
   //prawy = true;
    if(menu_1==DZIEWIEC){
        menu_1=SZESC;
        lcd.clear();
       }
       else if(menu_1==SIEDEM){
        if(tempUst<80){
          tempUst = tempUst+1;
        }
       }
        else if(menu_1==DZIESIEC){
          if(tempUst < (tempMax -2)){
          tempUst = tempUst+1;
        }
       }
    //Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!PRAWO");
  }
} 
// single click
void click(Button2& btn) {
}
// long click
void resetPosition(Button2& btn) {
  r.resetPosition();
  if(menu_1==SZESC){ // max->ustaw
    menu_1=SIEDEM;
    tempUst=tempMax;
    sekund10.restart();
    lcd.clear();
  }
  else if(menu_1==DZIEWIEC){ // min->ustaw
    menu_1=DZIESIEC;
    tempUst=tempMin;
    sekund10.restart();
    lcd.clear();
  }
  else if(menu_1==SIEDEM){ //max->ustawiono
    tempMax=tempUst;
    menu_1=OSIEM;
    lcd.clear();
    sekund3.restart();
  }
  else if(menu_1==DZIESIEC){ // min->ustawiono
    tempMin=tempUst;
    menu_1=JEDENASCIE;
    lcd.clear();
    sekund3.restart();
  }
   //Serial.println("LLLLLLLLLLLLOOOOOOOOOOOOOOONNNNNNNNNNNNNNNNNNNNNNNNNGGGGGGGGGGGGGGGGG");
}
 void tripleClick(Button2& btn) {
    //Serial.println("..................................................tripleeeeeeeeeeeeee");
    menu_1=SZESC;
    sekund10.restart();
    lcd.clear();
}

void ds(){
  if(sekund30.available()){
  t123.requestTemperatures(); 
  t1 = (t123.getTempC(ds1));
  t2 = (t123.getTempC(ds2));
  t3 = (t123.getTempC(ds3));
  t45.requestTemperatures(); 
  t4 = (t45.getTempC(ds4));
  t5 = (t45.getTempC(ds5));
 if((t1>tempMax) || (t2>tempMax) || (t3>tempMax) || (t4>tempMax) || (t5>tempMax)){
    przek1=1;
  }
 else if((t1<tempMin) && (t2<tempMin) && (t3<tempMin) && (t4<tempMin) && (t5<tempMin)){
    przek1=0;
  }
  sekund30.restart();
  }
}
void dsSTART(){
  t123.requestTemperatures(); 
  t1 = (t123.getTempC(ds1));
  t2 = (t123.getTempC(ds2));
  t3 = (t123.getTempC(ds3));
  t45.requestTemperatures(); 
  t4 = (t45.getTempC(ds4));
  t5 = (t45.getTempC(ds5));
  /*if(((t1) || (t2) || (t3) || (t4) || (t5))>tempMax){
    przek1=1;
  }
  else if(((t1) && (t2) && (t3) && (t4) && (t5))<tempMin){
    przek1=0;
  }*/
}
void relayOnOff(){
  if((przek1 == 1) && (wyslanoON == 0)){
   relay1->turnOn();
   wyslanoON = 1;
   wyslanoOFF = 0;
  }
  else if((przek1==0) && (wyslanoOFF==0)){
   relay1->turnOff();
   wyslanoOFF = 1;
   wyslanoON = 0;
  }
}
void menu_glowne(){

 switch(menu_1){
 case JEDEN:
  one();
    if(sekund3.available()){
      menu_1=DWA;
      lcd.clear();
      sekund3.restart();
    }

 break;
 
 case DWA:
   two();
    if(sekund3.available()){
      menu_1=TRZY;
      lcd.clear();
      sekund3.restart();
    }

 break;

 case TRZY:
   three();
    if(sekund3.available()){
      menu_1=CZTERY;
      lcd.clear();
      sekund3.restart();
    }

 break;

 case CZTERY:
   four();
    if(sekund3.available()){
      menu_1=PIEC;
      lcd.clear();
      sekund3.restart();
    }

 break;

 case PIEC:
   five();
    if(sekund3.available()){
      menu_1=JEDEN;
      lcd.clear();
      sekund3.restart();
    }

 break;

 case SZESC:
   six();
    if(sekund10.available()){
      menu_1=JEDEN;
      lcd.clear();
      sekund3.restart();
    }

 break;

 case SIEDEM:
   seven();
     if(sekund10.available()){
      menu_1=JEDEN;
      lcd.clear();
      sekund3.restart();
    }

 break;

 case OSIEM:
   eight();
   if(sekund3.available()){
      menu_1=JEDEN;
      lcd.clear();
      sekund3.restart();
    }
    

 break;

 case DZIEWIEC:
  nine();
    if(sekund10.available()){
      menu_1=JEDEN;
      lcd.clear();
      sekund3.restart();
    }
 break;

 case DZIESIEC:
  ten();
     if(sekund10.available()){
      menu_1=JEDEN;
      lcd.clear();
      sekund3.restart();
    }

 break;

 case JEDENASCIE:
  eleven();
    if(sekund3.available()){
      menu_1=JEDEN;
      sekund3.restart();
    }

 break;
 
 }
 }
void one(){
  lcd.setCursor(0,0);
  lcd.print("Temp. 1:  ");
  lcd.print(t1);
  lcd.write(byte(0));
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Temp. 2:  ");
  lcd.print(t2);
  lcd.write(byte(0));
  lcd.print("C");
 }
 void two(){
  lcd.setCursor(0,0);
  lcd.print("Temp. 2:  ");
  lcd.print(t2);
  lcd.write(byte(0));
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Temp. 3:  ");
  lcd.print(t3);
  lcd.write(byte(0));
  lcd.print("C");
  
 }
 void three(){
  lcd.setCursor(0,0);
  lcd.print("Temp. 3:  ");
  lcd.print(t3);
  lcd.write(byte(0));
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Temp. 4:  ");
  lcd.print(t4);
  lcd.write(byte(0));
  lcd.print("C");
 }
void four(){
  lcd.setCursor(0,0);
  lcd.print("Temp. 4:  ");
  lcd.print(t4);
  lcd.write(byte(0));
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Temp. 5:  ");
  lcd.print(t5);
  lcd.write(byte(0));
  lcd.print("C");
 }
 void five(){
  lcd.setCursor(0,0);
  lcd.print("Temp. 5:  ");
  lcd.print(t5);
  lcd.write(byte(0));
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Temp. 1:  ");
  lcd.print(t1);
  lcd.write(byte(0));
  lcd.print("C");
 }
 void six(){
  lcd.setCursor(0,0);
  lcd.print("Temperatura MAX:");
  lcd.setCursor(0,1);
  lcd.print("temp MAX: ");
  lcd.print(tempMax);
  lcd.write(byte(0));
  lcd.print("C");
  }
 
 void seven(){
  lcd.setCursor(0,0);
  lcd.print("*   Ustaw MAX  *");
  lcd.setCursor(0,1);
  lcd.print("temp MAX: ");
  lcd.print(tempUst);
  lcd.write(byte(0));
  lcd.print("C");
 }
 void eight(){
  lcd.setCursor(0,0);
  lcd.print("Temperatura MAX:");
  lcd.setCursor(0,1);
  lcd.print("  !!ZMIENIONA!!");
 }
 void nine(){
  lcd.setCursor(0,0);
  lcd.print("Temperatura MIN:");
  lcd.setCursor(0,1);
  lcd.print("temp MIN: ");
  lcd.print(tempMin);
  lcd.write(byte(0));
  lcd.print("C");
 }
 void ten(){
  lcd.setCursor(0,0);
  lcd.print("*   Ustaw MIN  *");
  lcd.setCursor(0,1);
  lcd.print("temp MIN: ");
  lcd.print(tempUst);
  lcd.write(byte(0));
  lcd.print("C");
 }
 void eleven(){
  lcd.setCursor(0,0);
  lcd.print("Temperatura MIN:");
  lcd.setCursor(0,1);
  lcd.print("  !!ZMIENIONA!!");
 }
https://kryry01.aqi.eco/pl
https://app.weathercloud.net/d4311785603

Return to “Projekty użytkowników”