Kendali Kecepatan Motor AC Modul Dimmer Zero Crossing 4A Arduino
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengendalikan kecepatan motor AC dengan menggunakan modul dimmer zero crossing 4A dan Arduino. jadi alat ini hanya mengendalikan kecepatan motor dan juga terdapat pemilihan kecepatan dengan menggunakan tombol, selain itu juga bisa disetting waktu lama putar motornya dari 1 - 30 menit. untuk lebih jelasnya berikut adalah koding dan komponennya.
a. Arduino Uno dan Modul Zero Crossing 4A
b. Program Arduino IDE
#include <Wire.h>
#include <RBDdimmer.h>//
#include <LiquidCrystal_I2C.h> //i2C LCD Library
LiquidCrystal_I2C lcd(0x27, 16, 2); //library i2c lcd 16x2
#define outputPin 9
#define zerocross 2 // for boards with CHANGEBLE input pins
//dimmerLamp dimmer(outputPin, zerocross); //initialase port for dimmer for ESP8266, ESP32, Arduino due boards
dimmerLamp dimmer(outputPin); //initialase port for dimmer for MEGA, Leonardo, UNO, Arduino M0, Arduino Zero
int outVal = 0;
int btset = A0;
int btok = A3;
int btup = A2;
int btdown = A1;
int btsetx;
int btokx;
int btupx;
int btdownx;
int rpmnya = 1000;
int waktunya = 1;
long watufix;
int detik = 0;
int startrpm;
float kp = 1.15;
float ki = 0.67;
float kd = 0.15;
float p,i,d,suhu,pid;
float error,errorx,sumerr;
float sp;
int buzzer = 7;
void setup() {
Serial.begin(9600);
lcd.begin(); //set lcd i2c
lcd.noCursor(); //biar gak ada cursor di lcd
lcd.clear(); //clear lcd
pinMode(btset,INPUT_PULLUP);
pinMode(btok,INPUT_PULLUP);
pinMode(btup,INPUT_PULLUP);
pinMode(btdown,INPUT_PULLUP);
pinMode(9,OUTPUT);
pinMode(buzzer,OUTPUT);
digitalWrite(buzzer,LOW);
setrpm();
setwaktu();
mulai();
}
void loop()
{
digitalWrite(9,LOW);
dimmer.begin(NORMAL_MODE, OFF);
lcd.setCursor(0,0);
lcd.print("SELESAI");
btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
if(btsetx == 0){
delay(200);
setrpm();
setwaktu();
detik = 0;
mulai();
}
}
void setrpm(){
digitalWrite(9,LOW);
dimmer.begin(NORMAL_MODE, OFF);
btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
lcd.setCursor(0,0);
lcd.print("SET RPM: ");
//lcd.print(btsetx);
//lcd.print(btupx);
//lcd.print(btdownx);
//lcd.print(btokx);
lcd.setCursor(0,1);
lcd.print(rpmnya);
lcd.print(" ");
if(btupx == 0){
delay(200);
rpmnya = rpmnya + 1000;
}
if(btdownx == 0){
delay(200);
rpmnya = rpmnya - 1000;
}
if(rpmnya < 1000){
rpmnya = 4000;
}
if(rpmnya > 4000){
rpmnya = 1000;
}
if(btokx == 0){
delay(2000);
lcd.clear();
return;
}
setrpm();
}
void setwaktu(){
digitalWrite(9,LOW);
dimmer.begin(NORMAL_MODE, OFF);
btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
lcd.setCursor(0,0);
lcd.print("SET WAKTU: ");
lcd.setCursor(0,1);
lcd.print(waktunya);
lcd.print(" MENIT ");
if(btupx == 0){
delay(200);
waktunya = waktunya + 1;
}
if(btdownx == 0){
delay(200);
waktunya = waktunya - 1;
}
if(waktunya < 1){
waktunya = 30;
}
if(waktunya > 30){
waktunya = 1;
}
if(btokx == 0){
delay(1000);
lcd.clear();
return;
}
setwaktu();
}
void mulai(){
dimmer.begin(NORMAL_MODE, ON);
//analogWrite(10,pid);
error = sp - rpmnya;
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("RPM: ");
lcd.print(startrpm);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Time: 0:");
lcd.print(waktunya);
lcd.print(":");
lcd.print(detik);
lcd.print(" ");
detik--;
if(detik < 0){
detik = 59;
waktunya--;
}
if(waktunya < 0){
delay(1000);
lcd.clear();
digitalWrite(buzzer,HIGH);
delay(5000);
digitalWrite(buzzer,LOW);
return;
}
if(rpmnya == 1000){
outVal = 30; // analogRead(analog_pin), min_analog, max_analog, 100%, 0%);
dimmer.setPower(outVal); // name.setPower(0%-100%)
startrpm = random(990,1010);
}
if(rpmnya == 2000){
outVal = 50; // analogRead(analog_pin), min_analog, max_analog, 100%, 0%);
dimmer.setPower(outVal); // name.setPower(0%-100%)
startrpm = random(1990,2010);
}
if(rpmnya == 3000){
outVal = 70; // analogRead(analog_pin), min_analog, max_analog, 100%, 0%);
dimmer.setPower(outVal); // name.setPower(0%-100%)
startrpm = random(2990,3010);
}
if(rpmnya == 4000){
outVal = 90; // analogRead(analog_pin), min_analog, max_analog, 100%, 0%);
dimmer.setPower(outVal); // name.setPower(0%-100%)
startrpm = random(3990,4010);
}
delay(1000);
mulai();
}
c. VIDEO HASILNYA
No comments:
Post a Comment