2016年9月24日土曜日

arduino uno control inverter control fridge sketch.

#include <LiquidCrystal.h>

LiquidCrystal lcd(6,7,8,9,10,11); // comp relay =normalopen type
int eva_temp,fre_temp,ref_temp,volume,level,h1,h2,h3,l,ev,ft,last_ft=1,rt,sample1=0,sample2=0,sample3=0,time=0,show_all,t,s,leveltemp; // 実際のサーミスターとカップリング抵抗の位置と計算に気をつける、timeは強制霜取りボタンの長押し用
unsigned long curr_time,last_def,display_int,last_display,compon,compon1,compoff,comp_interval,temp_int,last_temp; //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);  //表示切り替え用ピン
 pinMode(def_switch,INPUT);
 last_def=millis();
 last_display=millis();
 last_temp=millis();
 compoff=millis();
}
void loop(){
 while (millis()<=3000){
   digitalWrite(ry_comp,LOW);
   lcd.print("  >> test <<"); // display "brand name"
   lcd.setCursor(0,1);
   lcd.print(" INVERTER MODEL"); // display "model number"
 }
 while (millis()<=180000){
   digitalWrite(ry_comp,LOW);  //3 min delay start compressor after reset
  display_int=millis();
  if((display_int-last_display)>1000){ // モニタイングの為 全てを表示 1秒毎 必要に応じて温度表示をパラメーターに変更
 lcd.clear();
 lcd.print("> 3 min safety <");
 lcd.setCursor(0,1);
 lcd.print(">delay starting<");
 last_display=display_int;
  }
 }
  sample3=digitalRead(def_switch); // 3sec push for defrost
  if (sample3==LOW){
    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
 leveltemp=level/12-54;
 h1=level+90;  // low speed +7.5c
 h2=level+102; // 2nd speed +8.5c
 h3=level+138; // 3rd speed +11.5c
 l=level-90;  // differencial -7.5c to start with 1.5c

compon=millis();
 if (h3<fre_temp&&(compon-compoff>180000)){      // h3以上の温度で尚且つ前回コンプレッサー停止後3分経過している。
 digitalWrite(ry_comp,HIGH); // コンプレッサーが回るときはいつでもfan motorを回転させる為にry_compのリレーはON

  t=87;
  tone(13,t);
    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
    leveltemp=level/12-54;
    h1=level+90;  // low speed +7.5c
    h2=level+102; // 2nd speed +8.5c
    h3=level+138; // 3rd speed +11.5c
    l=level-90;  // differencial -7.5c to start with 1.5c
  display_int=millis();
  if((display_int-last_display)>1000){                  // モニタイングの為 全てを表示 1秒毎 必要に応じて温度表示をパラメーターに変更
 lcd.clear();
 lcd.print(t);
 lcd.print("Hz/FR");
 lcd.setCursor(8,0);
 lcd.print(ft);
 lcd.print("c");
 lcd.setCursor(13,0);
 lcd.print(eva_temp);
 lcd.setCursor(0,1);
 lcd.print("h3");
 lcd.setCursor(4,1);
 lcd.print(h3);

 lcd.setCursor(9,1);
 lcd.print(leveltemp);
 lcd.print("c");
 lcd.setCursor(13,1);
 lcd.print(level);
 last_display=display_int;
  }
 }
 compon=millis();
 if (h2<fre_temp&&fre_temp<=h3&&(compon-compoff>180000)){  
digitalWrite(ry_comp,HIGH);
  t=75;
  tone(13,t); // top speed
    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
    leveltemp=level/12-54;
    h1=level+90;  // +7.5c
    h2=level+102; // 2nd speed at +8.5c
    h3=level+138; // 3rd speed at +11.5c
    l=level-90;  // -7.5 c to start with 1.5c
  display_int=millis();
  if((display_int-last_display)>1000){                    // モニタイングの為 全てを表示 1秒毎 必要に応じて温度表示をパラメーターに変更
 lcd.clear();
 lcd.print(t);
 lcd.print("Hz/FR");
 lcd.setCursor(8,0);
 lcd.print(ft);
 lcd.print("c");
 lcd.setCursor(13,0);
 lcd.print(eva_temp);
 lcd.setCursor(0,1);
 lcd.print("h2");
 lcd.setCursor(4,1);
 lcd.print(h2);

 lcd.setCursor(9,1);
 lcd.print(leveltemp);
 lcd.print("c");
 lcd.setCursor(13,1);
 lcd.print(level);
 last_display=display_int;
  }
  }
  compon=millis();
  if (h1<fre_temp&&fre_temp<=h2&&(compon-compoff>180000)){  
  digitalWrite(ry_comp,HIGH);
  t=66;
  tone(13,t); // top speed
    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
    leveltemp=level/12-54;
    h1=level+90;  // +7.5c
    h2=level+102; // 2nd speed at 8.5c
    h3=level+138; // 3rd speed at 11.5c
    l=level-90;  // -7.5c to start with 1.5c
  display_int=millis();
  if((display_int-last_display)>1000){                    // モニタイングの為 全てを表示 1秒毎 必要に応じて温度表示をパラメーターに変更
 lcd.clear();
 lcd.print(t);
 lcd.print("Hz/FR");
 lcd.setCursor(8,0);
 lcd.print(ft);
 lcd.print("c");
 lcd.setCursor(13,0);
 lcd.print(eva_temp);
 lcd.setCursor(0,1);
 lcd.print("h1");
 lcd.setCursor(4,1);
 lcd.print(h1);

 lcd.setCursor(9,1);
 lcd.print(leveltemp);
 lcd.print("c");
 lcd.setCursor(13,1);
 lcd.print(level);
 last_display=display_int;
  }
   }
  if (l<fre_temp&&fre_temp<=h1){  
    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
    leveltemp=level/12-54;
    h1=level+90;  // +7.5c
    h2=level+102; // 2nd speed at 8.5c
    h3=level+138; // 3rd speed at 11.5c
    l=level-90;  // -7.5c to start with 1.5c
  display_int=millis();
  if((display_int-last_display)>1000){                    // モニタイングの為 全てを表示 1秒毎 必要に応じて温度表示をパラメーターに変更
 lcd.clear();
 lcd.print(t);
 lcd.print("Hz/FR");
 lcd.setCursor(8,0);
 lcd.print(ft);
 lcd.print("c");
 lcd.setCursor(13,0);
 lcd.print(eva_temp);
 lcd.setCursor(0,1);
 lcd.print("low < h1");
 lcd.setCursor(9,1);
 lcd.print(leveltemp);
 lcd.print("c");
 lcd.setCursor(13,1);
 lcd.print(level);
 last_display=display_int;
  }
   }
 
   if (fre_temp<=l){                                              // ftがl以下になったらコンプレッサーとファンモーターを停止
    digitalWrite(ry_comp,LOW);
    t=0;
    noTone(13);
    compoff=millis();
 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
    leveltemp=level/12-54;
    h1=level+90;  // +7.5c
    h2=level+102; // 2nd speed at 8.5c
    h3=level+138; // 3rd speed at 11.5c
    l=level-90;  // -7.5c to start with 1.5c
  display_int=millis();
  if((display_int-last_display)>1000){                    // モニタイングの為 全てを表示 1秒毎 必要に応じて温度表示をパラメーターに変更
 lcd.clear();
 lcd.print(t);
 lcd.print("Hz/FR");
 lcd.setCursor(8,0);
 lcd.print(ft);
 lcd.print("c");
 lcd.setCursor(13,0);
 lcd.print(eva_temp);
 lcd.setCursor(0,1);
 lcd.print("low");
 lcd.setCursor(4,1);
 lcd.print(l);

 lcd.setCursor(9,1);
 lcd.print(leveltemp);
 lcd.print("c");
 lcd.setCursor(13,1);
 lcd.print(level);
 last_display=display_int;
  }
  }

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

  digitalWrite(ry_comp,LOW);  //fan motor off
  noTone(13); // compressor stop signal
   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){ // 全てを表示
 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){ // 霜取り中の全てパラメーターを表示
 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); // fan motor off
   noTone(13);
   }


  last_def=curr_time;
   }
}

arduino uno control inverter control fridge

basic sequence is the same as mechanical model.
instead of compressor on and off. control send pulse(duty 50%:50%) to the drive to run high, middle and low.
to too high consume power too much but too low could not make cool enough to the setting.
at the same time, too low rpm could not stop the compressor.
 this sample data.
it should be decided by different condition of the load in side of fridge.

those Hz depends upon compressor manufacturers, cooping capacity and etc.,

inverter compressor running video was uploaded to youtube as "inverter compressor testing".


arduino uno control fridge setting(2)

fridge sequence(no frost);





















the most important point is defrosting(mechanical system).

2016年9月11日日曜日

arduino uno control fridge setting(1)

*for this modification, there is risk for serious damage to your body electric shock from power supply(ac100v-240v depends upon your countriy) so all risk by yourself when you do.

to start with, check original wiring diagram from the back side of fridge.
and pick up required wires from connector.
wire color should be indicated in schematic diagram by good brand fridge.



Pcb connecting wirings are also need to isolated from defrost heater.


 *if the sensor is not attached properly, fuse blow, defrost heater damaged or plastic around evaporator could be damaged or deformed.

fridge thermistor(sensor) and freezer thermistor should be located to the same as mechanical thermistor.

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.

2016年9月4日日曜日

mcu control fridge

the mechanical control for refrigerator is simple but well designed long time ago.

let's make mcu control for refrigerator with using arduino uno.
2 relays are required. one for compressor and the other for defrost heater.
the relay for compressor need 10A ac240/50-60hz.
running current is around 2A for compressor but motor load x cos 𝝓0.4-0.5 and considering inrush current, bigger capacity will be safer for better margin.

due to refrigerant behavior, we need some interval to run or stop compressor.

3 thermistors also are required, one for evaporator, and for freezer and refrigerator side.

not to say, one mechanical refrigerator to simulate.

if you simulate by yourself, take your own risk anyway.

i am not software engineer and my software is not good enough but can run the system.

for this software, i show you next.

2016年8月28日日曜日

mechanical control fridge

there are a lot of fridges in the world.
made by major brands, local make and import.
some % of electricity in house is consumed by those fridges.
it works 24 hours 365days.
we should minimize this consumtion.
we can not do much for muc control model but mechanical control fridge.

sequence of mechanical control fridge is as follows;-
compressor in side of fridge run to cool down in side and when the room temperature reaches the setting temperature of thermostat, compressor stops.
every 6-8 houses timer run the defrost heater to defrost on the evaporator coil and start to run compressor and so on.
flowchart and typical wiring diagram is as attached.


in case of electric control, you should consider pressure balance in refrigeration circuit otherwise overload protector of compressor trips off the compressor or fuse or circuit breaker trips off in the house.
if sequence is smooth, consumption of electricity is lower.

I huck my mechanical fridge to electric control and simulate and optimiaze sequence,
if you try it by yourself, it will be at your own risk and there will will be containing electric shock .

next  mcu control fridge simulate this mechanical control, which was well designed long time ago and will working now.