Translate

Membuat Alat Monitor Arus dan Tegangan AC Daya KWH Meter Menggunakan Arduino dan sensor ZMPT101b dan ACS 712 Topup saldo via Bluetooth Android

Membuat Alat Monitor Arus dan Tegangan AC Daya KWH Meter Menggunakan Arduino dan sensor ZMPT101b dan ACS 712 Topup Saldo via Bluetooth Android


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk monitoring arus dan tegangan dan menghitung daya terpakai seperti KWH meter. alat ini menggunakan arduino sebagai mikrokontrollernya dan RTC sebagai pewaktunya. alat ini bisa d topup saldo untuk isi ulangnya dengan menggunakan handphone android atau tab android via bluetooth. untuk lebih jelasnya berikut adalah program dan daftar komponennya.




a. Arduino Mega




b. Sensor Tegangan AC ZMPT101B




c. Sensor Arus ACS712




d. Module Relay 1 channel




e. Module RTC




f. LCD 16x2 + I2C






g. Program Arduino IDE

#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
#define DS3231_I2C_ADDRESS 0x68

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

char string[160];
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
char strsms[5];
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
int menit;
float total;

unsigned long start_times[300];
unsigned long stop_times[300];
unsigned long values[300];

// Define various ADC prescaler
const unsigned char PS_16 = (1 << ADPS2);
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);

int a = 0;
int zero = 1;
int vin = 0;
int iin = 0;
String dataku;
int isi;
int relay = 2;
int buzzer = 48;
float sisa;
unsigned int i;
unsigned int z;

// 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() {

  pinMode(relay,OUTPUT);
  digitalWrite(relay,HIGH);

  pinMode(buzzer,OUTPUT);
  digitalWrite(buzzer,LOW);

  Serial1.begin(9600);
  Serial1.setTimeout(5);

  lcd.begin();
  lcd.clear();
  lcd.noCursor();

  // set up the ADC
  ADCSRA &= ~PS_128;  // remove bits set by Arduino library

  // you can choose a prescaler from above.
  // PS_16, PS_32, PS_64 or PS_128
  ADCSRA |= PS_128;    // set our own prescaler to 64

 Wire.begin();
  Serial.begin(9600);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(0,30,7,6,24,7,15);

}


void loop() {


 if (Serial1.available()>0)
  {
    dataku = Serial1.readString();
    isi = dataku.toInt();
    sisa = isi;
  }


displayTime();

  z = 0;
 
  // capture the values to memory
  for(i=0;i<300;i++) {
    start_times[i] = micros();
    values[i] = analogRead(A0);           

  if (values[i] >= z) {
  z = values[i];
  }
    stop_times[i] = micros();
  }

   int vin = z ;

  z = 0;

  //================================
  // capture the values to memory
  for(i=0;i<300;i++) {
    start_times[i] = micros();
    values[i] = analogRead(A1);           

  if (values[i] >= z) {
  z = values[i];
  }
    stop_times[i] = micros();
  }
     float v1 = z * (5.0/1023.0);
     float iin = (v1-2.5)/0.1 ;

z = 0;

  // capture the values to memory
  for(i=0;i<300;i++) {
    start_times[i] = micros();
    values[i] = analogRead(A1);           

  if (values[i] >= z) {
  z = values[i];
  }
    stop_times[i] = micros();
  }
     float v1x = z * (5.0/1023.0);
     float iinx = (v1x-2.5)/0.1 ;

float iintot = (iin + iinx) / 2;

if (iintot < 0) {
iintot = 0;
}

 z = 0;

float vrms = (vin - 530.9) / 0.413 ;

if (vrms < 0) {
vrms = 0;
}

float p = vrms * iin;

if((menit != minute)&&(isi > 0)){
total = (p / 1000.0) + total;
menit = minute;
}

if((total >= isi)&&(isi > 0)){
digitalWrite(relay,HIGH);
}

if((total < isi)&&(isi > 0)){
digitalWrite(relay,LOW);
}

if((total >= sisa - 1)&&(isi > 0)){
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer,LOW);
delay(500);
}

  lcd.setCursor(11, 0);
  lcd.print(isi);

  lcd.setCursor(0, 0);
  lcd.print(vrms,1);

  lcd.print("/");
  lcd.print(iintot);
  lcd.print(" ");

  lcd.setCursor(9, 1);
  lcd.print(total);
  lcd.print("     ");

delay(200);
}



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);
  // send it to the serial monitor
  lcd.setCursor(0, 1);
  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);

}





h. Program Android







i. VIDEO HASILNYA










No comments:

Post a Comment