Kontrol suhu pemanas oven, dengan timer pada Arduino

Saya membutuhkan tungku untuk memanggang tanah liat polimer. Setelah pencarian tidak lama, pilihan jatuh pada oven listrik KEDR untuk dapur. Dengan kekuatan 600 watt, dengan suhu maksimum 250 derajat, tanpa regulator. Untuk pertama kalinya, regulator termomekanis dipasang, karena suhu untuk operasi diperlukan dalam kisaran 100-130 derajat. Tetapi seluruh masalahnya adalah tungku memiliki akselerasi yang sangat besar (setelah mematikan pemanas, suhu terus meningkat 20-50 derajat), dan regulator memiliki rentang on dan off yang sangat besar. Artinya, mengatur suhu ke 130 derajat, saya mendapat kisaran 100 - 160 derajat, yang tidak diizinkan.

Setelah beberapa bulan menganalisis prinsip-prinsip bekerja dengan Arduino IDE dan C ++, sebuah proyek lahir yang sepenuhnya memenuhi persyaratan. Perangkat dapat menjaga suhu yang diatur dari 100 hingga 150 derajat, setelah mencapai waktu yang diatur selama 5-35 menit, tergantung pada pengaturan, setelah alarm dipicu.

Berikut ini adalah diagram blok program.



Perangkat ini meliputi: empat pemanas serial yang dipasang di tungku secara default, yang dapat diganti dengan pemanas lain dari daya yang sesuai, relai keadaan padat SSR-25 DA, Arduino Pro Mini, enkoder tambahan dengan tombol yang terhubung melalui pemicu Schmitt terbalik, tampilan WH1602D dan dua NTC termistor MF58 pada 100kOhm.

Ini adalah kode sketsa, dengan komentar.

Daftar
#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(); } // <-    


Karena ini adalah salah satu proyek pertama, saya meminta lebih banyak kritik!

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


All Articles