Translate

Kendali Kecepatan Motor AC Modul Dimmer Zero Crossing 4A Arduino

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







Monitor Kemiringan Menggunakan IP Local Sensor GY-521 (MPU-6050)

Monitor Kemiringan Menggunakan IP Local Sensor GY-521 (MPU-6050) 

         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur tingkat kemiringan suatu dataran atau benda dengan menggunakan sensor GY-521 / MPU-6050 dan mikrokontroller yang dipakai yaitu wemos D1 mini. alat ini bisa memonitor tingkat kemiringan dengan menggunakan IP Address local sehingga membutuhkan suatu router sebagai medianya pengiriman sinyalnya dikarenakan menggunakan wifi. untuk lebih jelasnya berikut adalah komponen dan kodingnya.


a. Komponen

 

b. Program Arduino IDE

#include<Wire.h>
#include <ESP8266WiFi.h>
#include <EEPROM.h>

const char *ssid = "TP-Link_65A4"; // Enter your WiFi name
const char *password = "";  // Enter WiFi password

//int ledPin = D0;
WiFiServer server(80);

//I2C Address for MPU6050
const int MPU=0x68;  // Can be 0x69 if AD0 Pin is True (VCC)

//Variables for raw values from MPU ADC
int AcX,AcY,AcZ,GyX,GyY,GyZ;
int16_t Tmp;

int minVal=0;
int maxVal=65536; //2^16 levels from MPU6050 ADC

int offsetTemp = 35; // from MPU datasheet
int offsetTempLevels = 521; // from MPU datasheet

void setup() {
 
  Serial.begin(9600); // Begin Serial communication
  Wire.begin();
  Wire.beginTransmission(MPU); // begin transmission with MPU address
  Wire.write(0x6B);
   
  //Start MPU-6050 sensor
  Wire.write(0);
  Wire.endTransmission(true);    

  delay(10);

//  pinMode(ledPin, OUTPUT);
//  digitalWrite(ledPin, LOW);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");

}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }

  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

 Wire.beginTransmission(MPU);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  //Get data from Sensor (14 consecutive bytes)
  Wire.requestFrom(MPU,14,true);  
  //Read data byte by byte (16 bits is 8 bits | 8 bits)
  //Each value is composed by 16 bits (2 bytes)
  GyX=Wire.read()<<8|Wire.read();  //0x3B (GYRO_XOUT_H) & 0x3C (GYRO_XOUT_L)     
  GyY=Wire.read()<<8|Wire.read();  //0x3D (GYRO_YOUT_H) & 0x3E (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  //0x3F (GYRO_ZOUT_H) & 0x40 (GYRO_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  //0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  AcX=Wire.read()<<8|Wire.read();  //0x43 (ACCEL_XOUT_H) & 0x44 (ACCEL_XOUT_L)
  AcY=Wire.read()<<8|Wire.read();  //0x45 (ACCEL_YOUT_H) & 0x46 (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  //0x47 (ACCEL_ZOUT_H) & 0x48 (ACCEL_ZOUT_L)

  //Adapts to range from 0 to 2000 m/s^2
  AcX = map(AcX,minVal,maxVal,2000,0);
  AcY = map(AcY,minVal,maxVal,2000,0);
  AcZ = map(AcZ,minVal,maxVal,2000,0);
 
  //Adapts to range from -180º to 180º
  int xAng = map(GyX,minVal,maxVal,180,-180);
  int yAng = map(GyY,minVal,maxVal,180,-180);
  int zAng = map(GyZ,minVal,maxVal,180,-180);
   
  //Send X axis accelerometer value for serial monitor
  Serial.print("AcX = "); Serial.print(AcX);
   
  //Send Y axis accelerometer value for serial monitor
  Serial.print(" | AcY = "); Serial.print(AcY);

  //Send Z axis accelerometer value for serial monitor
  Serial.print(" | AcZ = "); Serial.print(AcZ);


  //Send Temperature value for serial
  //Calculates the temperature given the datasheet values (ºC)
  // 340 is the number of levels per ºC (from datasheet)
  Serial.print(" | Tmp = "); Serial.print(float(Tmp + offsetTempLevels)/340 + offsetTemp);   
  //Send X axis gyroscope angle value for serial monitor
  Serial.print(" | GyX = "); Serial.print(xAng);   
  //Send Y axis gyroscope angle value for serial monitor  
  Serial.print(" | GyY = "); Serial.print(yAng);   
  //Send Z axis gyroscope angle value for serial monitor
  Serial.print(" | GyZ = "); Serial.println(zAng);
 
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println("Refresh: 1");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
   
  client.println("<center>");
  client.println("<h1>");
  client.println("Monitoring Kemiringan");
  client.println("</h1>");
   
  client.println("<h3>");
   
  client.println("X = ");
  client.println(AcX);
  client.println("<br>");
 
  client.println("Y = ");
  client.println(AcY);
  client.println("<br>");
 
  client.println("Z = ");
  client.println(AcZ);
  client.println("<br>");
 
  client.println("</h3>");
  client.println("<a href = \"/?lighton\"\"><input type = 'button' value = 'DATA LOGGER' ></a>");
  client.println("<a href=" " download>");  
  client.println("</center>");
  client.println("</html>");

  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");

  delay(300);

}


c. VIDEO HASILNYA


Monitor DAYA (Arus Tegangan) AC dan DC Thingspeak + Monitor Android

Monitor DAYA (Arus Tegangan) AC dan DC Thingspeak + Monitor Android


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur 6 buah parameter yaitu tegangan AC, arus AC, Daya AC, Tegangan DC, Arus DC dan Daya DC. data tersebut dikirimkan ke server thingspeak lalu akan dibaca oleh aplikasi android. untuk lebih jelasnya berikut adalah koding dan komponennya.

 

a. Nodemcu ESP8266


b. Sensor INA219


c. Sensor PZEM-004T


d. Sensor DC Voltage


 

e. Aplikasi Android

Note: pada bagian LINK tuliskan seperti berikut ini dan sesuai dengan ID thingspeak dan ID Write apikey pada website / akun thingspeak Anda. yang berwarna merah adalah ID akun thingspeak dan warna biru adalah ID Write apikey.

https://api.thingspeak.com/channels/1223445/feeds/last.json?api_key=5TGHLW6HZUPQH2TF

  

 


f. Program Arduino IDE

#include <Wire.h>
#include <ThingSpeak.h>
#include <ESP8266WiFi.h>
#include <Adafruit_INA219.h>
#include <SoftwareSerial.h>
#include <PZEM004Tv30.h>
 
PZEM004Tv30 pzem(D7,D8);  // D6, D5, (RX,TX) connect to TX,RX of PZEM

float busVoltage = 0;
float arusac = 0; // Measure in milli amps
float dayaac = 0;
float vac;
float arusdc;
float dayadc;
float vdc;
int adcteg;
float tegangan;
float voltage;
float current;
float power;
 
Adafruit_INA219 sensor219; // Declare and instance of INA219

WiFiClient client;
// ThingSpeak Settings
String apiKey = "5TGHLW6HZUPQH2TF";
const char *ssid = "hotspothpku";
const char *pass = "123456789";
const char* server = "api.thingspeak.com";
const char* resource = "/update?api_key=";

 
void setup() {
  Serial.begin(9600);
  sensor219.begin();

  //setting ke online
  Serial.println("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED){\
    delay(200);
    Serial.println(".");
    }
  Serial.println("");
  Serial.println("WiFi connected");
 
}
 
void loop() {
 
    voltage = pzem.voltage();
    current = pzem.current();
    power = pzem.power();

    sensor219.begin();
    busVoltage = sensor219.getBusVoltage_V();
    arusdc = sensor219.getCurrent_mA();
    arusdc = arusdc /1000.0;
    //dayadc = busVoltage * (arusdc/1000);
    
    adcteg = analogRead(A0);
    tegangan = (adcteg * (5.0 / 1023.0) * 4.8) - 2.58;
    dayadc = tegangan * arusdc;
    
    Serial.print("VoltageAC: ");      Serial.print(voltage);          Serial.println("V");
    Serial.print("CurrentAC: ");      Serial.print(current);      Serial.println("A");
    Serial.print("PowerAC: ");        Serial.print(power);        Serial.println("W");
    Serial.print("busVoltage: ");     Serial.print(busVoltage);      Serial.println("V");
    Serial.print("VoltageDC: ");      Serial.print(tegangan);      Serial.println("V");    
    Serial.print("CurrentDC: ");      Serial.print(arusdc);      Serial.println("mA");
    Serial.print("PowerDC: ");        Serial.print(dayadc);        Serial.println("W");

 if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
 
                      {
                           
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(voltage);
                             postStr += "\r\n\r\n";

                             client.print(String("GET ") + resource + apiKey + "&field1=" + voltage + "&field2=" + current + "&field3=" + power + "&field4=" + tegangan + "&field5=" + arusdc + "&field6=" + dayadc + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
                                       
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);
                         
                             Serial.println(". Send to Thingspeak.");
                        }
                       
          client.stop();

          Serial.println("Waiting...");
 
  // thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
  delay(10000);

}



g. VIDEO HASILNYA


Monitor Tegangan Arus AC Sensor PZEM-004T NODEMCU ESP8266

Monitor Tegangan Arus AC Sensor PZEM-004T NODEMCU ESP8266

          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tegangan dan arus AC menggunakan sensor PZEM-004T dengan Nodemcu ESP8266. alat ini bisa dikoneksikan ke internet (IOT) dengan menggunakan wifi. untuk lebih jelasnya berikut adalah koding dan komponennya.

 

a. Komponen


b. Cara Setting Nodemcu ESP8266



c. Program Arduino IDE

#include <Wire.h>
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <PZEM004Tv30.h>
 
PZEM004Tv30 pzem(D7,D8);  // D6, D5, (RX,TX) connect to TX,RX of PZEM

float voltage;
float current;
float power;
 

void setup() {
  Serial.begin(9600);  
}
 
void loop() {
 
voltage = pzem.voltage();
current = pzem.current();
power = pzem.power();
   
Serial.print("VoltageAC: ");      Serial.print(voltage);      Serial.println("V");
Serial.print("CurrentAC: ");      Serial.print(current);      Serial.println("A");
Serial.print("PowerAC: ");        Serial.print(power);        Serial.println("W");

delay(1000);
}


 

d. VIDEO HASILNYA