📜 ⬆️ ⬇️

Save electricity or time timer for night tariffs in power grids

How often do you have to adjust different timers? The alarm clock on the smartphone, the timer on the bread maker, so that for breakfast there was fresh bread, and you never know when you need to start something. No less important is the task to turn off or complete the action in time.

So I was faced with the task of automating the on and off of the appliance. It would be possible to use a typical socket with a time relay, but you need to turn on an unusual load, so the controller and only the controller.

So, the task is to include an electric heating boiler for heating a house at night, when billing is at least a little benign. What came out of it - see below.
')
image

To buy a ready-made time relay for 6-8 thousand rubles (we are not talking about simple devices plugged into the outlet), which will close the necessary contacts by triggering events or by time, just unsportsmanlike. In addition, a controller with similar functions, and even with a good supply of functionality, will cost 4 times less, not to mention the warm-up for the brain. It all started in the New Year holidays.

The task of working in a strictly allotted time requires knowing the current time and setting the boundaries of the work. Everything is good, but it is desirable to change the time and sometimes adjust the clock. In addition, it is more convenient to implement the task in the form of an end device, which will not require a computer to change the parameters. Also, additional functions will be hung on the controller, but this is in version 2.0, but for now it is a timer.

From here, the list of devices needed to complete the task was determined:

1. Arduino Nano (the cheaper the module, the better, since the tasks are not resource-intensive);
2. RTC time module;
3. Relay module (2 relays);
4. Power adapter for arduino. Was chosen DC-DC converter stabilizer 12V-5V;
5. Display 4x20 characters for beauty (there were 4-line and 2-line);
6. I2C adapter for display.

So it turned out to be connected in the end:

image

It was quite simple to collect all this on a breadboard. Studying Habr, I noticed the work with I2C tire a long time ago and it really hurts me to like the design of the watch of a friend , so I borrowed a part of its code and made the main watch in the same style.

Then there was a long process of learning how to work with the EEPROM and the clock module, so that when the power fails, the time timer and the clock itself do not get lost. At first, the clock was turned off, but a long study of the forums led to the thought that the RTC module contained a Li-ION battery and it just sat down from a long journey from China to Russia. Support for food for a couple of days allowed us to fill the discharge and more time did not get lost.

It remains to connect all the modules stronger, write code and start debugging.

Sketch Timer
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib #include <EEPROM.h> #include <Wire.h> #include <DS1307.h> #include "RTClib.h" #include <LiquidCrystal_I2C.h> #define timePIN 10 #define RELE_1 12 //  1    7 #define RELE_2 11 //  2    8 //  A4  SDA   SDA  //  A5  SCL   SCL  int FullMinutesTimerOn = EEPROM.read(0); int FullMinutesTimerOff = EEPROM.read(2); int rtc[7]; byte rr[7]; int ledPin = 13; LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display int button1 = 10; //   D10 int button2 = 9; //   D9 int button3 = 8; //   D8 int button4 = 7; //   D7 int button5 = 6; //   D6 int led = 5; int rejim=0; //     int PrevSec=0; int CurSec=0; boolean lastButton=LOW; byte LT[8] = { B00111, B01111, B11111, B11111, B11111, B11111, B11111, B11111 }; byte UB[8] = { B11111, B11111, B11111, B00000, B00000, B00000, B00000, B00000 }; byte RT[8] = { B11100, B11110, B11111, B11111, B11111, B11111, B11111, B11111 }; byte LL[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B01111, B00111 }; byte LB[8] = { B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111 }; byte LR[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11110, B11100 }; byte MB[8] = { B11111, B11111, B11111, B00000, B00000, B00000, B11111, B11111 }; byte block[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 }; // loop counter int count = 0; void setup () { DDRC|=_BV(2) |_BV(3); // POWER:Vcc Gnd PORTC |=_BV(3); // VCC PINC3 pinMode(ledPin, OUTPUT); pinMode(timePIN, OUTPUT); pinMode(RELE_1, OUTPUT); //     pinMode(RELE_2, OUTPUT); //     digitalWrite(RELE_1, HIGH); //    digitalWrite(RELE_2, HIGH); //    RTC.get(rtc,true); lcd.init(); // initialize the lcd lcd.backlight(); lcd.home(); lcd.createChar(0,LT); lcd.createChar(1,UB); lcd.createChar(2,RT); lcd.createChar(3,LL); lcd.createChar(4,LB); lcd.createChar(5,LR); lcd.createChar(6,MB); lcd.createChar(7,block); // sets the LCD's rows and colums: lcd.clear(); RTC.SetOutput(DS1307_SQW32KHZ); pinMode(led, OUTPUT); pinMode(button1, INPUT); pinMode(button2, INPUT); pinMode(button3, INPUT); } void custom0(int x) { // uses segments to build the number 0 lcd.setCursor(x,0); // set cursor to column 0, line 0 (first row) lcd.write(0); // call each segment to create lcd.write(1); // top half of the number lcd.write(2); lcd.setCursor(x, 1); // set cursor to colum 0, line 1 (second row) lcd.write(3); // call each segment to create lcd.write(4); // bottom half of the number lcd.write(5); } void custom1(int x) { lcd.setCursor(x,0); lcd.write(1); lcd.write(2); lcd.print(" "); lcd.setCursor(x,1); lcd.write(4); lcd.write(7); lcd.write(4); } void custom2(int x) { lcd.setCursor(x,0); lcd.write(6); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(4); } void custom3(int x) { lcd.setCursor(x,0); lcd.write(6); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(4); lcd.write(4); lcd.write(5); } void custom4(int x) { lcd.setCursor(x,0); lcd.write(3); lcd.write(4); lcd.write(7); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(7); } void custom5(int x) { lcd.setCursor(x,0); lcd.write(3); lcd.write(6); lcd.write(6); lcd.setCursor(x, 1); lcd.write(4); lcd.write(4); lcd.write(5); } void custom6(int x) { lcd.setCursor(x,0); lcd.write(0); lcd.write(6); lcd.write(6); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(5); } void custom7(int x) { lcd.setCursor(x,0); lcd.write(1); lcd.write(1); lcd.write(2); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(7); } void custom8(int x) { lcd.setCursor(x,0); lcd.write(0); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(5); } void custom9(int x) { lcd.setCursor(x,0); lcd.write(0); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(7); } void digitalClockDisplay(){ // digital clock display of the time printDigits(rtc[2]/10,0); printDigits(rtc[2]%10,4); printDigits(rtc[1]/10,9); printDigits(rtc[1]%10,13); if (rtc[0]%10%2==0){ lcd.setCursor(7, 0); lcd.print("+ "); lcd.setCursor(7, 1); lcd.print(" +"); lcd.setCursor(3, 1); lcd.print("+"); lcd.setCursor(12, 0); lcd.print("+"); lcd.setCursor(3, 0); lcd.print(" "); lcd.setCursor(12, 1); lcd.print(" "); } else { lcd.setCursor(7, 0); lcd.print(" +"); lcd.setCursor(7, 1); lcd.print("+ "); lcd.setCursor(3, 0); lcd.print("+"); lcd.setCursor(12, 1); lcd.print("+"); lcd.setCursor(3, 1); lcd.print(" "); lcd.setCursor(12, 0); lcd.print(" "); } //  } void printDigits(int digits, int x){ // utility function for digital clock display: prints preceding colon and leading 0 switch (digits) { case 0: custom0(x); break; case 1: custom1(x); break; case 2: custom2(x); break; case 3: custom3(x); break; case 4: custom4(x); break; case 5: custom5(x); break; case 6: custom6(x); break; case 7: custom7(x); break; case 8: custom8(x); break; case 9: custom9(x); break; } } void loop () { int hourOn=EEPROM.read(110); //EEPROM.read(110) int hourOff= EEPROM.read(112);; //EEPROM.read(112) int minOn= EEPROM.read(111);; //EEPROM.read(111) int minOff= EEPROM.read(113);; //EEPROM.read(113) int Hour = rtc[2]; //  int Minute = rtc[1]; //  int Second = rtc[0]; //   int FullMinutes = Hour * 60 + Minute; //      int FullMinutesTimerOn= hourOn*60+minOn; //      int FullMinutesTimerOff= hourOff*60+minOff; //      int sutki=0; //  ,      if (hourOff-hourOn < 0) sutki=1; //     ,    =1 else sutki=0; if (sutki==1 && (FullMinutes >= FullMinutesTimerOn || FullMinutes <= FullMinutesTimerOff) ) { lcd.setCursor(16, 2); lcd.print("VKL1"); digitalWrite(RELE_1, LOW); //   ,      } else if (sutki==1) { lcd.print(" "); digitalWrite(RELE_1, HIGH); } if (sutki == 0 && (FullMinutes >= FullMinutesTimerOn && FullMinutes <= FullMinutesTimerOff )) { lcd.setCursor(16, 2); lcd.print("VKL0"); digitalWrite(RELE_1, LOW); } //    ,      else if (sutki == 0) { lcd.print(" "); digitalWrite(RELE_1, HIGH); } RTC.get(rtc,true); digitalClockDisplay(); //    2  strokatimera(); if (rejim==0) { lcd.setCursor(0, 2); lcd.print ("ojidayu komandi"); } if (rejim==1) { setTimerOn(); } if (rejim==2) { setTimerOff(); } if (rejim==3) { setTime(); } if (digitalRead (button5) == HIGH) { rejim++; if (rejim>3) rejim=0; lcd.clear(); //} } } void setTimerOn() { int hourOn= EEPROM.read(110); int minOn= EEPROM.read(111); lcd.setCursor(0, 2); lcd.print("nastroika VKL"); if (digitalRead(button3)==HIGH) //     { hourOn++; if (hourOn >=24) hourOn=0; } if (!digitalRead(button4)) //     { minOn++; if (minOn >=60) { minOn=0; hourOn++; if (hourOn >=24) hourOn=0; } } strokatimera(); if (digitalRead(button2) == HIGH) { EEPROM.write(110, hourOn); EEPROM.write(111, minOn); lcd.clear(); } } void setTimerOff() { int hourOff= EEPROM.read(112); int minOff= EEPROM.read(113); lcd.setCursor(0, 2); lcd.print("nastroika VIKL"); if (digitalRead(button3)==HIGH) //     { hourOff++; if (hourOff >=24) hourOff=0; } if (!digitalRead(button4)) //     { minOff++; if (minOff >=60) { minOff=0; hourOff++; if (hourOff >=24) hourOff=0; } } strokatimera(); if (digitalRead(button2) == HIGH) { EEPROM.write(112, hourOff); EEPROM.write(113, minOff); lcd.clear(); } } void setTime() { lcd.setCursor(0, 2); //lcd.print ("nastroika time_test"); lcd.print ("pustaya nastroika"); } void strokatimera() { int hourOn=EEPROM.read(110); //EEPROM.read(110) int hourOff= EEPROM.read(112);; //EEPROM.read(112) int minOn= EEPROM.read(111);; //EEPROM.read(111) int minOff= EEPROM.read(113);; //EEPROM.read(113) lcd.setCursor(0, 3); //        lcd.print(hourOn); lcd.print(":"); lcd.print(minOn); lcd.print("-"); lcd.print(hourOff); lcd.print(":"); lcd.print(minOff); } 


And this is how it works:



It remains a mystery to me why the controller does not want to react to pressing individual buttons for changing minutes and hours, but willingly reacts to pressing another button by changing minutes. Based on this, I finished the code to a working, albeit a Hindu state, since the first release of the timer must be started up, and the rest should be dealt with later. I sin on overheating when soldering, although the output to these contacts of a standard Blink gives a normal voltage on the pin. At the moment, pin D6 allows you to enter the change menu, and pin D9 scrolls through the minutes. Can someone tell me if I came across this?

PS Already after writing this article, I was faced with the fact that the tasks assigned to the controller should be expanded. The fact is that this controller controls the electric boiler in the country house, and as the temperature rises, the humidity rises. I had to add a channel fan to the ventilation system similar to this:

image

... and hang it up on the second relay. It was established experimentally that it would be best to turn it on every hour for a given period of time. At the same time it is switched on only from 9 to 21 hours, and at night the heat from the house is not thrown out. The on-time adjustment is also made from the buttons, but the operating time is still sewn in the program. At the moment, the hood is turned on for 10 minutes every hour. It is reserved to turn on the hood automatically when the lighting in the bathroom or toilet is turned on.
The current code, which has been working confidently for a month, is below:

Valid Code
 // Date and time functions using a DS1307 RTC connected via I2C and Wire lib #include <EEPROM.h> #include <Wire.h> #include <DS1307.h> #include "RTClib.h" #include <LiquidCrystal_I2C.h> //#define timePIN 10 #define RELE_1 12 //  1    7 #define RELE_2 11 //  2    8 //  A4  SDA   SDA  //  A5  SCL   SCL  int FullMinutesTimerOn = EEPROM.read(0); int FullMinutesTimerOff = EEPROM.read(2); int rtc[7]; byte rr[7]; int ledPin = 13; LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display int button1 = 10; //   D10 int button2 = 9; //   D9 int button3 = 8; //   D8 int button4 = 7; //   D7 int button5 = 6; //   D6 int led = 5; int rejim=0; //     int PrevSec=0; int CurSec=0; boolean lastButton=LOW; byte LT[8] = { B00111, B01111, B11111, B11111, B11111, B11111, B11111, B11111 }; byte UB[8] = { B11111, B11111, B11111, B00000, B00000, B00000, B00000, B00000 }; byte RT[8] = { B11100, B11110, B11111, B11111, B11111, B11111, B11111, B11111 }; byte LL[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B01111, B00111 }; byte LB[8] = { B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111 }; byte LR[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11110, B11100 }; byte MB[8] = { B11111, B11111, B11111, B00000, B00000, B00000, B11111, B11111 }; byte block[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 }; // loop counter int count = 0; void setup () { DDRC|=_BV(2) |_BV(3); // POWER:Vcc Gnd PORTC |=_BV(3); // VCC PINC3 pinMode(ledPin, OUTPUT); //pinMode(timePIN, OUTPUT); pinMode(RELE_1, OUTPUT); //     pinMode(RELE_2, OUTPUT); //     digitalWrite(RELE_1, HIGH); //    digitalWrite(RELE_2, HIGH); //    RTC.get(rtc,true); lcd.init(); // initialize the lcd lcd.backlight(); lcd.home(); lcd.createChar(0,LT); lcd.createChar(1,UB); lcd.createChar(2,RT); lcd.createChar(3,LL); lcd.createChar(4,LB); lcd.createChar(5,LR); lcd.createChar(6,MB); lcd.createChar(7,block); // sets the LCD's rows and colums: lcd.clear(); RTC.SetOutput(DS1307_SQW32KHZ); pinMode(led, OUTPUT); pinMode(button1, INPUT); pinMode(button2, INPUT); pinMode(button3, INPUT); } void custom0(int x) { // uses segments to build the number 0 lcd.setCursor(x,0); // set cursor to column 0, line 0 (first row) lcd.write(0); // call each segment to create lcd.write(1); // top half of the number lcd.write(2); lcd.setCursor(x, 1); // set cursor to colum 0, line 1 (second row) lcd.write(3); // call each segment to create lcd.write(4); // bottom half of the number lcd.write(5); } void custom1(int x) { lcd.setCursor(x,0); lcd.write(1); lcd.write(2); lcd.print(" "); lcd.setCursor(x,1); lcd.write(4); lcd.write(7); lcd.write(4); } void custom2(int x) { lcd.setCursor(x,0); lcd.write(6); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(4); } void custom3(int x) { lcd.setCursor(x,0); lcd.write(6); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(4); lcd.write(4); lcd.write(5); } void custom4(int x) { lcd.setCursor(x,0); lcd.write(3); lcd.write(4); lcd.write(7); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(7); } void custom5(int x) { lcd.setCursor(x,0); lcd.write(3); lcd.write(6); lcd.write(6); lcd.setCursor(x, 1); lcd.write(4); lcd.write(4); lcd.write(5); } void custom6(int x) { lcd.setCursor(x,0); lcd.write(0); lcd.write(6); lcd.write(6); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(5); } void custom7(int x) { lcd.setCursor(x,0); lcd.write(1); lcd.write(1); lcd.write(2); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(7); } void custom8(int x) { lcd.setCursor(x,0); lcd.write(0); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(5); } void custom9(int x) { lcd.setCursor(x,0); lcd.write(0); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(7); } void digitalClockDisplay(){ // digital clock display of the time printDigits(rtc[2]/10,0); printDigits(rtc[2]%10,4); printDigits(rtc[1]/10,9); printDigits(rtc[1]%10,13); if (rtc[0]%10%2==0){ lcd.setCursor(7, 0); lcd.print("+ "); lcd.setCursor(7, 1); lcd.print(" +"); lcd.setCursor(3, 1); lcd.print("+"); lcd.setCursor(12, 0); lcd.print("+"); lcd.setCursor(3, 0); lcd.print(" "); lcd.setCursor(12, 1); lcd.print(" "); } else { lcd.setCursor(7, 0); lcd.print(" +"); lcd.setCursor(7, 1); lcd.print("+ "); lcd.setCursor(3, 0); lcd.print("+"); lcd.setCursor(12, 1); lcd.print("+"); lcd.setCursor(3, 1); lcd.print(" "); lcd.setCursor(12, 0); lcd.print(" "); } //  } void printDigits(int digits, int x){ // utility function for digital clock display: prints preceding colon and leading 0 switch (digits) { case 0: custom0(x); break; case 1: custom1(x); break; case 2: custom2(x); break; case 3: custom3(x); break; case 4: custom4(x); break; case 5: custom5(x); break; case 6: custom6(x); break; case 7: custom7(x); break; case 8: custom8(x); break; case 9: custom9(x); break; } } void loop () { int hourOn=EEPROM.read(110); //EEPROM.read(110) int hourOff= EEPROM.read(112);; //EEPROM.read(112) int minOn= EEPROM.read(111);; //EEPROM.read(111) int minOff= EEPROM.read(113);; //EEPROM.read(113) int minVent= EEPROM.read(114); //   int Hour = rtc[2]; //  int Minute = rtc[1]; //  int Second = rtc[0]; //   int FullMinutes = Hour * 60 + Minute; //      int FullMinutesTimerOn= hourOn*60+minOn; //      int FullMinutesTimerOff= hourOff*60+minOff; //      int sutki=0; //  ,      if (hourOff-hourOn < 0) sutki=1; //     ,    =1 else sutki=0; if (sutki==1 && (FullMinutes >= FullMinutesTimerOn || FullMinutes <= FullMinutesTimerOff) ) { lcd.setCursor(16, 2); lcd.print("VKL1"); digitalWrite(RELE_1, LOW); //   ,      } else if (sutki==1) { lcd.print(" "); digitalWrite(RELE_1, HIGH); } if (sutki == 0 && (FullMinutes >= FullMinutesTimerOn && FullMinutes <= FullMinutesTimerOff )) { lcd.setCursor(16, 2); lcd.print("VKL0"); digitalWrite(RELE_1, LOW); } //    ,      else if (sutki == 0) { lcd.print(" "); digitalWrite(RELE_1, HIGH); } if ((Minute >= 0 && Minute <= minVent) && (Hour >= 9 && Hour <= 21)) { lcd.setCursor(17, 1); lcd.print("VEN"); digitalWrite(RELE_2, LOW); } if (Minute >= 0 && Minute > minVent) { lcd.setCursor(17, 1); lcd.print(" "); digitalWrite(RELE_2, HIGH); } RTC.get(rtc,true); digitalClockDisplay(); //    2  strokatimera(); if (rejim==0) { lcd.setCursor(0, 2); lcd.print ("ojidayu komandi"); } if (rejim==1) { setTimerOn(); } if (rejim==2) { setTimerOff(); } if (rejim==3) { setTime(); } if (rejim==4) { setVent(); } if (digitalRead (button5) == HIGH) { rejim++; if (rejim>4) rejim=0; lcd.clear(); //} } } void setTimerOn() { int hourOn= EEPROM.read(110); int minOn= EEPROM.read(111); lcd.setCursor(0, 2); lcd.print("nastroika VKL"); if (digitalRead(button3)==HIGH) //     { hourOn++; if (hourOn >=24) hourOn=0; } if (!digitalRead(button4)) //     { minOn++; if (minOn >=60) { minOn=0; hourOn++; if (hourOn >=24) hourOn=0; } } strokatimera(); if (digitalRead(button2) == HIGH) { EEPROM.write(110, hourOn); EEPROM.write(111, minOn); lcd.clear(); } } void setTimerOff() { int hourOff= EEPROM.read(112); int minOff= EEPROM.read(113); lcd.setCursor(0, 2); lcd.print("nastroika VIKL"); if (digitalRead(button3)==HIGH) //     { hourOff++; if (hourOff >=24) hourOff=0; } if (!digitalRead(button4)) //     { minOff++; if (minOff >=60) { minOff=0; hourOff++; if (hourOff >=24) hourOff=0; } } strokatimera(); if (digitalRead(button2) == HIGH) { EEPROM.write(112, hourOff); EEPROM.write(113, minOff); lcd.clear(); } } void setTime() { int Hour = rtc[2]; //  int Minute = rtc[1]; //lcd.clear(); lcd.setCursor(0, 2); lcd.print ("nastroika time"); RTC.get(rtc,true); //lcd.setCursor(0, 3); //        // lcd.print(Hour); // lcd.print(":"); // lcd.print(Minute); if (!digitalRead(button4)) //     { Minute++; if (Minute >=60) { Minute=0; Hour++; if (Hour >=24) Hour=0; } } if (digitalRead(button2) == HIGH) { RTC.set(DS1307_MIN,Minute); RTC.set(DS1307_HR,Hour); lcd.clear(); } } void strokatimera() { int hourOn=EEPROM.read(110); //EEPROM.read(110) int hourOff= EEPROM.read(112);; //EEPROM.read(112) int minOn= EEPROM.read(111);; //EEPROM.read(111) int minOff= EEPROM.read(113);; //EEPROM.read(113) int minVent= EEPROM.read(114); lcd.setCursor(0, 3); //        lcd.print(hourOn); lcd.print(":"); lcd.print(minOn); lcd.print("-"); lcd.print(hourOff); lcd.print(":"); lcd.print(minOff); lcd.print(" "); lcd.print("VENT:"); lcd.print(minVent); } void setVent() { int minVent= EEPROM.read(114); lcd.setCursor(0, 2); lcd.print("nastroika Vent"); if (!digitalRead(button4)) //     { minVent++; if (minVent >=60) { minVent=0; } } strokatimera(); if (digitalRead(button2) == HIGH) { EEPROM.write(114, minVent); lcd.clear(); } } 


In the future, this controller is planned to be connected to OpenHab in order to remotely monitor and control the heating and ventilation system of the house.

Version 1.1 of the firmware, which allows you to:


Added work by day
 // Date and time functions using a DS1307 RTC connected via I2C and Wire lib #include <EEPROM.h> #include <Wire.h> #include <DS1307.h> #include "RTClib.h" #include <LiquidCrystal_I2C.h> //#define timePIN 10 #define RELE_1 12 //  1    7 #define RELE_2 11 //  2    8 // //  A4  SDA   SDA  //  A5  SCL   SCL  int FullMinutesTimerOn = EEPROM.read(0); int FullMinutesTimerOff = EEPROM.read(2); int rtc[7]; byte rr[7]; int ledPin = 13; LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display int button1 = 10; //   D10 int button2 = 9; //   D9 int button3 = 8; //   D8 int button4 = 7; //   D7 int button5 = 6; //   D6 int led = 5; int rejim=0; //     int i=1; //       int PrevSec=0; int CurSec=0; int Day=0; boolean lastButton=LOW; byte LT[8] = { B00111, B01111, B11111, B11111, B11111, B11111, B11111, B11111 }; byte UB[8] = { B11111, B11111, B11111, B00000, B00000, B00000, B00000, B00000 }; byte RT[8] = { B11100, B11110, B11111, B11111, B11111, B11111, B11111, B11111 }; byte LL[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B01111, B00111 }; byte LB[8] = { B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111 }; byte LR[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11110, B11100 }; byte MB[8] = { B11111, B11111, B11111, B00000, B00000, B00000, B11111, B11111 }; byte block[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 }; // loop counter int count = 0; void setup () { DDRC|=_BV(2) |_BV(3); // POWER:Vcc Gnd PORTC |=_BV(3); // VCC PINC3 pinMode(ledPin, OUTPUT); //pinMode(timePIN, OUTPUT); pinMode(RELE_1, OUTPUT); //     pinMode(RELE_2, OUTPUT); //     digitalWrite(RELE_1, HIGH); //    digitalWrite(RELE_2, HIGH); //    RTC.get(rtc,true); lcd.init(); // initialize the lcd lcd.backlight(); lcd.home(); lcd.createChar(0,LT); lcd.createChar(1,UB); lcd.createChar(2,RT); lcd.createChar(3,LL); lcd.createChar(4,LB); lcd.createChar(5,LR); lcd.createChar(6,MB); lcd.createChar(7,block); // sets the LCD's rows and colums: lcd.clear(); RTC.SetOutput(DS1307_SQW32KHZ); pinMode(led, OUTPUT); pinMode(button1, INPUT); pinMode(button2, INPUT); pinMode(button3, INPUT); } void custom0(int x) { // uses segments to build the number 0 lcd.setCursor(x,0); // set cursor to column 0, line 0 (first row) lcd.write(0); // call each segment to create lcd.write(1); // top half of the number lcd.write(2); lcd.setCursor(x, 1); // set cursor to colum 0, line 1 (second row) lcd.write(3); // call each segment to create lcd.write(4); // bottom half of the number lcd.write(5); } void custom1(int x) { lcd.setCursor(x,0); lcd.write(1); lcd.write(2); lcd.print(" "); lcd.setCursor(x,1); lcd.write(4); lcd.write(7); lcd.write(4); } void custom2(int x) { lcd.setCursor(x,0); lcd.write(6); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(4); } void custom3(int x) { lcd.setCursor(x,0); lcd.write(6); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(4); lcd.write(4); lcd.write(5); } void custom4(int x) { lcd.setCursor(x,0); lcd.write(3); lcd.write(4); lcd.write(7); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(7); } void custom5(int x) { lcd.setCursor(x,0); lcd.write(3); lcd.write(6); lcd.write(6); lcd.setCursor(x, 1); lcd.write(4); lcd.write(4); lcd.write(5); } void custom6(int x) { lcd.setCursor(x,0); lcd.write(0); lcd.write(6); lcd.write(6); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(5); } void custom7(int x) { lcd.setCursor(x,0); lcd.write(1); lcd.write(1); lcd.write(2); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(7); } void custom8(int x) { lcd.setCursor(x,0); lcd.write(0); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(5); } void custom9(int x) { lcd.setCursor(x,0); lcd.write(0); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(7); } void digitalClockDisplay(){ // digital clock display of the time printDigits(rtc[2]/10,0); printDigits(rtc[2]%10,4); printDigits(rtc[1]/10,9); printDigits(rtc[1]%10,13); if (rtc[0]%10%2==0){ lcd.setCursor(7, 0); lcd.print("+ "); lcd.setCursor(7, 1); lcd.print(" +"); lcd.setCursor(3, 1); lcd.print("+"); lcd.setCursor(12, 0); lcd.print("+"); lcd.setCursor(3, 0); lcd.print(" "); lcd.setCursor(12, 1); lcd.print(" "); } else { lcd.setCursor(7, 0); lcd.print(" +"); lcd.setCursor(7, 1); lcd.print("+ "); lcd.setCursor(3, 0); lcd.print("+"); lcd.setCursor(12, 1); lcd.print("+"); lcd.setCursor(3, 1); lcd.print(" "); lcd.setCursor(12, 0); lcd.print(" "); } //  } void printDigits(int digits, int x){ // utility function for digital clock display: prints preceding colon and leading 0 switch (digits) { case 0: custom0(x); break; case 1: custom1(x); break; case 2: custom2(x); break; case 3: custom3(x); break; case 4: custom4(x); break; case 5: custom5(x); break; case 6: custom6(x); break; case 7: custom7(x); break; case 8: custom8(x); break; case 9: custom9(x); break; } } void loop () { int hourOn=EEPROM.read(110); //EEPROM.read(110) int hourOff= EEPROM.read(112);; //EEPROM.read(112) int minOn= EEPROM.read(111);; //EEPROM.read(111) int minOff= EEPROM.read(113);; //EEPROM.read(113) int minVent= EEPROM.read(114); //   int rejimDay=0; int Day = rtc[3]; //  int Hour = rtc[2]; //  int Minute = rtc[1]; //  int Second = rtc[0]; //   int FullMinutes = Hour * 60 + Minute; //      int FullMinutesTimerOn= hourOn*60+minOn; //      int FullMinutesTimerOff= hourOff*60+minOff; //      int sutki=0; //  ,      lcd.setCursor(16, 0); lcd.print(Day); if (hourOff-hourOn < 0) sutki=1; //     ,    =1 else sutki=0; if (EEPROM.read(114+Day)==1 && sutki==1) { rejimDay=1; lcd.print("+"); } else { rejimDay=0; lcd.print("-"); } if (sutki==1 && (FullMinutes >= FullMinutesTimerOn || FullMinutes <= FullMinutesTimerOff) ) { lcd.setCursor(16, 2); lcd.print("VKL"); digitalWrite(RELE_1, LOW); //   ,      } else if (sutki==1) { lcd.print(" "); digitalWrite(RELE_1, HIGH); } if (sutki == 0 && (FullMinutes >= FullMinutesTimerOn && FullMinutes <= FullMinutesTimerOff )) { lcd.setCursor(16, 2); lcd.print("VKL"); digitalWrite(RELE_1, LOW); } //    ,      else if (sutki == 0) { lcd.print(" "); digitalWrite(RELE_1, HIGH); } if ((Minute >= 0 && Minute <= minVent) && (Hour >= 9 && Hour <= 21)) { lcd.setCursor(17, 1); lcd.print("VEN"); digitalWrite(RELE_2, LOW); } if (Minute >= 0 && Minute > minVent) { lcd.setCursor(17, 1); lcd.print(" "); digitalWrite(RELE_2, HIGH); } RTC.get(rtc,true); if (rejim==0) { lcd.setCursor(0, 2); lcd.print ("ojidayu komandi"); strokatimera(); digitalClockDisplay(); //    2  } if (rejim==1) { setTimerOn(); } if (rejim==2) { setTimerOff(); } if (rejim==3) { setTime(); } if (rejim==4) { setVent(); } if (rejim==5) { setTimerDay1(); } if (digitalRead (button5) == HIGH) { rejim++; delay(100); if (rejim>5) rejim=0; lcd.clear(); //} } } void setTimerOn() { int hourOn= EEPROM.read(110); int minOn= EEPROM.read(111); lcd.setCursor(0, 2); lcd.print("nastroika VKL"); if (digitalRead(button3)==HIGH) //     { hourOn++; if (hourOn >=24) hourOn=0; } if (digitalRead(button2)==HIGH) //     { minOn++; if (minOn >=60) { minOn=0; hourOn++; if (hourOn >=24) hourOn=0; } } strokatimera(); digitalClockDisplay(); if (digitalRead(button2) == HIGH) { EEPROM.write(110, hourOn); EEPROM.write(111, minOn); lcd.clear(); } } void setTimerOff() { int hourOff= EEPROM.read(112); int minOff= EEPROM.read(113); lcd.setCursor(0, 2); lcd.print("nastroika VIKL"); if (digitalRead(button3)==HIGH) //     { hourOff++; if (hourOff >=24) hourOff=0; } if (!digitalRead(button4)) //     { minOff++; if (minOff >=60) { minOff=0; hourOff++; if (hourOff >=24) hourOff=0; } } strokatimera(); digitalClockDisplay(); if (digitalRead(button2) == HIGH) { EEPROM.write(112, hourOff); EEPROM.write(113, minOff); lcd.clear(); } } void setTime() { int Hour = rtc[2]; //  int Minute = rtc[1]; //lcd.clear(); lcd.setCursor(0, 2); lcd.print ("nastroika time"); RTC.get(rtc,true); digitalClockDisplay(); //lcd.setCursor(0, 3); //        // lcd.print(Hour); // lcd.print(":"); // lcd.print(Minute); if (!digitalRead(button4)) //     { Minute++; if (Minute >=60) { Minute=0; Hour++; if (Hour >=24) Hour=0; } } if (digitalRead(button2) == HIGH) { RTC.set(DS1307_MIN,Minute); RTC.set(DS1307_HR,Hour); lcd.clear(); } } void strokatimera() { int hourOn=EEPROM.read(110); //EEPROM.read(110) int hourOff= EEPROM.read(112);; //EEPROM.read(112) int minOn= EEPROM.read(111);; //EEPROM.read(111) int minOff= EEPROM.read(113);; //EEPROM.read(113) int minVent= EEPROM.read(114); lcd.setCursor(0, 3); //        lcd.print(hourOn); lcd.print(":"); lcd.print(minOn); lcd.print("-"); lcd.print(hourOff); lcd.print(":"); lcd.print(minOff); lcd.print(" "); lcd.print("VENT:"); lcd.print(minVent); } void setVent() { strokatimera(); int minVent= EEPROM.read(114); lcd.setCursor(0, 2); lcd.print("nastroika Vent"); if (!digitalRead(button4)) //     { minVent++; if (minVent >=60) { minVent=0; } } digitalClockDisplay(); //    2  if (digitalRead(button2) == HIGH) { EEPROM.write(114, minVent); lcd.clear(); } } void setTimerDay1() { int z; //lcd.clear(); lcd.setCursor(0, 0); lcd.print ("nastroika dney"); //lcd.setCursor(0, 1); lcd.setCursor (0,3); lcd.print (EEPROM.read(115)); lcd.print (" "); lcd.print (EEPROM.read(116)); lcd.print (" "); lcd.print (EEPROM.read(117)); lcd.print (" "); lcd.print (EEPROM.read(118)); lcd.print (" "); lcd.print (EEPROM.read(119)); lcd.print (" "); lcd.print (EEPROM.read(120)); lcd.print (" "); lcd.print (EEPROM.read(121)); lcd.print (" "); //lcd.clear(); z=EEPROM.read(114+i); //     /   if (i==1) { lcd.setCursor(1, 2); lcd.print ("ponedelnik"); lcd.print (" "); lcd.print (z); } if (i==2) { lcd.setCursor(1, 2); lcd.print ("vtornik"); lcd.print (" "); lcd.print (z); } if (i==3) { lcd.setCursor(1, 2); lcd.print ("sreda"); lcd.print (" "); lcd.print (z); } if (i==4) { lcd.setCursor(1, 2); lcd.print ("chetverg"); lcd.print (" "); lcd.print (z); } if (i==5) { lcd.setCursor(1, 2); lcd.print ("pyatnica"); lcd.print (" "); lcd.print (z); } if (i==6) { lcd.setCursor(1, 2); lcd.print ("subbota"); lcd.print (" "); lcd.print (z); } if (i==7) { lcd.setCursor(1, 2); lcd.print ("voskresen'e"); lcd.print (" "); lcd.print (z); } if (digitalRead(button3)==HIGH) //   { lcd.clear(); i++; delay(150); if (i>7) {i=1;} } if (digitalRead(button2)==HIGH) { delay(150); z=!z; if (z!= EEPROM.read(114+i)) { EEPROM.write(114+i,z); } } } 



Faced with the fact that the regular work of the hood noticeably squeezes the house in extreme cold, vybrsyvaya warm air outside the room. Added in the menu item off the hood. On the inclusion of lighting in the toilet and bathroom hood always works. Also corrected some points in the firmware.

Added shutdown hood
 // Date and time functions using a DS1307 RTC connected via I2C and Wire lib #include <EEPROM.h> #include <Wire.h> #include <DS1307.h> #include "RTClib.h" #include <LiquidCrystal_I2C.h> //#define timePIN 10 #define RELE_1 11 //      #define RELE_2 12 //  ,   // //  A4  SDA   SDA  //  A5  SCL   SCL  int FullMinutesTimerOn = EEPROM.read(0); int FullMinutesTimerOff = EEPROM.read(2); int rtc[7]; byte rr[7]; int ledPin = 13; LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display int button1 = 10; //   D10 int button2 = 9; //   D9 int button3 = 8; //   D8 int button4 = 7; //   D7 int button5 = 6; //   D6 int vanna = 2; //     D2 int led = 5; int rejim=0; //     int i=1; //       int PrevSec=0; int CurSec=0; int Day=0; int vannatimer=0; boolean lastButton=LOW; byte LT[8] = { B00111, B01111, B11111, B11111, B11111, B11111, B11111, B11111 }; byte UB[8] = { B11111, B11111, B11111, B00000, B00000, B00000, B00000, B00000 }; byte RT[8] = { B11100, B11110, B11111, B11111, B11111, B11111, B11111, B11111 }; byte LL[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B01111, B00111 }; byte LB[8] = { B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111 }; byte LR[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11110, B11100 }; byte MB[8] = { B11111, B11111, B11111, B00000, B00000, B00000, B11111, B11111 }; byte block[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 }; // loop counter int count = 0; void setup () { DDRC|=_BV(2) |_BV(3); // POWER:Vcc Gnd PORTC |=_BV(3); // VCC PINC3 pinMode(ledPin, OUTPUT); //pinMode(timePIN, OUTPUT); pinMode(RELE_1, OUTPUT); //     pinMode(RELE_2, OUTPUT); //     digitalWrite(RELE_1, HIGH); //    digitalWrite(RELE_2, HIGH); //    RTC.get(rtc,true); lcd.init(); // initialize the lcd lcd.backlight(); lcd.home(); lcd.createChar(0,LT); lcd.createChar(1,UB); lcd.createChar(2,RT); lcd.createChar(3,LL); lcd.createChar(4,LB); lcd.createChar(5,LR); lcd.createChar(6,MB); lcd.createChar(7,block); // sets the LCD's rows and colums: lcd.clear(); RTC.SetOutput(DS1307_SQW32KHZ); pinMode(led, OUTPUT); pinMode(button1, INPUT); pinMode(button2, INPUT); pinMode(button3, INPUT); pinMode(vanna, INPUT); //    - } void custom0(int x) { // uses segments to build the number 0 lcd.setCursor(x,0); // set cursor to column 0, line 0 (first row) lcd.write(0); // call each segment to create lcd.write(1); // top half of the number lcd.write(2); lcd.setCursor(x, 1); // set cursor to colum 0, line 1 (second row) lcd.write(3); // call each segment to create lcd.write(4); // bottom half of the number lcd.write(5); } void custom1(int x) { lcd.setCursor(x,0); lcd.write(1); lcd.write(2); lcd.print(" "); lcd.setCursor(x,1); lcd.write(4); lcd.write(7); lcd.write(4); } void custom2(int x) { lcd.setCursor(x,0); lcd.write(6); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(4); } void custom3(int x) { lcd.setCursor(x,0); lcd.write(6); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(4); lcd.write(4); lcd.write(5); } void custom4(int x) { lcd.setCursor(x,0); lcd.write(3); lcd.write(4); lcd.write(7); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(7); } void custom5(int x) { lcd.setCursor(x,0); lcd.write(3); lcd.write(6); lcd.write(6); lcd.setCursor(x, 1); lcd.write(4); lcd.write(4); lcd.write(5); } void custom6(int x) { lcd.setCursor(x,0); lcd.write(0); lcd.write(6); lcd.write(6); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(5); } void custom7(int x) { lcd.setCursor(x,0); lcd.write(1); lcd.write(1); lcd.write(2); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(7); } void custom8(int x) { lcd.setCursor(x,0); lcd.write(0); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(5); } void custom9(int x) { lcd.setCursor(x,0); lcd.write(0); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(7); } void digitalClockDisplay(){ // digital clock display of the time printDigits(rtc[2]/10,0); printDigits(rtc[2]%10,4); printDigits(rtc[1]/10,9); printDigits(rtc[1]%10,13); if (rtc[0]%10%2==0){ lcd.setCursor(7, 0); lcd.print("+ "); lcd.setCursor(7, 1); lcd.print(" +"); lcd.setCursor(3, 1); lcd.print("+"); lcd.setCursor(12, 0); lcd.print("+"); lcd.setCursor(3, 0); lcd.print(" "); lcd.setCursor(12, 1); lcd.print(" "); } else { lcd.setCursor(7, 0); lcd.print(" +"); lcd.setCursor(7, 1); lcd.print("+ "); lcd.setCursor(3, 0); lcd.print("+"); lcd.setCursor(12, 1); lcd.print("+"); lcd.setCursor(3, 1); lcd.print(" "); lcd.setCursor(12, 0); lcd.print(" "); } //  } void printDigits(int digits, int x){ // utility function for digital clock display: prints preceding colon and leading 0 switch (digits) { case 0: custom0(x); break; case 1: custom1(x); break; case 2: custom2(x); break; case 3: custom3(x); break; case 4: custom4(x); break; case 5: custom5(x); break; case 6: custom6(x); break; case 7: custom7(x); break; case 8: custom8(x); break; case 9: custom9(x); break; } } void loop () { int hourOn=EEPROM.read(110); //EEPROM.read(110) int hourOff= EEPROM.read(112);; //EEPROM.read(112) int minOn= EEPROM.read(111);; //EEPROM.read(111) int minOff= EEPROM.read(113);; //EEPROM.read(113) int minVent= EEPROM.read(114); //   int Vent= EEPROM.read(122); int rejimDay=0; int Day = rtc[3]; //  int Hour = rtc[2]; //  int Minute = rtc[1]; //  int Second = rtc[0]; //   int FullMinutes = Hour * 60 + Minute; //      int FullMinutesTimerOn= hourOn*60+minOn; //      int FullMinutesTimerOff= hourOff*60+minOff; //      int sutki=0; //  ,      //if (digitalRead (vanna) == HIGH) //           //{ // digitalWrite(RELE_2, LOW); //digitalWrite(ledPin, HIGH); // vannatimer=1; //} lcd.setCursor(16, 0); lcd.print(Day); if (hourOff-hourOn < 0) sutki=1; //     ,    =1 else sutki=0; if (EEPROM.read(114+Day)==1 && sutki==1) { rejimDay=1; lcd.print("+"); } else { rejimDay=0; lcd.print("-"); } if ((sutki==1 && rejimDay==1) && (FullMinutes >= FullMinutesTimerOn || FullMinutes <= FullMinutesTimerOff) ) { lcd.setCursor(16, 2); lcd.print("VKL"); digitalWrite(RELE_1, LOW); //   ,      } else if (sutki==1) { lcd.print(" "); digitalWrite(RELE_1, HIGH); } if (sutki == 0 && (FullMinutes >= FullMinutesTimerOn && FullMinutes <= FullMinutesTimerOff )) { lcd.setCursor(16, 2); lcd.print("VKL"); digitalWrite(RELE_1, LOW); } //    ,      else if (sutki == 0) { lcd.print(" "); digitalWrite(RELE_1, HIGH); } if (((Minute >= 0 && Minute <= minVent) && (Hour >= 9 && Hour <= 21))||(digitalRead (vanna) == HIGH)) { if (Vent==1) { lcd.setCursor(17, 1); lcd.print("VEN"); digitalWrite(RELE_2, LOW); } } if ((Minute >= 0 && Minute > minVent || digitalRead (vanna) == LOW)&&(Vent==0)) { lcd.setCursor(17, 1); lcd.print(" "); digitalWrite(RELE_2, HIGH); } if (digitalRead (vanna) == HIGH) digitalWrite(RELE_2, LOW); //          RTC.get(rtc,true); if (rejim==0) { lcd.setCursor(0, 2); lcd.print ("ojidayu komandi"); strokatimera(); digitalClockDisplay(); //    2  } if (rejim==1) { setTimerOn(); } if (rejim==2) { setTimerOff(); } if (rejim==3) { setTime(); } if (rejim==4) { setVent(); } if (rejim==5) { setVentOnOff(); } if (rejim==6) { setTimerDay1(); } if (digitalRead (button5) == HIGH) { rejim++; delay(100); if (rejim>6) rejim=0; lcd.clear(); //} } } void setTimerOn() { int hourOn= EEPROM.read(110); int minOn= EEPROM.read(111); lcd.setCursor(0, 2); lcd.print("nastroika VKL"); if (digitalRead(button3)==HIGH) //     { hourOn++; if (hourOn >=24) hourOn=0; } if (digitalRead(button2)==HIGH) //     { minOn++; if (minOn >=60) { minOn=0; hourOn++; if (hourOn >=24) hourOn=0; } } strokatimera(); digitalClockDisplay(); if ((digitalRead(button2) == HIGH)||(digitalRead(button3) == HIGH)) { EEPROM.write(110, hourOn); EEPROM.write(111, minOn); lcd.clear(); } } void setTimerOff() { int hourOff= EEPROM.read(112); int minOff= EEPROM.read(113); lcd.setCursor(0, 2); lcd.print("nastroika VIKL"); if (digitalRead(button3)==HIGH) //     { hourOff++; if (hourOff >=24) hourOff=0; } if (digitalRead(button2)==HIGH) //     { minOff++; if (minOff >=60) { minOff=0; hourOff++; if (hourOff >=24) hourOff=0; } } strokatimera(); digitalClockDisplay(); if ((digitalRead(button2) == HIGH)||(digitalRead(button3) == HIGH)) { EEPROM.write(112, hourOff); EEPROM.write(113, minOff); lcd.clear(); } } void setTime() { int Hour = rtc[2]; //  int Minute = rtc[1]; //lcd.clear(); lcd.setCursor(0, 2); lcd.print ("nastroika time"); RTC.get(rtc,true); digitalClockDisplay(); //lcd.setCursor(0, 3); //        // lcd.print(Hour); // lcd.print(":"); // lcd.print(Minute); if (digitalRead(button2)==HIGH) //     { Minute++; if (Minute >=60) { Minute=0; Hour++; if (Hour >=24) Hour=0; } } if (digitalRead(button3)==HIGH) //     { Hour++; if (Hour >=24) Hour=0; } if ((digitalRead(button2) == HIGH)||(digitalRead(button3) == HIGH)) { RTC.set(DS1307_MIN,Minute); RTC.set(DS1307_HR,Hour); lcd.clear(); } } void strokatimera() { int hourOn=EEPROM.read(110); //EEPROM.read(110) int hourOff= EEPROM.read(112);; //EEPROM.read(112) int minOn= EEPROM.read(111);; //EEPROM.read(111) int minOff= EEPROM.read(113);; //EEPROM.read(113) int minVent= EEPROM.read(114); lcd.setCursor(0, 3); //        lcd.print(hourOn); lcd.print(":"); lcd.print(minOn); lcd.print("-"); lcd.print(hourOff); lcd.print(":"); lcd.print(minOff); lcd.print(" "); lcd.print("VENT:"); lcd.print(minVent); } void setVent() { strokatimera(); int minVent= EEPROM.read(114); lcd.setCursor(0, 2); lcd.print("nastroika Vent"); if (!digitalRead(button4)) //     { minVent++; if (minVent >=60) { minVent=0; } } digitalClockDisplay(); //    2  if (digitalRead(button2) == HIGH) { EEPROM.write(114, minVent); lcd.clear(); } } void setVentOnOff() { strokatimera(); int Vent= EEPROM.read(122); lcd.setCursor(0, 2); lcd.print("Vent"); if (Vent==0) lcd.print(" Off"); if (Vent==1) lcd.print(" On"); if (!digitalRead(button4)) //       { delay(100); Vent++; if (Vent >=2) { Vent=0; } } digitalClockDisplay(); //    2  if (digitalRead(button2) == HIGH) { EEPROM.write(122, Vent); lcd.clear(); } } void setTimerDay1() { int z; //lcd.clear(); lcd.setCursor(0, 0); lcd.print ("nastroika dney"); //lcd.setCursor(0, 1); lcd.setCursor (0,3); lcd.print (EEPROM.read(115)); lcd.print (" "); lcd.print (EEPROM.read(116)); lcd.print (" "); lcd.print (EEPROM.read(117)); lcd.print (" "); lcd.print (EEPROM.read(118)); lcd.print (" "); lcd.print (EEPROM.read(119)); lcd.print (" "); lcd.print (EEPROM.read(120)); lcd.print (" "); lcd.print (EEPROM.read(121)); lcd.print (" "); //lcd.clear(); z=EEPROM.read(114+i); //     /   if (i==1) { lcd.setCursor(1, 2); lcd.print ("ponedelnik"); lcd.print (" "); lcd.print (z); } if (i==2) { lcd.setCursor(1, 2); lcd.print ("vtornik"); lcd.print (" "); lcd.print (z); } if (i==3) { lcd.setCursor(1, 2); lcd.print ("sreda"); lcd.print (" "); lcd.print (z); } if (i==4) { lcd.setCursor(1, 2); lcd.print ("chetverg"); lcd.print (" "); lcd.print (z); } if (i==5) { lcd.setCursor(1, 2); lcd.print ("pyatnica"); lcd.print (" "); lcd.print (z); } if (i==6) { lcd.setCursor(1, 2); lcd.print ("subbota"); lcd.print (" "); lcd.print (z); } if (i==7) { lcd.setCursor(1, 2); lcd.print ("voskresen'e"); lcd.print (" "); lcd.print (z); } if (digitalRead(button3)==HIGH) //   { lcd.clear(); i++; delay(150); if (i>7) {i=1;} } if (digitalRead(button2)==HIGH) { delay(150); z=!z; if (z!= EEPROM.read(114+i)) { EEPROM.write(114+i,z); } } //EEPROM.write(115, 0);// //EEPROM.write(116, 0);// //EEPROM.write(117, 1);// //EEPROM.write(118, 0);// //EEPROM.write(119, 1);// //EEPROM.write(120, 1);// //EEPROM.write(121, 0);// //z=EEPROM.read(114+i); } 

Source: https://habr.com/ru/post/251121/


All Articles