📜 ⬆️ ⬇️

Oven heater temperature control, with timer on Arduino

Needed a stove for baking polymer clay. After not long searching, the choice fell on the electric oven for the kitchen "KEDR". The power of 600 watts, with a maximum temperature of 250 degrees, without a regulator. For the first time, a thermomechanical regulator was installed, since the temperature for work was required in the range of 100-130 degrees. But the whole problem was that the furnace had a very large acceleration (after turning off the heater, the temperature continued to grow by another 20-50 degrees), and the regulator had a very large on and off range. That is, setting the temperature to 130 degrees, I received a range of 100 - 160 degrees, which is not valid.

After several months of analyzing the principles of working with the Arduino IDE and C ++, a project was born that fully meets the requirements. The device can keep the set temperature from 100 to 150 degrees, upon reaching which the timer setting for 5-35 minutes is triggered, depending on the setting, after the alarm goes off.

Here is a flowchart of the program.


')
The device includes: four consecutive heaters installed in the furnace by default, which can be replaced with any other heater of appropriate power, SSR-25 DA solid-state relay, Arduino Pro Mini, incremental encoder with a button connected via a Schmitt inverting trigger, WH1602D display and two NTC MF58 thermistors per 100kΩ.

Here is the sketch code, with comments.

Listing
#include <LiquidCrystal.h> #include "timer-api.h" const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 6; //    LiquidCrystal lcd(rs, en, d4, d5, d6, d7); int encCLK = 2 ; //    int encDT = 7; //    int button = 8 ; //    //        !!! volatile bool button_not_press = true; //     volatile int pinClkValue = 0; //      volatile int pinDtValue = 0; //      uint8_t temp_cel[8] = {B00111,B00101,B00111,B00000,B00000,B00000,B00000}; //   int temp_upside_pin = 14; //     MF58 100k,     int temp_downside_pin = 15; //   .      (-),   //    100k  (+5v). volatile float temp_upside; //       volatile float temp_downside; //       #define B 3950 // B-    int heater_pin = 10; //     SSR-25DA. volatile bool preheating_state = false; //  ,      volatile bool heater_state = true; //   volatile int hyst = 40; //        volatile int changeTemp; //     60 . volatile long timeHyst = 0; //     volatile long normalModeTime; //     volatile int curTemp = 0; //    ,    volatile int setTemp = 0; //     int *pCurTemp = &curTemp; // ,     ...? int *pSetTemp = &setTemp; // ,     ...? volatile bool alarm; //  volatile int count = 0; //    state*5 volatile int state = 0; //    volatile int setTimeMinute = 0; //        volatile int second = 0; //        int *pMinute = &setTimeMinute; // ,     ...? volatile long currentTime = millis(); //     //======================================================= void setup() { //     timer-api.h,       timer_init_ISR_1Hz(TIMER_DEFAULT); //    /(pin) pinMode(encCLK, INPUT); //  CLK  pinMode(encDT, INPUT); //  DT  pinMode(button, INPUT); //  button  pinMode(temp_upside_pin, INPUT); //       1 pinMode(temp_downside_pin,INPUT); //       2 pinMode(heater_pin, OUTPUT); //    attachInterrupt(0, clkEnc, CHANGE);//     lcd.createChar(1, temp_cel); //    //    !!! lcd.begin(16, 2); lcd.setCursor(2, 0); lcd.print("Polimer Clay"); lcd.setCursor(0, 1); lcd.print("BURNER ver. 1.01"); delay(2000); //     lcd.clear(); lcd.print("Set"); lcd.setCursor(11, 0); lcd.print("Timer"); lcd.setCursor(0, 1); lcd.print("Cur"); lcd.setCursor(9, 1); lcd.print(" NotSet"); setupTemp(); //      } //===================================================== void clkEnc(){ //    ,    pinClkValue = digitalRead(encCLK); pinDtValue = digitalRead(encDT); cli(); if (!pinClkValue && pinDtValue) state = 1; if (!pinClkValue && !pinDtValue) state = -1; if (pinClkValue && state != 0) { if (state == 1 && !pinDtValue || state == -1 && pinDtValue) { count += state*5; state = 0; }} sei(); } //===================================================== void setupTemp(){ //    count = 0; //   button_not_press = true; //   ,     while,      while(button_not_press){ //    ... if (count <= 100) count = 100; //      100 if (count >= 151) count = 150; //      150 setTemp = count; //    //    lcd.setCursor(4, 0); if(*pSetTemp<10) lcd.print(" "); else if(*pSetTemp<100) lcd.print(" "); lcd.print(*pSetTemp); lcd.print("\1"); lcd.print("C"); lcd.print(" "); if(*pSetTemp !=0)button_not_press = digitalRead(button); //   preheating_state = true;}} //      //===================================================== void setupTimer(){ //   lcd.setCursor(11, 0); //     lcd.print("Timer"); //   count = 0; //   button_not_press = true; lcd.setCursor(9, 1); //  lcd.print(" "); // NotSet while(button_not_press){ //    ... if (count <= -1) count = 0; //       -  0 if (count >= 36) count = 35; //       -  35 setTimeMinute = count; //    lcd.setCursor(11, 1); //     if(*pMinute<10)lcd.print("0"); lcd.print(*pMinute); //    lcd.print(":00"); //     00:00 tempMonitor(); //   if(*pMinute !=0)button_not_press = digitalRead(button);} //   if (*pMinute != 0){second = 0; timerStart();} //   ,     timeEnd(); } //   , !!! //====================================================== void tempMonitor(){ //   !!! //          . if(millis() > normalModeTime + 10){ heater_state = !heater_state; normalModeTime = millis();} //          if(millis() > currentTime + 500){ lcd.setCursor(4, 1); if(*pCurTemp<10) lcd.print(" "); else if(*pCurTemp<100) lcd.print(" "); lcd.print(*pCurTemp); lcd.print("\1"); lcd.print("C"); lcd.print(" "); int US = analogRead(temp_upside_pin); //   1  int DS = analogRead(temp_downside_pin); //   2  int MID = (US+DS)/2; //    float tr = (5 / 1023.0) * MID ; //    float VR = 5 - tr; //    float RT = tr/(VR / 99000); //    float ln = log(RT / 100000); float TX = (1 / ((ln / B) + (1 / (25+273.15)))); //    —  TX = round(TX - 273.15); //        *pCurTemp = int(TX); //    currentTime = millis(); } //      ( - hyst) if(preheating_state){ if(*pCurTemp < (*pSetTemp - hyst)) digitalWrite(heater_pin, HIGH); //     ( - hyst), //         (pSetTemp). else if(*pCurTemp > (*pSetTemp - hyst)) digitalWrite(heater_pin, LOW); if (*pCurTemp >= *pSetTemp){ preheating_state = false; Serial.print(preheating_state); } //             //   ,       //      ,     // .    , //     . if (millis() > timeHyst + 30000){ changeTemp = *pCurTemp; //   30 ,     timeHyst = millis(); } if(changeTemp >= *pCurTemp){ if(!digitalRead(heater_pin)){ digitalWrite(heater_pin, HIGH);}}} //   (pSetTemp)  //           //    5    if(!preheating_state){ if(*pCurTemp < *pSetTemp - 5) { digitalWrite(heater_pin, heater_state);} else digitalWrite(heater_pin, LOW); }} //==================================================== void timer_handle_interrupts(int timer){second--;} //==================================================== //          //  second,     //     . void timerStart(){ while(*pMinute+second != 0){ if (second == 0){(*pMinute)--; second = 59;} lcd.setCursor(11, 1); if(*pMinute<10)lcd.print(" "); lcd.print(*pMinute); lcd.print(":"); if(second<10)lcd.print("0"); lcd.print(second); lcd.print(" "); if(alarm){ noTone(9); if(!digitalRead(button)){ alarm = false; noTone(9); return;}} tempMonitor(); if(alarm) tone(9,100); }} //=================================================== //  !!! void timeEnd(){ alarm = true; lcd.setCursor(11, 0); lcd.print("Alarm"); *pMinute = 1; //second = 30; //   <- ,    timerStart(); //,       0 if(alarm){ //    ,    *pSetTemp = 0; //       ,   digitalWrite(heater_pin, LOW); //  ,      lcd.setCursor(4, 0); if(*pSetTemp<10) lcd.print(" "); else if(*pSetTemp<100) lcd.print(" "); lcd.print(*pSetTemp); lcd.print("\1"); lcd.print("C"); lcd.print(" "); alarm = false; }} //==================================================== //       void loop() { tempMonitor(); // <-    if(*pSetTemp == 0 && !digitalRead(button)) setupTemp(); // <-     0 if(*pCurTemp == *pSetTemp) setupTimer(); } // <-    


Since this is one of the first projects, I ask for more criticism!

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


All Articles