Project in progress

Climate Cube for Greenhouse © GPL3+

Opening 26 pieces of windows at the same time in a 2,000-square-meter greenhouse under just 20 seconds? Yes!

  • 6,349 views
  • 2 comments
  • 37 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

About this project

2 years ago I decided to step to a new level in controlling micro-climate in our thermal water heated greenhouses. Before that time for example we did all airing by opening-closing windows manually. It was a waste of time, took hours per day! So the "simple" and clear step was to build automatic micro-climate control "things" begin with automatic windows openers.

The physical environment (from big to small):

  • 200 meters long, 10 meters wide and 4 meters high half-circle production area
  • Any number (26 in my case) of windows along at the top of the structure
  • 400 (2x200) meters long, 4mm thick steel leading wire to attach to the control arms of the windows. One of the 200m line is the opening line the other is the closing line.
  • The leading wire is attached to a 3-phase motor assembled with a worm gear unit. The steel wire lines are twisted around the axis of the gear unit clockwise and counter-clockwise. If the motor rotates clockwise then one line of wire moves one direction and the other one moves opposite.
  • Different rotation is managed by a 3-pole reversing contactor assembled with a thermal relay set to the motor's parameters. The contactor has two 24V AC coils. Coils can be powered with a 230AC to 24V AC transformer through a 3-way selector switch (OPEN or CLOSE) where the third position is for the AUTOMATIC control. For limiting the amount of opening and closing movement (no to destroy the structure by the gear) two limit switches have been put near the steel wire rail.

BIG "How to" questions for automatic micro-climate control

  • ... How to decide what kind of climate is need for the plants during 24 hours whole year...?
  • ... How to manage system stability in an airspace where humidity can be 100%, temperature can be 60 Celsius degree and huge EMI pollution (3-phase motor, contactor, pumps and relays for irrigation, etc.) all around...?
  • ... How to protect structure, and parts if malfunction hits...? Have experienced when a motor-gear-unit crushes the structure. No one should see that...
  • Etc...

A little recollection

During last 2 years I had several phases of this project. For example it was a dead end using plastic cases. High humidity and sunlight can be harmful. All the 1602 and 2004 type LCDs with its HD44780 type controller have a high sensitivity to any kind of electromagnetic impact. After a time it just doodled random things. Not to think for future modifications can be expensive. Bought many Arduino Nanos thinking they are just fine but later I built around the MKR1000 boards. Yes they are much expensive but for IoT projects being online is essential :) isn't it?

Path believed quite good

After this long prelude lets do the workmanship (from big to small again).

I need to isolate things as much as possible from climate. Metal box is the best option i found to achieve that. I have to separate high voltage things (Supply Box) from low voltage (MCU Box) things. Two metal boxes better than one :).

The high voltage box contains the 3-phase input supply (3 phase + Neutral + Earth). Circuit brakers for motor/transformer and for MCU in the other box. Transformer (230V to 24-18-12-6-3V). Reversing contactor and thermal relay. Input and output cables from motor to Supply Box, from MCU box to Supply Box.

The biggest limitation is the physical size of the controller housing. First it was a headache how to install everything in a logical manner.

The MCU Box contains the controller aka the Climate Cube, and an I2C bus expander housing. The controller have all the stuff what counts here. But first, the most important thing is I wanted to built it as a structure of modules to be able to expand, enhance later and replace parts if necessary. See the wiring diagram.

MKR1000 has everything (now) i need. Lots of GPIOs, hardware I2C, WIFI option, and strong processing ability not to mention it has more program space than Nanos.

I use 2-channel opto-isolated relay to switch the 24V AC circuit to drive the contactors' coil. The relay can be fully separated from the MCU by giving a second 5V DC power supply. So the coil of the relay powered from one power supply (PSU) and the optocouplers (relay inputs' VCC) are from another PSU shared with MCU. The two PSUs have been built with input and output EMI filter circuits. (I did not find such filtered PSU where 24V AC input available).

A DS3231 clock is installed also. During plant production there are many scenarios. For example if there is not enough sunlight for plants to do their photosynthesis effectively no need to keep hotter air.

The lack of sunlight in the winter (January) not warmth the air and there is a high chance that temperature inside is lower than what we wanted so windows stay closed. If this happens plant cannot get fresh CO2 rich air. So we need to get some fresh air in despite the temperature inside still lower what needed. Of course we don't want to do that in the night when outer temperature drops minuses. That is why MCU needs to know what time it is. Because, for the daylight I need to set checkpoint/time. Example: when certain conditions appear MCU opens the windows for 5 seconds interval then keep that for 3 minutes than close them. Air freshening done.

A display is also necessary to set things and inform us. The 1,3" OLED was the simplest and best for this project. Uses 3.3V and I2C. Piece of cake.

Keypad was a hard choice. Tried several types but MPR121 Capacitive keypad won. The 4x4 membrane also in duty elsewhere but uses 8 input. (to achive only 2 wires using different resistors connected to its' wires gave hectic readings, so in the end membrane OK but not with 8 outputs). So the cap. keypad... Farming is a dirty thing, much have rough hands and fingers, not to mention gloves. I have to get used to that capacitive keypad requires clean hand.

There are dedicated switches and a button in duty. Main switch is a full ON/OFF switch for AC 230V input. The metal tactile button only switches the Relay coil ON/OFF (good when debugging needed). And there is a momentary button also. Pushing it the display activates for certain seconds and then deactivates (or pushing it again also deactivates it). OLED displays have limited lifetime that's the reason I put it there.

MCU cannot capable of running parallel processes at the exact same time. To show user what is going on inside the Cube I also installed an RGB 5MM (common cathode) LED. You can program which colour what means in the program loop. For example in normal 'stand-by' mode when MCU only reads sensors a blinking green colour indicates everything is fine "you can go to your work". If freezing hits (not happened since OLED displays used) blinking stops or it is just light but not blinks.

The first and most important input is coming from the temperature sensor. I chose the 1-Wire bus type DS18B20 sensor. Simple and long range. Range is needed here, we are talking about 200 meters where can be so much differences between temperatures. I managed to reach 50 meters using CAT5 cable. Sometimes, thanks to the EMI sensor gives 'error' values but you can filter them easily in the software.

In the future under new project names but based on this very first Climate Cube project i am going to install more sensors (RH%, LUX, etc.). Optimum relative humidity for sweet pepper is important and Si7021 sensor can measure it quite well. The amount of radiation is also very important to know. If it is less than the optimum you have to keep cooler temperature inside, not to turn the growing process into vegetative stage etc.

The 'What if...' session

There are many dilemmas and 'what if...' type questions but the main thing is we all exposed to the changes of weather. All we can do is to adapt our micro-climate to it. First of all, for optimum adaptation we need exact data (°C of Air, °C of Soil, RH%, Soil moisture, Watts/m2° etc.) from our surroundings. Second, we should know what plants exact need in certain period of production. Only after these information we can start to think about what type of intervention should we take.

Next levels of Climate Cube

I am about to build a 3G based Wi-Fi network in the area, after that i can monitor, manage etc. the already installed units. I real IoT based plant production come alive soon.

If demo video required I will do that, just say.

Custom parts and enclosures

bom2_on59eMkwtx.xlsx
bom2_on59eMkwtx.xlsx

Schematics

climate_cube-window_controller_QBevI9N3WU.fzz
climate_cube-window_controller_QBevI9N3WU.fzz

Code

Proba_141os23mkrOled.inoArduino
#include <HCMatrixKeypad.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Metro.h>
#include <Wire.h>
#include <Arduino.h>
#include <U8g2lib.h>
#include "RTClib.h"



#define Addrsi 0x40 //Si7021
#define Addrbh 0x23 // BH1750

U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);


#define relayPin0 16 // a 8es kimenetre rakotve az 1 es rele ami a Zaras
#define relayPin1 17 // a 9as kimenetre rakotve a 2 es rele ami a Nyitas

#define HOMERO 0 // A homero bedugva az mcu 2es digitalis bemenetere es elnevezve HOMEROnek

#define LED 19



/*unsigned long myChannelNumber = 258360;
const char * myWriteAPIKey = "I44H7MK2AYDPZBIJ";
const long ThingspeakDelay = 30000;*/

int kivantHomerseklet = 1800;
int homDiff = 50;

/* --------- METRO time constants ----------------- */
const int idoNyit = 700;
const int idoZar = 500;

const long varNyit= 90000;
const long varZar= 60000;
const int varLed = 700;  //3600000=1 ra
const int varHumHomBes = 1923;  //3600000=1 ra
const int varBeSug = 571; 
const int varLcd = 1000;


/*----------------Keypad-----------------*/

#define DEBOUNCE 100 //100

#define C1 1  // DIO for keypad column 1
#define C2 2  // DIO for keypad column 2
#define C3 3  // DIO for keypad column 3
#define C4 4  // DIO for keypad column 4


#define R1 8 // DIO for keypad row 1
#define R2 7 // DIO for keypad row 2
#define R3 6 // DIO for keypad row 3
#define R4 5 // DIO for keypad row 4


HCMatrixKeypad Keypad(DEBOUNCE, C1, C2, C3, C4, ROWMARKER, R1, R2, R3, R4);

/*1=14    .   .   A=11
4=24    .   .   B=21
7=34
*=44
*/
/*---------------------------------------------------------------------*/

int state0 = HIGH;
int state1 = HIGH;
int ledstate = LOW;


int inPin = 19;         // the number of the input pin


int state = LOW;      // the current state of the output pin
int previous = HIGH;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

int reading;           // the current reading from the input pin
const int numReadings = 10;

int readings[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
int tempCaverage = 0;                // the average


OneWire oneWire(HOMERO); // A homero egykabeles onewire bekotest kapott
DallasTemperature sensors(&oneWire); // megadtuk a homero gyartasi tipusat es hivatkozunk ra

RTC_DS3231 rtc;


 
Metro metro0 = Metro(varZar); 
Metro metro1 = Metro(varNyit); 
Metro ledMetro = Metro(varLed);
Metro metro3 = Metro(varHumHomBes);
Metro metro4 = Metro(varBeSug);
Metro metro5 = Metro(varLcd);
Metro rtcMetro = Metro(1000);
//Metro metro6 = Metro(ThingspeakDelay);



void setup()
{
  
  // Initialise I2C communication as MASTER
  //Wire.begin();
  u8g2.begin();
  Wire.setClock(32000L); //The slowest i2c speed for Mkr1000
  
  // Initialise serial communication, set baud rate = 9600
  //Serial.begin(9600);
  //u8g2.setFlipMode(1);
  u8g2.clearBuffer();          // clear the internal memory
  u8g2.setFont(u8g2_font_7x14_tf); // choose a suitable font
  u8g2.drawStr(43,10,"PaMon!");  // write something to the internal memory
  u8g2.sendBuffer();          // transfer internal memory to the display
  delay(2000);
  u8g2.clearDisplay();

  //Start I2C transmission
  Wire.beginTransmission(Addrsi);
 
  // Stop I2C transmission
  Wire.endTransmission();
  delay(300);

  // Start I2C Transmission
  Wire.beginTransmission(Addrbh);
  // Send power on command
  Wire.write(0x01);
  // Stop I2C Transmission
  Wire.endTransmission();
  delay(300);
  
  // Start I2C Transmission
  Wire.beginTransmission(Addrbh);
  // Send continuous -......-low precision measurement command: 0x13
  Wire.write(0x10);   //0x10- high-continuous measurement;0x11 high0.5 lx cont mode 120ms time
  // Stop I2C Transmission
  Wire.endTransmission();
  delay(300);

 

  pinMode(LED,OUTPUT);
  digitalWrite(LED,ledstate);

  rtc.begin();
  sensors.begin(); // Elindul a homero
  sensors.setResolution(10);
  
  pinMode(relayPin0, OUTPUT);
  digitalWrite(relayPin0, HIGH);
  
  pinMode(relayPin1, OUTPUT);  
  digitalWrite(relayPin1, HIGH);

  // initialize the button pin as a input:
  pinMode(inPin, INPUT);


  // initialize the LED as an output:
  
  
  u8g2.clearBuffer();          // clear the internal memory
  // write something to the internal memory
  //u8g2.sendBuffer(); 
  
  
  
  
  
  
  /*u8g2.setCursor(16,2);
  u8g2.print("W/m2");

  u8g2.setCursor(0,1);
  u8g2.print("Par:");
  u8g2.setCursor(8,1);
  u8g2.print("%");

  u8g2.setCursor(10,1);
  u8g2.print("Hom:");
  
  
  
  u8g2.setCursor(0,3);
  u8g2.print("Aj.Hom:");


/*t = rtc.getTime();
  
  if(t.hour<10) {
    u8g2.setCursor(5,3);
    u8g2.print("0");
    u8g2.setCursor(6,3);
    u8g2.print(t.hour);
  }
  else {
    u8g2.setCursor(5,3);
    u8g2.print(t.hour);
  }
  
  if(t.min<10) {
    u8g2.setCursor(8,3);
    u8g2.print("0");
    u8g2.setCursor(9,3);
    u8g2.print(t.min);
  }
  else {
    u8g2.setCursor(8,3);
    u8g2.print(t.min);
  }*/

  for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
  }

  sensors.requestTemperatures();


  delay(500);
  metro0.reset();
  metro1.reset();
  ledMetro.reset();
  metro3.reset();
  metro4.reset();
  metro5.reset();

 //WiFi.begin(ssid, pass);
 //ThingSpeak.begin(client);
 //delay(2000);
}

void loop()
{

//
  
if (state0 == HIGH && state1 == HIGH) {

  if (ledMetro.check() == 1) { // check if the metro has passed its interval .
    if (ledstate==HIGH)  ledstate=LOW;
    else ledstate=HIGH;
    
    digitalWrite(LED,ledstate);
  }

  
  float tempRaw = sensors.getTempCByIndex(0);
  float tempFloat = tempRaw*100;
  int tempInt = tempFloat;
  

  // subtract the last reading:
  total = total - readings[readIndex];
  // read from the sensor:
  if(tempInt>0 && tempInt<8000){
    int tempC = tempInt;
    readings[readIndex] = tempC;
    //Serial.println(tempC);
  }
  // add the reading to the total:
  total = total + readings[readIndex];
  // advance to the next position in the array:
  readIndex = readIndex + 1;

  // if we're at the end of the array...
  if (readIndex >= numReadings) {
    // ...wrap around to the beginning:
    readIndex = 0;
  }

  // calculate the average:
  tempCaverage = total / numReadings;
  // send it to the computer as ASCII digits
  //Serial.println(tempCaverage);
  //delay(100);
  
  //Serial.println(sensors.getTempCByIndex(0));
  //Serial.println(tempInt);
  
  //Serial.println(tempCaverage);

  u8g2.setCursor(0,10);
  u8g2.print("Bh:");
  
  u8g2.setCursor(0,24);
  u8g2.print("D:");
    
  u8g2.setCursor(0,38);
  u8g2.print("Ah:");

  u8g2.setCursor(0,52);
  u8g2.print("Ido:");

  Keypad.Scan();
  
    /* If so the send the key to the serial port 
    //Serial.print("Number of Key Pressed: ");
    //Serial.println(Keypad.Read());
    if (Keypad.Read() > 0){
     u8g2.setCursor(120,52);
     u8g2.print("*");
  }
    else {
     u8g2.setCursor(120,52);
     u8g2.print(" ");
  }*/

  if (Keypad.Read() == 14) {
        kivantHomerseklet+=100;
        if (kivantHomerseklet == 2600){
          kivantHomerseklet = 1600;
        }
        
  }
  if (Keypad.Read() == 24) {
        kivantHomerseklet-=100;
        if (kivantHomerseklet == 1500){
          kivantHomerseklet = 2500;
        }
  }
  

  if (Keypad.Read() == 13) {
    
        homDiff+=10;
        if (homDiff > 205){
          homDiff = 10;
        }
        
  }
  if (Keypad.Read() == 23) {
        homDiff-=10;
        if (homDiff < 5){
          homDiff = 200;
        }
  }    
  


  if (rtcMetro.check()== 1) {
  
  DateTime now = rtc.now();

    Serial.print(now.year());
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
  
    u8g2.setCursor(30,52);
    u8g2.print(now.hour());

    u8g2.setCursor(45,52);
    u8g2.print(":");
    
    u8g2.setCursor(54,52);
    u8g2.print(now.minute());
    
  }
  
  

  
 
  int Bh = kivantHomerseklet/100;
  u8g2.setCursor(23,10);
  u8g2.print(Bh);
  
  if (homDiff > 5 && homDiff < 100) {
    u8g2.setCursor(18,24);
    u8g2.print("0.");
    u8g2.setCursor(34,24);
    u8g2.print(homDiff/10);
    u8g2.setCursor(42,24);
    u8g2.print(" ");
    
  }

  if (homDiff > 95 && homDiff < 200) {
    u8g2.setCursor(18,24);
    u8g2.print(homDiff);
    u8g2.setCursor(26,24);
    u8g2.print(".");
    u8g2.setCursor(34,24);
    u8g2.print(homDiff-100);
    u8g2.setCursor(42,24);
    u8g2.print(" ");
  }
  if (homDiff==200) {
    u8g2.setCursor(18,24);
    u8g2.print(homDiff);
    u8g2.setCursor(26,24);
    u8g2.print(".");
    u8g2.setCursor(34,24);
    u8g2.print(homDiff-200);
    u8g2.setCursor(42,24);
    u8g2.print(" ");
  }
  
  
  

  u8g2.setCursor(23,38);
  u8g2.print(tempRaw,1);
  u8g2.setCursor(62,38);
  u8g2.print("C");

  //Serial.print("Jelenlegi homerseklet: ");
  //Serial.println(sensors.getTempCByIndex(0));  // kiirjuk a monitorra a kapott homersekletet



if (metro3.check()== 1 && state0 == HIGH && state1 == HIGH) {
  
  unsigned int datasi[2];
  
  // Start I2C transmission
  Wire.beginTransmission(Addrsi);
  // Send humidity measurement command, NO HOLD MASTER
  Wire.write(0xF5);
  // Stop I2C transmission
  Wire.endTransmission();
  delay(150);
    
  // Request 2 bytes of data
  Wire.requestFrom(Addrsi, 2);

  // Read 2 bytes of data
  // humidity msb, humidity lsb 
  if(Wire.available() == 2)
  {
    datasi[0] = Wire.read();
    datasi[1] = Wire.read();
  }
    
  // Convert the data
  float humidity  = ((datasi[0] * 256.0) + datasi[1]);
  humidity = ((125 * humidity) / 65536.0) - 6;
  

  // Start I2C transmission
  Wire.beginTransmission(Addrsi);
  // Send temperature measurement command, NO HOLD MASTER
  Wire.write(0xF3);
  // Stop I2C transmission
  Wire.endTransmission();
  delay(150);
    
  // Request 2 bytes of data
  Wire.requestFrom(Addrsi, 2);
  
  // Read 2 bytes of data
  // temp msb, temp lsb
  if(Wire.available() == 2)
  {
    datasi[0] = Wire.read();
    datasi[1] = Wire.read();
  }

  // Convert the data
  float temp  = ((datasi[0] * 256.00) + datasi[1]);
  float cTemp = ((175.72 * temp) / 65536.00) - 46.85;
  

  unsigned int databh[2];
  // Request 2 byte of data
  Wire.requestFrom(Addrbh, 2);

  // Read 2 bytes of data
  // ALS msb, ALS lsb
  if(Wire.available() == 2) 
  {
    databh[0] = Wire.read();
    databh[1] = Wire.read();
  }
    //delay(130);
  
  //convert the data
  float luxraw = (((databh[0] * 256.0000) + databh[1]) / 1.2000);
  float irradiation = (((databh[0] * 256.0000) + databh[1]) / 1.2000)*0.0079;
  int lux = irradiation;


  /*if(humidity<=0) {
    u8g2.setCursor(4,1);
    u8g2.print(" 0  ");
    
  }
  if(humidity>0 && humidity<100) {
    u8g2.setCursor(4,1);
    u8g2.print(humidity,0);
    u8g2.setCursor(6,1);
    u8g2.print("  ");
    }
   if(humidity>=100 && humidity<=115) {
    u8g2.setCursor(4,1);
    u8g2.print(humidity,0);
    u8g2.setCursor(7,1);
    u8g2.print(" ");
    }
   if(humidity>115) {
    u8g2.setCursor(5,1);
    u8g2.print("115");
    u8g2.setCursor(4,1);
    u8g2.print(">");
   }
   
  

  u8g2.setCursor(14,1);
  u8g2.print(cTemp, 1);
  u8g2.setCursor(19,1);
  u8g2.print("C");

  if(lux<10) {
    u8g2.setCursor(12,2);
    u8g2.print(lux);
    u8g2.setCursor(13,2);
    u8g2.print(" ");
    u8g2.setCursor(14,2);
    u8g2.print(" ");
    
  }
  
if(lux>=10 && lux<100) {
    u8g2.setCursor(12,2);
    u8g2.print(lux);
    u8g2.setCursor(14,2);
    u8g2.print(" ");
    
  }

if(lux>=100 && lux<1000) {
    u8g2.setCursor(12,2);
    u8g2.print(lux);

}

if(lux>1000) {
    u8g2.setCursor(11,2);
    u8g2.print(lux);

}
 

if(lux<100) {
    u8g2.setCursor(7,3);
    u8g2.print("18-20 ");
    u8g2.setCursor(13,3);
    u8g2.print("C");
}


if(lux>=100 && lux<200){
    u8g2.setCursor(7,3);
    u8g2.print("21-22 ");
    u8g2.setCursor(13,3);
    u8g2.print("C");
}

if(lux>=200 && lux<300) {
    u8g2.setCursor(7,3);
    u8g2.print("23-24 ");
    u8g2.setCursor(13,3);
    u8g2.print("C");
}

if(lux>=300 && lux<400) {
    u8g2.setCursor(7,3);
    u8g2.print("25-26 ");
    u8g2.setCursor(13,3);
    u8g2.print("C");
}
if(lux>=400) {
    u8g2.setCursor(7,3);
    u8g2.print("Arnyek");
    u8g2.setCursor(13,3);
    u8g2.print(" ");
}*/

  
    // Output data to serial monitor
  Serial.print("Ambient Light Luminance   :");
  Serial.print(irradiation);
  Serial.println(" lux"); 
   
  // Output data to serial monitor
  Serial.print("Relative humidity : ");
  Serial.print(humidity);
  Serial.println(" % RH");
  Serial.print("Temperature in Celsius : ");
  Serial.print(cTemp);
  Serial.println(" C");
  Serial.print("LUX: ");
  Serial.print(luxraw);
  Serial.println(" lx");
  
  
  //u8g2.setCursor(0,2);
  //u8g2.print("Besugarzas:");
  
  
}


  reading = digitalRead(inPin);

  // if the input just went from LOW and HIGH and we've waited long enough
  // to ignore any noise on the circuit, toggle the output pin and remember
  // the time
  if (reading == HIGH && previous == LOW) {
    if (state == HIGH)
      state = LOW;
    else
      state = HIGH;
      metro5.reset();
  }
  
  if (state == HIGH) {
      u8g2.sendBuffer();
      Serial.println("OLED ON");
      metro5.interval(20000);
  }

  if(metro5.check() == 1 && state == HIGH){
      state = LOW;
  }
        
  if (state == LOW) { 
      // if the current state is LOW then the button
      // wend from on to off:
      u8g2.clearDisplay();
  }
  previous = reading;


 

} // closes the display and measuring methods

if ((kivantHomerseklet-homDiff) == tempCaverage ) {
digitalWrite(relayPin0, HIGH);
digitalWrite(relayPin1, HIGH);
}
if ((kivantHomerseklet+homDiff) == tempCaverage) {
digitalWrite(relayPin0, HIGH);
digitalWrite(relayPin1, HIGH);
}
if (((kivantHomerseklet-homDiff) < tempCaverage &&  tempCaverage < (kivantHomerseklet+homDiff)) && relayPin0==LOW) {
digitalWrite(relayPin0, HIGH);

}
if (((kivantHomerseklet-homDiff) < tempCaverage && tempCaverage < (kivantHomerseklet+homDiff)) && relayPin1==LOW) {
digitalWrite(relayPin1, HIGH);
}

if ((tempCaverage < (kivantHomerseklet-homDiff)) && relayPin1==LOW) {
digitalWrite(relayPin1, HIGH);
}

if ((tempCaverage > (kivantHomerseklet+homDiff)) && relayPin0==LOW) {
digitalWrite(relayPin0, HIGH);
}

if ((metro0.check() == 1) && (tempCaverage < (kivantHomerseklet-homDiff))) { // check if the metro has passed its interval .
    if (state0==HIGH)  { 
      state0=LOW;
      metro0.interval(idoZar); //Zarasi ido
    } 
    else {
      state0=HIGH;
      metro0.interval(varZar); // if the pin is LOW, set the interval to 1 second.
    }
    digitalWrite(relayPin0,state0);
}
if ((metro1.check() == 1) && (tempCaverage > (kivantHomerseklet+homDiff))) { // check if the metro has passed its interval .
    if (state1==HIGH)  { 
      state1=LOW;
      metro1.interval(idoNyit); // if the pin is HIGH, set the interval to 0.25 seconds.
    } 
    else {
      state1=HIGH;
      metro1.interval(varNyit); // if the pin is LOW, set the interval to 1 second.
    }
    digitalWrite(relayPin1,state1);
}

    
        sensors.requestTemperatures(); // Homerotol beolvassunk a homersekletet  
    


}

Comments

Similar projects you might like

Hacking My Toaster

Project tutorial by javier muñoz sáez

  • 155 views
  • 5 comments
  • 5 respects

Music Reactive LED Strip

Project showcase by buzzandy

  • 106 views
  • 2 comments
  • 8 respects

Pavlov's Cat

Project tutorial by Arduino

  • 192 views
  • 0 comments
  • 1 respect

Infrared Controlled Logic Puzzle -- Lights On!

Project tutorial by FIELDING

  • 78 views
  • 0 comments
  • 5 respects

Arduino Obstacle Avoidance Robot with Ultrasonic HC-SR04

Project tutorial by Jorge Rancé

  • 777 views
  • 1 comment
  • 11 respects

Using Finite State Machines

by Gustavo Gonnet

  • 6,974 views
  • 2 comments
  • 18 respects
Add projectSign up / Login