Translate

KENDALI PANAS DINGIN PELTIER CONTROL PID

KENDALI PANAS DINGIN PELTIER CONTROL PID
 

         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengendalikan panas dan dingin suhu peltier dengan menggunakan PID control. jadi ada 2 buah peltier yang difungsikan untuk panas dan satunya untuk dingin. untuk lebih jelasnya berikut adalah komponen dan kodingnya.
 
 
a. Komponen
 

 
 
b. Program Arduino IDE
 
#include <Wire.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <DS3231.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#define ONE_WIRE_BUS 7  

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DS3231  rtc(SDA, SCL);

float temppanas;
float tempdingin;

int inpanas1 = 5;
int inpanas2 = 4;
int indingin1 = 3;
int indingin2 = 2;
int pwmpanas = 10;
int pwmdingin = 9;

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

int btsetx;
int btupx;
int btdownx;
int btokx;
Time  t;
float kp = 2.15;
float ki = 2.67;
float kd = 2.15;

float p,i,d,suhu,pid;
float error,errorx,sumerr;
float sp = 0;

void setup()
{

rtc.begin();
rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAmy
rtc.setTime(0, 0, 0);     // Set the time to 12:00:00 (24hr format)
rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014

  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();  
  pinMode(buzzer,OUTPUT);
  pinMode(btset,INPUT_PULLUP);
  pinMode(btup,INPUT_PULLUP);
  pinMode(btdown,INPUT_PULLUP);
  pinMode(btok,INPUT_PULLUP);
 
  pinMode(inpanas1,OUTPUT);
  pinMode(inpanas2,OUTPUT);
  pinMode(indingin1,OUTPUT);
  pinMode(indingin2,OUTPUT);
  pinMode(pwmpanas,OUTPUT);
  pinMode(pwmdingin,OUTPUT);

  settingsp();
}

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

 lcd.setCursor(0,0);
 lcd.print("TEKAN START ");

if(btsetx == 0){
 lcd.clear();
 delay(2000);  
 settingsp();
}

if(btokx == 0){
 lcd.clear();
 delay(2000);  
 rtc.setTime(0, 0, 0);
 proses();
}

}

void settingsp(){

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

 lcd.setCursor(0,0);
 lcd.print("SP= ");
 lcd.print(sp);
 lcd.print("  ");

 if(btupx == 0){
 delay(200);  
 sp++;
 }

 if(btdownx == 0){
 delay(200);  
 sp--;
 }  

 if(btokx == 0){
 delay(200);
 lcd.clear();  
 return;
 }  
 
settingsp();  
}


void proses(){
 t = rtc.getTime();
 
  sensors.requestTemperatures();
  tempdingin = sensors.getTempCByIndex(0);
  temppanas = sensors.getTempCByIndex(1);
 
  error = sp - temppanas;
  p = error * kp;
  sumerr = error + errorx;
  i = ki * sumerr;
  d = kd * (error - errorx);
  pid = p + i + d;

  if(pid < 1){
  pid = 0;
  }
 
  if(pid > 255){
  pid = 255;
  }
 
 lcd.setCursor(0,0);
 lcd.print("T1/2= ");
 lcd.print(tempdingin,1);
 lcd.print("/");
 lcd.print(temppanas,1);
 lcd.print("  ");

 lcd.setCursor(0,1);
 lcd.print("PID= ");
 lcd.print(pid,1);
 lcd.print("  ");

 digitalWrite(inpanas1,HIGH);
 digitalWrite(inpanas2,LOW);
 digitalWrite(indingin1,HIGH);
 digitalWrite(indingin2,LOW);
 analogWrite(pwmpanas,pid);
 analogWrite(pwmdingin,255);

if(t.min == 5){
lcd.clear();
digitalWrite(buzzer,HIGH);
delay(2000);
digitalWrite(buzzer,LOW);
return;  
}
      
delay(200);
proses();  
}


 
c. VIDEO HASILNYA
 

 

No comments:

Post a Comment