Kendali Oven dengan Metode PID dan IOT Blynk 2.0
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa dikendalikan dengan metode pid, alat ini yaitu oven listrik yang menggunakan tegangan 220 volt selain itu juga bisa dipantau menggunakan IOT Blynk karena menggunakan ESP32. untuk lebih jelasnya berikut adalah koding dan daftar komponennya.
1. Daftar komponen
- ESP32
- LCD 16x2 I2c
- SSR Modul
- Thermocouple Type K
- Elemen pemanas
2. Program Arduino IDE
#define BLYNK_TEMPLATE_ID "TMPL662sTjRVt"
#define BLYNK_TEMPLATE_NAME "oven pid"
#define BLYNK_AUTH_TOKEN "p0MGEqfrRkPDCDwNvZZszpA6-fvA9b5V"
#define BLYNK_PRINT Serial
#include <Wire.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <LiquidCrystal_I2C.h> //i2C LCD Library
#include <max6675.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int thermoDO = 19; //bisa juga S0
int thermoCS = 23; //bisa juga CS
int thermoCLK = 5; //bisa juga SCK
int ssr = 34;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
float kp = 2.08;
float ki = 1.67;
float kd = 2.15;
float p,i,d,suhu,pid;
float error,errorx,sumerr;
//set point = 95
float sp = 80.0;
BlynkTimer timer;
char ssid[] = "hotspothpku";
char pass[] = "123456789";
void sendSensor()
{
Blynk.virtualWrite(V0, suhu);
Blynk.virtualWrite(V1, pid);
delay(1000);
}
void setup() {
pinMode(ssr,OUTPUT);
Serial.begin(9600);
lcd.begin();
lcd.clear();
lcd.noCursor();
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(1000L, sendSensor);
// wait for MAX chip to stabilize
delay(500);
}
void loop() {
float suhu = thermocouple.readCelsius();
analogWrite(ssr,pid);
error = sp - suhu;
p = error * kp;
sumerr = error + errorx;
i = ki * sumerr;
d = error - errorx;
pid = p + i + d;
pid = 255.0 - pid;
if(pid < 1){
pid = 0;
}
lcd.setCursor(0,0);
lcd.print("Suhu: ");
lcd.print(suhu);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("PID: ");
lcd.print(pid);
lcd.print(" ");
Blynk.run();
timer.run();
delay(200);
errorx = error;
}
No comments:
Post a Comment