ALAT KENDALI SUHU / TEMPERATURE PANAS MENGGUNAKAN DIMMER DAN PID CONTROL
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa digunakan untuk mengendalikan suhu dengan menggunakan pid control untuk pengaturan panasnya. alat ini menggunakan modul dimmer dan servo untuk kendali pemanasnya. untuk lebih jelasnya berikut adalah komponen dan kodingnya.
a. Arduino Uno
b. Modul Dimmer
c. Sensor Thermocouple Tipe K dan Max6675
d. Program Arduino IDE
#include<Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <DS3231.h>
#include <max6675.h>
LiquidCrystal_I2C lcd(0x27, 16,2);
Servo myservo;
int thermoDO = 4; //bisa juga S0
int thermoCS = 5;
int thermoCLK = 6; //bisa juga SCK
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
DS3231 rtc(SDA, SCL);
Time t;
int btset = A0;
int btok = A1;
int btup = A2;
int btdown = A3;
int btsetx;
int btokx;
int btupx;
int btdownx;
float dataku;
int setpoint = 30;
int durasi = 1;
float kp = 1.15;
float ki = 0.67;
float kd = 0.15;
float p,i,d,suhu,pid;
float error,errorx,sumerr;
float sp;
//servo full on = 200;
//servo full off = 30;
void setup(){
lcd.clear();
lcd.begin();
lcd.noCursor();
Serial.begin(9600);
myservo.attach(9);
myservo.write(30);
rtc.begin();
//rtc.setDOW(FRIDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(0, 0, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(13, 5, 2022); // Set the date to January 1st, 2014
pinMode(btset,INPUT_PULLUP);
pinMode(btok,INPUT_PULLUP);
pinMode(btup,INPUT_PULLUP);
pinMode(btdown,INPUT_PULLUP);
delay(500);
}
void loop(){
btsetx = digitalRead(btset);
btokx = digitalRead(btok);
if(btsetx == 0){
delay(200);
lcd.clear();
menuset();
menujam();
}
if(btokx == 0){
delay(200);
lcd.clear();
rtc.setTime(0, 0, 0);
utama();
}
lcd.setCursor(0,0);
lcd.print("TEKAN MULAI");
lcd.setCursor(0,1);
lcd.print("SP/D= ");
lcd.print(setpoint);
lcd.print("/");
lcd.print(durasi);
lcd.print(" ");
delay(200);
}
void menuset(){
btsetx = digitalRead(btset);
btokx = digitalRead(btok);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
lcd.setCursor(0,0);
lcd.print("SP Suhu= ");
lcd.print(setpoint);
lcd.print(" ");
if(btupx == 0){
delay(200);
setpoint++;
}
if(btdownx == 0){
delay(200);
setpoint--;
}
if(btokx == 0){
lcd.clear();
delay(2000);
btokx = 1;
return;
}
if(setpoint > 1000){
setpoint = 0;
}
if(setpoint < 0){
setpoint = 1000;
}
menuset();
}
void menujam(){
btsetx = digitalRead(btset);
btokx = digitalRead(btok);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
lcd.setCursor(0,0);
lcd.print("Durasi= ");
lcd.print(durasi);
lcd.print(" jam ");
if(btupx == 0){
delay(200);
durasi++;
}
if(btdownx == 0){
delay(200);
durasi--;
}
if(btokx == 0){
lcd.clear();
delay(2000);
return;
}
if(durasi > 12){
durasi = 0;
}
if(durasi < 0){
durasi = 12;
}
menujam();
}
void utama(){
t = rtc.getTime();
dataku = thermocouple.readCelsius();
error = setpoint - dataku;
p = error * kp;
sumerr = error + errorx;
i = ki * sumerr;
d = kd * (error - errorx) ;
pid = p + i + d;
if(pid < 30){
pid = 30;
}
if(pid > 200){
pid = 200;
}
myservo.write(pid);
lcd.setCursor(0,0);
lcd.print("T/SP= ");
lcd.print(dataku);
lcd.print("/");
lcd.print(setpoint);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("D= ");
lcd.print(t.hour);
lcd.print(":");
lcd.print(t.min);
lcd.print(":");
lcd.print(t.sec);
lcd.print("/");
lcd.print(pid);
lcd.print(" ");
if(t.hour >= durasi){
lcd.clear();
delay(1000);
myservo.write(30);
return;
}
errorx = error;
delay(200);
utama();
}
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <DS3231.h>
#include <max6675.h>
LiquidCrystal_I2C lcd(0x27, 16,2);
Servo myservo;
int thermoDO = 4; //bisa juga S0
int thermoCS = 5;
int thermoCLK = 6; //bisa juga SCK
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
DS3231 rtc(SDA, SCL);
Time t;
int btset = A0;
int btok = A1;
int btup = A2;
int btdown = A3;
int btsetx;
int btokx;
int btupx;
int btdownx;
float dataku;
int setpoint = 30;
int durasi = 1;
float kp = 1.15;
float ki = 0.67;
float kd = 0.15;
float p,i,d,suhu,pid;
float error,errorx,sumerr;
float sp;
//servo full on = 200;
//servo full off = 30;
void setup(){
lcd.clear();
lcd.begin();
lcd.noCursor();
Serial.begin(9600);
myservo.attach(9);
myservo.write(30);
rtc.begin();
//rtc.setDOW(FRIDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(0, 0, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(13, 5, 2022); // Set the date to January 1st, 2014
pinMode(btset,INPUT_PULLUP);
pinMode(btok,INPUT_PULLUP);
pinMode(btup,INPUT_PULLUP);
pinMode(btdown,INPUT_PULLUP);
delay(500);
}
void loop(){
btsetx = digitalRead(btset);
btokx = digitalRead(btok);
if(btsetx == 0){
delay(200);
lcd.clear();
menuset();
menujam();
}
if(btokx == 0){
delay(200);
lcd.clear();
rtc.setTime(0, 0, 0);
utama();
}
lcd.setCursor(0,0);
lcd.print("TEKAN MULAI");
lcd.setCursor(0,1);
lcd.print("SP/D= ");
lcd.print(setpoint);
lcd.print("/");
lcd.print(durasi);
lcd.print(" ");
delay(200);
}
void menuset(){
btsetx = digitalRead(btset);
btokx = digitalRead(btok);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
lcd.setCursor(0,0);
lcd.print("SP Suhu= ");
lcd.print(setpoint);
lcd.print(" ");
if(btupx == 0){
delay(200);
setpoint++;
}
if(btdownx == 0){
delay(200);
setpoint--;
}
if(btokx == 0){
lcd.clear();
delay(2000);
btokx = 1;
return;
}
if(setpoint > 1000){
setpoint = 0;
}
if(setpoint < 0){
setpoint = 1000;
}
menuset();
}
void menujam(){
btsetx = digitalRead(btset);
btokx = digitalRead(btok);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
lcd.setCursor(0,0);
lcd.print("Durasi= ");
lcd.print(durasi);
lcd.print(" jam ");
if(btupx == 0){
delay(200);
durasi++;
}
if(btdownx == 0){
delay(200);
durasi--;
}
if(btokx == 0){
lcd.clear();
delay(2000);
return;
}
if(durasi > 12){
durasi = 0;
}
if(durasi < 0){
durasi = 12;
}
menujam();
}
void utama(){
t = rtc.getTime();
dataku = thermocouple.readCelsius();
error = setpoint - dataku;
p = error * kp;
sumerr = error + errorx;
i = ki * sumerr;
d = kd * (error - errorx) ;
pid = p + i + d;
if(pid < 30){
pid = 30;
}
if(pid > 200){
pid = 200;
}
myservo.write(pid);
lcd.setCursor(0,0);
lcd.print("T/SP= ");
lcd.print(dataku);
lcd.print("/");
lcd.print(setpoint);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("D= ");
lcd.print(t.hour);
lcd.print(":");
lcd.print(t.min);
lcd.print(":");
lcd.print(t.sec);
lcd.print("/");
lcd.print(pid);
lcd.print(" ");
if(t.hour >= durasi){
lcd.clear();
delay(1000);
myservo.write(30);
return;
}
errorx = error;
delay(200);
utama();
}
e. VIDEO HASILNYA
No comments:
Post a Comment