Translate

Alat Kendali Dimmer dan Timer Interface LCD TFT

Alat Kendali Dimmer dan Timer Interface LCD TFT



       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang menggunakan dimmer modul dan timer sebagi fitur utamanya. interface menggunakan LCD TFT dan terdapat pula fitur EEprom sehingga data tidak hilang ketika di simpan. untuk lebih jelasnya berikut adalah koding dan komponennya.


1. Modul Dimmer



2. Program Arduino IDE

#include "SPI.h"
#include <Adafruit_GFX.h>
#include <ILI9488.h>
#include <max6675.h>   
#include <RBDdimmer.h>
#include <EEPROM.h>

#define TFT_CS         10
#define TFT_DC         8
//#define TFT_LED      5v
#define TFT_RST        9
#define TFT_MOSI       11
#define TFT_CLK        13
#define TFT_MISO       12

ILI9488 tft = ILI9488(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

int addr1 = 0;
int addr2 = 1;
int addr3 = 2;
int addr4 = 3;
int addr5 = 4;

int timerinfusion;
int ssr1 = 30;
int ssr2 = 31;

#define outputPin  7 
#define zerocross  2 // for boards with CHANGEBLE input pins

dimmerLamp dimmer(outputPin); //initialase port for dimmer for MEGA, Leonardo, UNO, Arduino M0, Arduino Zero

int waktu = 10;

int thermoDO1 = 16; //bisa juga S0
int thermoCS1 = 15;
int thermoCLK1 = 14; //bisa juga SCK
MAX6675 thermocouple1(thermoCLK1, thermoCS1, thermoDO1);

int thermoDO2 = 19; //bisa juga S0
int thermoCS2 = 18;
int thermoCLK2 = 17; //bisa juga SCK
MAX6675 thermocouple2(thermoCLK2, thermoCS2, thermoDO2);

int thermoDO3 = 22; //bisa juga S0
int thermoCS3 = 21;
int thermoCLK3 = 20; //bisa juga SCK
MAX6675 thermocouple3(thermoCLK3, thermoCS3, thermoDO3);

int x1 = 0;
int y1 = 150;
int x2 = 500;
int y2 = 150;
int suhu1, suhu2, suhu3;

int btset = A0;
int btup = A1;
int btdown = A2;
int btok = A3;

int bton1 = A4;
int btoff1 = A5;
int bton2 = A6;
int btoff2 = A7;

int btsetx;
int btupx;
int btdownx;
int btokx;

int bton1x;
int btoff1x;
int bton2x;
int btoff2x;

int cacah;

int timepreheat1;
int pwm1;
int pwm2;
int sp1;
int sp2;
int convpwm;

unsigned long start;

  
void setup() {

timepreheat1 = EEPROM.read(addr1);
pwm1 = EEPROM.read(addr2);
pwm2 = EEPROM.read(addr3);
sp1 = EEPROM.read(addr4);
sp2 = EEPROM.read(addr5);
  
  Serial.begin(9600);
  pinMode(6,OUTPUT); 
  pinMode(7,OUTPUT); 
  pinMode(ssr1,OUTPUT);
  pinMode(ssr2,OUTPUT);
  pinMode(btset,INPUT_PULLUP);
  pinMode(btup,INPUT_PULLUP);
  pinMode(btdown,INPUT_PULLUP);
  pinMode(btok,INPUT_PULLUP);

  pinMode(bton1,INPUT_PULLUP);
  pinMode(btoff1,INPUT_PULLUP);
  pinMode(bton2,INPUT_PULLUP);
  pinMode(btoff2,INPUT_PULLUP);
  
  tft.begin();
  tft.fillScreen(ILI9488_BLACK);
  tft.setRotation(1);
  tft.setTextSize(2);
  
delay(500);
}


void loop() {

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

bton1x = digitalRead(bton1);
btoff1x = digitalRead(btoff1);
bton2x = digitalRead(bton2);
btoff2x = digitalRead(btoff2);

if(bton1x == 0){
  delay(1);
  tft.fillScreen(ILI9488_BLACK);
  mulai1();
}

if(bton2x == 0){
  delay(1);
  tft.fillScreen(ILI9488_BLACK);
  mulai2();
}

if(btsetx == 0){
  delay(1);
  cacah++;
}

if(btokx == 0){
  delay(1);
  cacah--;
}

if(cacah > 4){
  cacah = 0;
}

if(cacah < 0){
  cacah = 0;
}
 
  suhu1 = thermocouple1.readCelsius();
  suhu2 = thermocouple2.readCelsius();
  suhu3 = thermocouple3.readCelsius();
  
  tft.setCursor(5, 10);
  tft.setTextColor(ILI9488_YELLOW,ILI9488_BLACK);  
  tft.print("Suhu1: ");  
  tft.print(suhu1);  
  tft.print(" C ");  

  tft.setCursor(5, 40);
  tft.setTextColor(ILI9488_YELLOW,ILI9488_BLACK);  
  tft.print("Suhu2: ");
  tft.print(suhu2);    
  tft.print(" C ");  

  tft.setCursor(5, 70);
  tft.setTextColor(ILI9488_YELLOW,ILI9488_BLACK);  
  tft.print("Suhu3: ");
  tft.print(suhu3);    
  tft.print(" C ");  

  if(cacah == 0){
  EEPROM.write(addr1, timepreheat1);
  timerinfusion = timepreheat1;
  if(btupx == 0){
    delay(1);
    timepreheat1 = timepreheat1 + 1; 
  }

  if(btdownx == 0){
    delay(1);
    timepreheat1 = timepreheat1 - 1; 
  }
      
  tft.setCursor(5, 120);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("-> Time Pre Infusion: ");
  tft.print(timepreheat1);    
  tft.print("     "); 
 
  tft.setCursor(5, 150);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("PWM 1: ");
  tft.print(pwm1);    
  tft.print("      "); 

  tft.setCursor(5, 180);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("PWM 2: ");
  tft.print(pwm2);    
  tft.print("      ");

  tft.setCursor(5, 210);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("SP SUHU1: ");
  tft.print(sp1);    
  tft.print("      "); 

  tft.setCursor(5, 240);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("SP SUHU2: ");
  tft.print(sp2);    
  tft.print("      ");
  
  }


  if(cacah == 1){
  EEPROM.write(addr2, pwm1);
  if(btupx == 0){
    delay(1);
    pwm1 = pwm1 + 1; 
  }

  if(btdownx == 0){
    delay(1);
    pwm1 = pwm1 - 1;; 
  }
      
  tft.setCursor(5, 120);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("Time Pre Infusion: ");
  tft.print(timepreheat1);    
  tft.print("     "); 
 
  tft.setCursor(5, 150);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("-> PWM 1: ");
  tft.print(pwm1);    
  tft.print("      "); 

  tft.setCursor(5, 180);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("PWM 2: ");
  tft.print(pwm2);    
  tft.print("      ");

  tft.setCursor(5, 210);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("SP SUHU1: ");
  tft.print(sp1);    
  tft.print("      "); 

  tft.setCursor(5, 240);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("SP SUHU2: ");
  tft.print(sp2);    
  tft.print("      ");
  }


  if(cacah == 2){
  EEPROM.write(addr3, pwm2);
  if(btupx == 0){
    delay(1);
    pwm2 = pwm2 + 1;  
  }

  if(btdownx == 0){
    delay(1);
    pwm2 = pwm2 - 1;  
  }
      
  tft.setCursor(5, 120);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("Time Pre Infusion: ");
  tft.print(timepreheat1);    
  tft.print("     "); 
 
  tft.setCursor(5, 150);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("PWM 1: ");
  tft.print(pwm1);    
  tft.print("      "); 

  tft.setCursor(5, 180);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("-> PWM 2: ");
  tft.print(pwm2);    
  tft.print("      ");

  tft.setCursor(5, 210);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("SP SUHU1: ");
  tft.print(sp1);    
  tft.print("      "); 

  tft.setCursor(5, 240);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("SP SUHU2: ");
  tft.print(sp2);    
  tft.print("      ");
  }

  if(cacah == 3){
  EEPROM.write(addr4, sp1);
  if(btupx == 0){
    delay(1);
    sp1 = sp1 + 1;  
  }

  if(btdownx == 0){
    delay(1);
    sp1 = sp1 - 1;  
  }

      
  tft.setCursor(5, 120);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("Time Pre Infusion: ");
  tft.print(timepreheat1);    
  tft.print("     "); 
 
  tft.setCursor(5, 150);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("PWM 1: ");
  tft.print(pwm1);    
  tft.print("      "); 

  tft.setCursor(5, 180);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("PWM 2: ");
  tft.print(pwm2);    
  tft.print("      ");

  tft.setCursor(5, 210);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("-> SP SUHU1: ");
  tft.print(sp1);    
  tft.print("      "); 

  tft.setCursor(5, 240);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("SP SUHU2: ");
  tft.print(sp2);    
  tft.print("      ");
  }


  if(cacah == 4){
  EEPROM.write(addr5, sp2);
  if(btupx == 0){
    delay(1);
    sp2 = sp2 + 1;  
  }

  if(btdownx == 0){
    delay(1);
    sp2 = sp2 - 1;  
  }
      
  tft.setCursor(5, 120);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("Time Pre Infusion: ");
  tft.print(timepreheat1);    
  tft.print("     "); 
 
  tft.setCursor(5, 150);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("PWM 1: ");
  tft.print(pwm1);    
  tft.print("      "); 

  tft.setCursor(5, 180);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("PWM 2: ");
  tft.print(pwm2);    
  tft.print("      ");

  tft.setCursor(5, 210);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("SP SUHU1: ");
  tft.print(sp1);    
  tft.print("      "); 

  tft.setCursor(5, 240);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("-> SP SUHU2: ");
  tft.print(sp2);    
  tft.print("      ");
  } 

delay(1);
 
}

void mulai1(){
dimmer.begin(NORMAL_MODE, ON); 

  suhu1 = thermocouple1.readCelsius();
  suhu2 = thermocouple2.readCelsius();
  suhu3 = thermocouple3.readCelsius();
  
  tft.setCursor(5, 10);
  tft.setTextColor(ILI9488_YELLOW,ILI9488_BLACK);  
  tft.print("Suhu1: ");  
  tft.print(suhu1);  
  tft.print(" C ");  

  tft.setCursor(5, 40);
  tft.setTextColor(ILI9488_YELLOW,ILI9488_BLACK);  
  tft.print("Suhu2: ");
  tft.print(suhu2);    
  tft.print(" C ");  

  tft.setCursor(5, 70);
  tft.setTextColor(ILI9488_YELLOW,ILI9488_BLACK);  
  tft.print("Suhu3: ");
  tft.print(suhu3);    
  tft.print(" C "); 

  tft.setCursor(5, 120);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("Time Pre Infusiom: ");
  tft.print(timerinfusion);    
  tft.print("     ");   
 
  tft.setCursor(5, 150);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("PWM 1: ");
  tft.print(pwm1);    
  tft.print("      ");

  tft.setCursor(5, 180);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("SP SUHU1: ");
  tft.print(sp1);    
  tft.print("      ");

  timerinfusion--;
  if(timerinfusion > 0){
  dimmer.setPower(20);
  }
  
  if(timerinfusion <= 0){
    timerinfusion = 0;
    dimmer.setPower(pwm1);
  }

  if(suhu1 > sp1){
    digitalWrite(ssr1,HIGH);
  }

  if(suhu1 < sp1){
    digitalWrite(ssr1,LOW);
  }  

delay(1000);
mulai1();  
}

void mulai2(){

bton1x = digitalRead(bton1);
btoff1x = digitalRead(btoff1);
bton2x = digitalRead(bton2);
btoff2x = digitalRead(btoff2);

if(btoff2x == 0){
  delay(1);
  analogWrite(6, 0);
  tft.fillScreen(ILI9488_BLACK);
  return;
}
  
convpwm = pwm2 * 2.55;

  suhu1 = thermocouple1.readCelsius();
  suhu2 = thermocouple2.readCelsius();
  suhu3 = thermocouple3.readCelsius();
  
  tft.setCursor(5, 10);
  tft.setTextColor(ILI9488_YELLOW,ILI9488_BLACK);  
  tft.print("Suhu1: ");  
  tft.print(suhu1);  
  tft.print(" C ");  

  tft.setCursor(5, 40);
  tft.setTextColor(ILI9488_YELLOW,ILI9488_BLACK);  
  tft.print("Suhu2: ");
  tft.print(suhu2);    
  tft.print(" C ");  

  tft.setCursor(5, 70);
  tft.setTextColor(ILI9488_YELLOW,ILI9488_BLACK);  
  tft.print("Suhu3: ");
  tft.print(suhu3);    
  tft.print(" C ");  
 
  tft.setCursor(5, 120);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("Time Pre Infusiom: ");
  tft.print(waktu);    
  tft.print("     "); 

  tft.setCursor(5, 150);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("PWM 2: ");
  tft.print(pwm2);    
  tft.print("      "); 

  tft.setCursor(5, 180);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("SP SUHU2: ");
  tft.print(sp2);    
  tft.print("      "); 

  if(waktu > 0){
  waktu--;
  analogWrite(6,50);
  }
  
  if(waktu <= 0){
    waktu = 0;
    analogWrite(6, convpwm);
  }

  if(suhu2 > sp2){
    digitalWrite(ssr2,HIGH);
  }

  if(suhu2 < sp2){
    digitalWrite(ssr2,LOW);
  }

delay(1000);
mulai2();  
}
 
 
3. VIDEO HASILNYA
 




No comments:

Post a Comment