Translate

KWH Meter Digital + IOT Blynk dan Biaya per KWH Arduino Wemos D1

KWH Meter Digital + IOT Blynk dan Biaya per KWH Arduino Wemos D1


         Pada kesempatan kali ini saya akan mmenjelaskan mengenai sebuah alat yang berfungsi untuk monitor KWH listrik dengan interface menggunakan Blynk secara online IOT. keuntungan menggunakan Blynk ini yaitu bisa dimonitor secara jarak jauh asalkan kedua device terkoneksi ke internet. alat ini juga menampilkan biaya yang harus diibayar oleh pengguna. untuk lebih jelasnya berikut adalah komponen dan programnya.



a. Wemos D1 Mini




b. Arduno Nano




c. Sensor PZEM-004t




d. Lcd 16x2 + I2C






e. Program Arduino IDE

#include <PZEM004Tv30.h>
#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);

PZEM004Tv30 pzem(11, 12);

void setup() {
  lcd.begin(); 
  lcd.noCursor();
  lcd.clear();
  Serial.begin(9600); 
}

void loop() {

    float voltage = pzem.voltage();
    int tegangan = voltage * 100;
    float current = pzem.current();
    int arus = current * 100;
    float energy = pzem.energy();
    int energyx = energy * 100;
    float biaya = energy * 1352;
    int biayax = biaya * 100;
   
Serial.print("*");
Serial.print(tegangan);
Serial.print(",");
Serial.print(arus);
Serial.print(",");
Serial.print(energyx);
Serial.print(",");
Serial.print(biayax);
Serial.println("#"); 

lcd.setCursor(0, 0);
lcd.print(voltage,1);
lcd.print(" ");
lcd.print(current,1);
lcd.print(" ");

lcd.setCursor(0, 1);
lcd.print(energy);
lcd.print(" ");
lcd.print(biaya);
lcd.print("       ");

delay(1000);
}




f. Program Wemos D1

#define BLYNK_PRINT Serial   
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

int temp;
int x = 5;
int y;

int value1;
int value2;

float tegangan = 0;
float arus = 0;
float powerx = 0;
float energyx = 0;

float datain1;
float datain2;
float datain3;
float datain4;

String dataIn;
String dt[10];
int i;
boolean parsing=false;

char auth[] = "DFDGDgfhgfhgTTUTjhgnbvmbmnvfgfghgfhdg";
char ssid[] = "my hotspotku";
char pass[] = "123456789";

SimpleTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{

 Blynk.virtualWrite(V2, tegangan);
 Blynk.virtualWrite(V3, arus);
 Blynk.virtualWrite(V4, powerx);
 Blynk.virtualWrite(V5, energyx);
 delay(1000);

}

void setup()
{
 
  dataIn="";
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}

void loop()
{

while(Serial.available()>0) {
//   dataIn="";
    char inChar = (char)Serial.read();
    dataIn += inChar;
    if (inChar == '\n') {
    parsing = true;
  }
}

if(parsing){
  parsingData();
   
  Blynk.run();
  timer.run();
}

}

void parsingData(){
int j=0;

//kirim data yang telah diterima sebelumnya
//Serial.print("data masuk : ");
//Serial.print(dataIn);
//Serial.print("\n");

//inisialisasi variabel, (reset isi variabel)
dt[j]="";
//proses parsing data
for(i=1;i<dataIn.length();i++){
//pengecekan tiap karakter dengan karakter (#) dan (,)
if ((dataIn[i] == '#') || (dataIn[i] == ','))
{
//increment variabel j, digunakan untuk merubah index array penampung
j++;
dt[j]="";       //inisialisasi variabel array dt[j]
}
else
{
//proses tampung data saat pengecekan karakter selesai.
dt[j] = dt[j] + dataIn[i];
}
}

datain1 = dt[0].toInt();
datain2 = dt[1].toInt();
datain3 = dt[2].toInt();
datain4 = dt[3].toInt();

//kirim data hasil parsing
Serial.print("data 1 : ");
Serial.print(datain1);
Serial.print("\n");
Serial.print("data 2 : ");
Serial.print(datain2);
Serial.print("\n");
Serial.print("data 3 : ");
Serial.print(datain3);
Serial.print("\n");
Serial.print("data 4 : ");
Serial.print(datain4);
Serial.print("\n");

//Serial.print("data 3 : ");
//Serial.print(dt[2].toInt());
//Serial.print("\n\n");

 tegangan = datain1 / 100.0;
 arus = datain2 / 100.0;
 powerx = datain3 / 100.0;
 energyx = datain4 / 100.0;

}




g. VIDEO HASILNYA







Alat Absensi Penjaga Malam / Satpam / Security

Alat Absensi Penjaga Malam / Satpam / Security


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk absensi petugas jaga malam atau satpam. alat ini menggunakan 3 buah tombol yang digunakan untuk check point area ketika area yang terdapat tombol itu telah di cek. adapun alasannya yaitu agar security atau petugas jaga bekerja sesuai waktu yang diberikan. untuk lebih jelasnya berikut adalah program dan daftar komponennya.



a. Arduino Nano




b. RTC modul






c. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#define DS3231_I2C_ADDRESS 0x68

LiquidCrystal_I2C lcd(0x27, 16, 2);

int btsetx;
int btupx;
int btdownx;
int btokx;
int jam;
int button = 2;
int bt1 = 4;
int bt2 = 5;
int buzzer = 3;
int tstart = 21;
int tfinish = 5;
int waktu = 59;
int counter;
int simpan;
int mark;
int bt1x;
int bt2x;
int area;

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}

void setup()
{
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  simpan = EEPROM.read(0);
  
  pinMode(button,INPUT_PULLUP);
  pinMode(bt1,INPUT_PULLUP);
  pinMode(bt2,INPUT_PULLUP);
  pinMode(buzzer,OUTPUT);
  digitalWrite(buzzer,HIGH);
  
  Wire.begin();
  Serial.begin(9600);
  // DS3231 seconds, minutes, hours, day, date, month, year
   setDS3231time(50,59,20,4,30,7,20);
}

void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}

void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}

void displayTime()
{

  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);

  lcd.setCursor(0,0);
  // send it to the serial monitor
  lcd.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  lcd.print(":");
  if (minute<10)
  {
    lcd.print("0");
  }
  lcd.print(minute, DEC);
  lcd.print(":");
  if (second<10)
  {
    lcd.print("0");
  }
  lcd.print(second, DEC);
   
}

void loop()
{
  displayTime();
  
  int buttonx = digitalRead(button);
  bt1x = digitalRead(bt1);
  bt2x = digitalRead(bt2);
  
  lcd.setCursor(9,0);
  lcd.print(area);
  
  lcd.setCursor(0,1);
  lcd.print(tstart);
  lcd.print("/"); 
  lcd.print(tfinish);
  lcd.print("/"); 
  lcd.print(simpan);
  lcd.print("/");
  lcd.print(counter);
  lcd.print("     ");
  
  lcd.setCursor(12,1); 
  lcd.print(dayOfWeek);
  lcd.print("/");
  lcd.print(dayOfMonth);
  lcd.print(" ");
  
  if((hour >= tstart)&&(hour <= 23)&&(counter <= waktu)&&(hour != jam)&&(mark == 0)){
  lcd.setCursor(11,0);
  lcd.print("START");  
  mark = 1;
  }
  
  if((hour >= 0)&&(hour <= tfinish)&&(counter <= waktu)&&(hour != jam)&&(mark == 0)){
  lcd.setCursor(11,0);
  lcd.print("START");  
  mark = 1;
  }
  
  if((mark == 1)&&(counter < waktu)){
  counter++;
  }
  
  
  if((bt1x == 0)&&(counter < waktu)&&(mark == 1)&&(area == 0)){
  digitalWrite(buzzer,LOW);
  delay(500);
  digitalWrite(buzzer,HIGH);  
  area = 1;
  }
  
  if((bt2x == 0)&&(counter < waktu)&&(mark == 1)&&(area == 1)){
  digitalWrite(buzzer,LOW);
  delay(500);
  digitalWrite(buzzer,HIGH);  
  area = 2;
  }
  
  if((bt1x == 0)&&(bt2x == 0)){
  simpan = 0;
  EEPROM.write(0, simpan);
  }
  
  if((buttonx == 0)&&(counter < waktu)&&(mark == 1)&&(area == 2)){
  digitalWrite(buzzer,LOW);
  delay(500);
  digitalWrite(buzzer,HIGH);
  simpan++;
  EEPROM.write(0, simpan);
  lcd.setCursor(11,0);
  lcd.print("OFF  "); 
  counter = 0;
  mark = 0;
  area = 0;
  }
  
  if(counter == waktu){
  lcd.setCursor(11,0);
  lcd.print("OFF  "); 
  counter = 0;
  mark = 0;
  area = 0;
  }
  
  jam = hour;
  
  if((dayOfMonth == 1)&&(hour == 0)&&(minute == 0)&&(second == 0)){
  simpan = 0;
  EEPROM.write(0, simpan);
  }
  
  delay(1000);




d. VIDEO HASILNYA








Monitoring Tegangan 3 fasa (3-phase Voltage monitoring) Sensor PZEM-004t TCP-IP WEBSERVER ARDUINO

Monitoring Tegangan 3 fasa (3-phase Voltage monitoring) Sensor PZEM-004t TCP-IP WEBSERVER ARDUINO

         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk monitoring tegangan 3 fasa dan juga bisa memonitor tegangan dc serta jarak, alat ini juga dilengkapi fitur kendali relay, alat ini menggunakan komunikasi ke server via TCP-IP sehingga membutuhkan IP address. untuk lebih jelasnya berikut koding dan daftar komponennya.


a. Arduino Mega 




b. Ethernet Shield




c. Sensor PZEM 004t




d. Sensor Tegangan DC




e. Sensor Jarak HC-SRF04




f. Modul Relay




g. Program Arduino IDE

#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <Ethernet.h>
#include <PZEM004Tv30.h>
#include <SoftwareSerial.h>
#define trigPin 26
#define echoPin 28
LiquidCrystal_I2C lcd(0x27,16,2); 
PZEM004Tv30 pzem1(11, 12);
PZEM004Tv30 pzem2(A8, A9);
PZEM004Tv30 pzem3(A10, A11);
int voltage1, voltage2, voltage3;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,99);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
long duration, distance;
EthernetServer server(80);
String readString;
int relay1 = 22;
int relay2 = 24;
int mark = 0;
int markx = 2;
int incomingByte = 0; 

void setup() {
  lcd.begin();   
  lcd.noCursor();
  lcd.clear();
  Serial.begin(9600);  
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
  
   while (!Serial) {
  }
  Ethernet.begin(mac, ip);
  server.begin();
    delay(1000);
}

void loop() {
voltage1 = pzem1.voltage();
voltage2 = pzem2.voltage();
voltage3 = pzem3.voltage();
int adcteg = analogRead(A0);
float tegangan = adcteg * (5.0 / 1023.0) * 4.8;
  
digitalWrite(trigPin, LOW);  // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
distance = 23 - distance;
if(distance < 0){
  distance = 0;
}
lcd.setCursor(0, 0);
lcd.print(voltage1);
lcd.print("/");
lcd.print(voltage2);
lcd.print("/");
lcd.print(voltage3);
lcd.print("               ");
lcd.setCursor(0, 1);
lcd.print(tegangan);
lcd.print("/");
lcd.print(distance);
lcd.print("              ");
  EthernetClient client = server.available();
  if (client) {
   // Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
     //   Serial.write(c);
     if (readString.length() < 100) {
          //store characters to string
          readString += c;
          //Serial.print(c);
        }
        
        if (c == '\n' && currentLineIsBlank) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println("Refresh: 3");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println(" ");
          client.println("<title> Monitor </title> ");     
          client.println("<body bgcolor = #000000>");     
          client.println("<center>");
            client.println("<font color = yellow><center><h2>MONITORING TEGANGAN RST </h2></center><br></font>");
            client.println("<font color = #FFFFFF>");
            client.println("<h1>");
            client.println(" Tegangan R = ");
            client.print(voltage1);
            client.println("<br />");
            client.println(" Tegangan S = ");
            client.print(voltage2);
            client.println("<br />");
            client.println(" Tegangan T = ");
            client.print(voltage3);
            client.println("<br />");
            client.println(" VDC = ");
            client.print(tegangan);
            client.println("<br />"); 
            client.println(" Jarak = ");
            client.print(distance);
            client.println("<br />");          
            client.println("</h1>");      
            client.println("</font><br><br>");
           client.println("<a href = \"/?lighton1\"\"><input type = 'button' value = 'ON 1' ></a>");
           client.println("<a href = \"/?lightof2\"\"><input type = 'button' value = 'TOG 1' ></a> ");    
           client.println("<a href = \"/?lighton3\"\"><input type = 'button' value = 'ON 2' ></a>");
           client.println("<a href = \"/?lightof4\"\"><input type = 'button' value = 'TOG 2' ></a> "); 
           client.println("</center>");
//untuk kirim data ke client via TCPIP 
        server.print("Tegangan R = ");
        server.print(voltage1);
        server.print(" Tegangan S = ");
        server.print(voltage1);
        server.print(" Tegangan T = ");
        server.print(voltage1);
        server.print(" VDC = ");
        server.print(tegangan);
        server.print(" Jarak = ");
        server.println(distance);
        break; 
  
        }    
        if (c == '\n') {
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    delay(1);
    client.stop();
  //  Serial.println("client disonnected");
  }
          if((readString.indexOf("?lighton1") >0)&&(mark == 1))
          {
             digitalWrite(relay1, LOW);
             delay(3000);
             digitalWrite(relay1, HIGH);                
             mark = 0;
          }
         
          if((readString.indexOf("?lightof2") >0)&&(mark == 0))
          {
             mark = 1;
          }
        
          if((readString.indexOf("?lighton3") >0)&&(markx == 3))
          {
             digitalWrite(relay2, LOW);
             delay(3000);
             digitalWrite(relay2, HIGH);                
             markx = 2;   
          }
         
          if((readString.indexOf("?lightof4") >0)&&(markx == 2))
          {
             markx = 3;
          }
 
readString="";
delay(1000);
}



h. VIDEO HASILNYA



      

Alat Monitor Arus dan Tegangan DC Server Thingspeak + Arduino Ethernet Shield webserver

Alat Monitor Arus dan Tegangan DC Server Thingspeak + Arduino Ethernet Shield  Webserver


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang berguna untuk monitor arus dan tegangan DC via internet atau server THINGSPEAK. alat ini menggunakan sensor tegangan dc dan ACS712 untuk monitor arus dc. yang berbeda dari biasanya yaitu alat ini menggunakan ethernet shield sehngga bisa menggunakan arduino uno yang mana pin ADC bisa lebih dari satu. untuk lebih jelasnya berikut adalah komponen dan programnya.



a. Arduino + Ethernet Shield




b. Sensor tegangan DC



c. Sensor arus  ACS712




d. LCD + I2C






e. Program Arduino IDE 

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <Ethernet.h>

LiquidCrystal_I2C lcd(0x3F,16,2);

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,99);

int datain1;
int datain2;

String dataIn;
String dt[10];
int i;
boolean parsing=false;

String apiKey = "AABBVHJ678UUIGFJW";     //  Enter your Write API key from ThingSpeak
const char* resource = "/update?api_key=";
const char* server = "api.thingspeak.com";

EthernetClient client;


void setup() {
  lcd.begin();
  lcd.clear();
  lcd.noCursor(); 
  Serial.begin(9600);
  while (!Serial) {
    ;
  }

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    Ethernet.begin(mac, ip);
  }

    delay(1000);
    Serial.println("connecting...");
      
}


void loop() {
  
int adcteg = analogRead(A3);
float tegangan = adcteg * (5.0 / 1023.0) * 4.8;

int adcarus = analogRead(A2);
float v = adcarus * (5.0 / 1023.0);
float arus = (v - 2.5)/0.1;
  
lcd.setCursor(0,0);
lcd.print("V= ");
lcd.print(tegangan);
lcd.print("   ");
lcd.setCursor(0,1);
lcd.print("I= ");
lcd.print(arus);
lcd.print("   ");

EthernetClient client;

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

   client.print(String("GET ") + resource + apiKey + "&field1=" + tegangan + "&field2=" + arus + " 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.print("Tegangan: ");
  Serial.print(tegangan);
  Serial.print(" Arus: ");
  Serial.print(arus);
  Serial.println(". Send to Thingspeak.");
 }
                       
  client.stop();

  Serial.println("Waiting...");

  delay(10000);
  
}




f. VIDEO HASILNYA