2016年9月11日日曜日

arduino control fridge

mcu(this time arduino uno) control fridge to simulate mechanical control fridge as attached.

sketch is as follows;-
#include <LiquidCrystal.h>

LiquidCrystal lcd(6,7,8,9,10,11); //lcd model comp relay =normal open type
int eva_temp,fre_temp,ref_temp,volume,level,h,l,ev,ft,rt,sample1=0,sample2=0,sample3=0,time=0,show_all; // time to switch defrost
unsigned long curr_time,last_def,display_int,last_display,compon,compoff,comp_interval; //defrost interval time
const int ry_comp=4,ry_heater=5,disclose=12,def_switch=19; //relay,defrost led,discloseは

void setup(){
 lcd.begin(16,2);
 pinMode(ry_comp,OUTPUT);
 pinMode(ry_heater,OUTPUT);
 pinMode(disclose,OUTPUT);  //debug
 pinMode(def_switch,INPUT);
 last_def=millis();
 last_display=millis();
 compoff=millis();
}
void loop(){
 while (millis()<=3000){
    digitalWrite(ry_comp,LOW);
    sample1=digitalRead(def_switch);
   lcd.clear();
   lcd.print("  >> lcd model <<"); // display "brand name"
   lcd.setCursor(0,1);
   lcd.print("model no.new"); // display "model number"
   delay(60);
 }
 while (millis()<=180000){
   digitalWrite(ry_comp,LOW);  //3 min delay start compressor after reset
   sample2=digitalRead(def_switch);
   if (sample1!=sample2){    // if sample1 is not sample2 = defrost button on and defrost cycle immediately
     goto defrost;
   }
 lcd.clear();
 lcd.print("> 3 min safety <");
 lcd.setCursor(0,1);
 lcd.print(">delay starting<");
 delay(60);
 }

  sample3=digitalRead(def_switch);
  if (sample3==HIGH){
    time++;
    delay(1);
  }else{
    time=0;
  }
  if(time>3000){
    time=0;
    goto defrost;
  }
 
 eva_temp=analogRead(1); // 6k thermister + 10k
 volume=analogRead(2);   // 10k
 fre_temp=analogRead(3); // 6k thermister + 10k
 ref_temp=analogRead(4); // 6k thermister + 10k
 ft=fre_temp/12-54; //-18c stanrad
 rt=ref_temp/9-71; // 3c standard

 level=volume/7+383; // -22c min max -10c
 h=level+24;  // to avoid activate olp
 l=level-24;  // differencial 2 c start to 1.5c
compon=millis();
 if (h<fre_temp&&(compon-compoff>180000)){    //th4.273k + 10k = 431(1024-593) at -18c && more than 3 min
   digitalWrite(ry_comp,HIGH); //compressor on

 }
 else if (fre_temp<l){
   digitalWrite(ry_comp,LOW); //compressor off
   compoff=millis();  // last comp off
 }
  show_all=digitalRead(disclose);
  display_int=millis();
  if((display_int-last_display)>1000&&show_all==LOW){ // debug
 lcd.clear();
 lcd.print("FREEZER");
 lcd.setCursor(8,0);
 lcd.print(ft);
 lcd.print("c");
 lcd.setCursor(13,0);
 lcd.print(eva_temp);
 lcd.setCursor(0,1);
 lcd.print("FRIDGE");
 lcd.setCursor(9,1);
 lcd.print(rt);
 lcd.print("c");
 lcd.setCursor(13,1);
 lcd.print(level);
 last_display=display_int;
  }
 else if((display_int-last_display)>10000&&fre_temp>629){ // -1c over
    lcd.clear();
    lcd.print(" >> COOLING <<");
    lcd.setCursor(12,0);
    lcd.setCursor(0,1);
    lcd.print("Do not open door");
    last_display=display_int;
  }
  else if ((display_int-last_display)>10000&&fre_temp<=629){ // -1c less
 lcd.clear();
 lcd.print("FREEZER");
 lcd.setCursor(10,0);
 lcd.print(ft);
 lcd.print(" c ");
 lcd.setCursor(0,1);
 lcd.print("FRIDGE");
 lcd.setCursor(10,1);
 lcd.print(rt);
 lcd.print(" c");
 last_display=display_int;
  }

 curr_time=millis();
 if ((curr_time - last_def)>54000000&&eva_temp<629){ //15hours=1000x60x60x15&& -1c)
 defrost:

  digitalWrite(ry_comp,LOW);  //compressor off

   while (eva_temp<689){ // th4.844k + 10k = 689(1024-335) at 5c
    eva_temp=analogRead(1); // 6k thermister + 10k
    volume=analogRead(2);   // 10k
    fre_temp=analogRead(3); // 6k thermister + 10k
    ref_temp=analogRead(4); // 6k thermister + 10k
    ft=fre_temp/12-54; //-18c stanrad
    rt=ref_temp/9-71; // 3c standard
    level=volume/7+383; // -22c min max -10c
   show_all=digitalRead(disclose);
  if(show_all==LOW){ // debug
 lcd.clear();
 lcd.print("FREEZER");
 lcd.setCursor(8,0);
 lcd.print(ft);
 lcd.print("c");
 lcd.setCursor(13,0);
 lcd.print(eva_temp);
 lcd.setCursor(0,1);
 lcd.print("HEAT UP");
 lcd.setCursor(8,1);
 lcd.print("R");
 lcd.print(rt);
 lcd.print("c");
 lcd.setCursor(13,1);
 lcd.print(level);
 delay(1000);
  } else {
    lcd.clear();
  lcd.print(" - DEFROSTING -");
  lcd.setCursor(0,1);
  lcd.print("Do not open door");
  delay(1000);
  }
     digitalWrite(ry_heater,HIGH); //heater on till defrost temp 5c
   }
   digitalWrite(ry_heater,LOW);
     comp_interval=millis();
   while (millis()-comp_interval<=300000){ //5 min
     eva_temp=analogRead(1); // 6k thermister + 10k
     volume=analogRead(2);   // 10k
     fre_temp=analogRead(3); // 6k thermister + 10k
     ref_temp=analogRead(4); // 6k thermister + 10k
     ft=fre_temp/12-54; //-18c stanrad
     rt=ref_temp/9-71; // 3c standard
     level=volume/7+383; // -22c min max -10c
   show_all=digitalRead(disclose);
  if(show_all==LOW){ // debug
 lcd.clear();
 lcd.print("FREEZER");
 lcd.setCursor(8,0);
 lcd.print(ft);
 lcd.print("c");
 lcd.setCursor(13,0);
 lcd.print(eva_temp);
 lcd.setCursor(0,1);
 lcd.print("INTERVL");
 lcd.setCursor(8,1);
 lcd.print("R");
 lcd.print(rt);
 lcd.print("c");
 lcd.setCursor(13,1);
 lcd.print(level);
 delay(1000);
  } else {
    lcd.clear();
  lcd.print(" - DEFROSTING -");
  lcd.setCursor(0,1);
  lcd.print("Do not open door");
  delay(1000);
  }
   digitalWrite(ry_comp,LOW);
   }


  last_def=curr_time;
   }
}

*not to say, all risk at yourself.

0 件のコメント:

コメントを投稿