Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk mengendalikan suhu suatu benda dengan output yang dipakai adalah fan PC atau motor brushless, jadi alat ini seperti kendali fan saja yang mana menggunakan PID sebagai metodenya, semakin mendekati set point maka kipas akan semakin pelan dan jika sudah sampai set point maka kipas akan berhenti, alat ini memiliki beberapa buah parameter yaitu PV yang artinya suhu realtime sekarang, SV (Set Value) artinya batas set point yang diinginkan agar mencapai steady state, HYS (histerisis) artinya batas toleransi set point, akan ada batas atas dan ada batas bawah untuk toleransi, kemudian ada ONR yaitu nilai untuk menghidupkan relay atau mematikan relay. PWM artinya nilai PID atau duty cycle yang telah dikeluarkan oleh mikrokontroller untuk mengatur kecepatan fan. untuk lebih jelasnya berikut adalah skema dan programnya.
a. Arduino Uno
b. LCD Display 16x2
c. Sensor Suhu LM35
d. Transistor Driver Fan Brushless
e. Relay + Driver
f. Program Arduino IDE
#include "Wire.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int relay = 10;
int kipas = 9;
const int btset = A2;
const int btup = A3;
const int btdown = A2;
const int btok = A5;
int btsetx = 0;
int btupx = 0;
int btdownx = 0;
int btokx = 0;
float sv = 35;
float hys = 1;
float onrelay = 37;
int adcdat;
float simpansv = 35;
float simpanhys = 1;
float simpanonrelay = 37;
float kp = 1.85;
float ki = 1.67;
float kd = 1.15;
float batasatas;
float batasbawah;
float p,i,d,suhu,pid;
float error,errorx,sumerr;
void setup() {
lcd.begin(16, 2);
lcd.clear();
lcd.noCursor();
pinMode(relay,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(kipas,OUTPUT);
pinMode(btset,INPUT);
pinMode(btup,INPUT);
pinMode(btdown,INPUT);
pinMode(btok,INPUT);
digitalWrite(btset,HIGH);
digitalWrite(btup,HIGH);
digitalWrite(btdown,HIGH);
digitalWrite(btok,HIGH);
digitalWrite(A1,LOW);
}
void loop() {
btsetx = digitalRead(btset);
if(btsetx == 0){
delay(200);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("LOADING...");
delay(3000);
lcd.clear();
setting();
lcd.setCursor(0, 0);
lcd.print("LOADING...");
delay(3000);
lcd.clear();
settinghy();
lcd.setCursor(0, 0);
lcd.print("LOADING...");
delay(3000);
lcd.clear();
settingrelay();
lcd.clear();
}
error = batasatas - suhu;
p = error * kp;
sumerr = error + errorx;
i = ki * sumerr;
d = error - errorx;
pid = p + i + d;
if(pid < 1){
pid = 0;
}
adcdat = analogRead(0);
suhu = (adcdat * (5.0 / 1023.0)) * 100;
analogWrite(kipas,pid);
lcd.setCursor(0, 0);
lcd.print("PV=");
lcd.print(suhu,1);
lcd.setCursor(0, 1);
lcd.print("SV=");
lcd.print(simpansv,1);
lcd.setCursor(8, 0);
lcd.print("HYS=");
lcd.print(simpanhys,1);
lcd.setCursor(8, 1);
lcd.print("PWM=");
//lcd.print(simpanonrelay,1);
lcd.print(pid,1);
delay(200);
batasatas = simpansv + simpanhys;
batasbawah = simpansv - simpanhys;
if(suhu >= simpanonrelay){
digitalWrite(relay,HIGH);
}
if(suhu < simpanonrelay){
digitalWrite(relay,LOW);
}
errorx = error;
}
//======================================
void setting(){
lcd.setCursor(0, 0);
lcd.print("SETTING SV");
lcd.setCursor(0, 1);
lcd.print(sv);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
if(btupx == 0){
delay(200);
sv = sv + 0.5;
}
if(btdownx == 0){
delay(200);
sv = sv - 0.5;
}
if(btokx == 0){
delay(200);
lcd.clear();
simpansv = sv;
return;
}
setting();
}
void settinghy(){
lcd.setCursor(0, 0);
lcd.print("SETTING HYS");
lcd.setCursor(0, 1);
lcd.print(hys);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
if(btupx == 0){
delay(200);
hys = hys + 0.5;
}
if(btdownx == 0){
delay(200);
hys = hys - 0.5;
}
if(btokx == 0){
delay(200);
lcd.clear();
simpanhys = hys;
return;
}
settinghy();
}
void settingrelay(){
lcd.setCursor(0, 0);
lcd.print("SETTING ON RELAY");
lcd.setCursor(0, 1);
lcd.print(onrelay);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
if(btupx == 0){
delay(200);
onrelay = onrelay + 0.5;
}
if(btdownx == 0){
delay(200);
onrelay = onrelay - 0.5;
}
if(btokx == 0){
delay(200);
lcd.clear();
simpanonrelay = onrelay;
return;
}
settingrelay();
}
g. VIDEO HASILNYA
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int relay = 10;
int kipas = 9;
const int btset = A2;
const int btup = A3;
const int btdown = A2;
const int btok = A5;
int btsetx = 0;
int btupx = 0;
int btdownx = 0;
int btokx = 0;
float sv = 35;
float hys = 1;
float onrelay = 37;
int adcdat;
float simpansv = 35;
float simpanhys = 1;
float simpanonrelay = 37;
float kp = 1.85;
float ki = 1.67;
float kd = 1.15;
float batasatas;
float batasbawah;
float p,i,d,suhu,pid;
float error,errorx,sumerr;
void setup() {
lcd.begin(16, 2);
lcd.clear();
lcd.noCursor();
pinMode(relay,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(kipas,OUTPUT);
pinMode(btset,INPUT);
pinMode(btup,INPUT);
pinMode(btdown,INPUT);
pinMode(btok,INPUT);
digitalWrite(btset,HIGH);
digitalWrite(btup,HIGH);
digitalWrite(btdown,HIGH);
digitalWrite(btok,HIGH);
digitalWrite(A1,LOW);
}
void loop() {
btsetx = digitalRead(btset);
if(btsetx == 0){
delay(200);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("LOADING...");
delay(3000);
lcd.clear();
setting();
lcd.setCursor(0, 0);
lcd.print("LOADING...");
delay(3000);
lcd.clear();
settinghy();
lcd.setCursor(0, 0);
lcd.print("LOADING...");
delay(3000);
lcd.clear();
settingrelay();
lcd.clear();
}
error = batasatas - suhu;
p = error * kp;
sumerr = error + errorx;
i = ki * sumerr;
d = error - errorx;
pid = p + i + d;
if(pid < 1){
pid = 0;
}
adcdat = analogRead(0);
suhu = (adcdat * (5.0 / 1023.0)) * 100;
analogWrite(kipas,pid);
lcd.setCursor(0, 0);
lcd.print("PV=");
lcd.print(suhu,1);
lcd.setCursor(0, 1);
lcd.print("SV=");
lcd.print(simpansv,1);
lcd.setCursor(8, 0);
lcd.print("HYS=");
lcd.print(simpanhys,1);
lcd.setCursor(8, 1);
lcd.print("PWM=");
//lcd.print(simpanonrelay,1);
lcd.print(pid,1);
delay(200);
batasatas = simpansv + simpanhys;
batasbawah = simpansv - simpanhys;
if(suhu >= simpanonrelay){
digitalWrite(relay,HIGH);
}
if(suhu < simpanonrelay){
digitalWrite(relay,LOW);
}
errorx = error;
}
//======================================
void setting(){
lcd.setCursor(0, 0);
lcd.print("SETTING SV");
lcd.setCursor(0, 1);
lcd.print(sv);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
if(btupx == 0){
delay(200);
sv = sv + 0.5;
}
if(btdownx == 0){
delay(200);
sv = sv - 0.5;
}
if(btokx == 0){
delay(200);
lcd.clear();
simpansv = sv;
return;
}
setting();
}
void settinghy(){
lcd.setCursor(0, 0);
lcd.print("SETTING HYS");
lcd.setCursor(0, 1);
lcd.print(hys);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
if(btupx == 0){
delay(200);
hys = hys + 0.5;
}
if(btdownx == 0){
delay(200);
hys = hys - 0.5;
}
if(btokx == 0){
delay(200);
lcd.clear();
simpanhys = hys;
return;
}
settinghy();
}
void settingrelay(){
lcd.setCursor(0, 0);
lcd.print("SETTING ON RELAY");
lcd.setCursor(0, 1);
lcd.print(onrelay);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
if(btupx == 0){
delay(200);
onrelay = onrelay + 0.5;
}
if(btdownx == 0){
delay(200);
onrelay = onrelay - 0.5;
}
if(btokx == 0){
delay(200);
lcd.clear();
simpanonrelay = onrelay;
return;
}
settingrelay();
}
g. VIDEO HASILNYA