Kendali Kecepatan Motor AC Modul Dimmer Zero Crossing 4A Arduino
Translate
Kendali Kecepatan Motor AC Modul Dimmer Zero Crossing 4A Arduino
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
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