Deteksi Tegangan AC 220v dan Listrik Padam / Nyala NOTIF SMS
Pada kesempatan kali ini saya akan menjeaskan mengenai bagaimana memuat sebuah alat yang dapat mendeteksi tegangan PLN 220v, jadi alat ini akan memberikan notif sms jika terjadi listrik padam dan ketika listrik nyala maka akan memberikan notif sms juga sehingga user atau pemilik bisa mengetahui bahwa telah terjadi listrik padam. untuk lebih jelasnya berikut adalah koding dan skemanya.
a. Komponen dan skemanya
b. Program Arduino IDE
#include "Wire.h"
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
int vin = 0;
int iin = 0;
int vout;
float kal;
int a = 0;
int zero = 1;
int kondisi = 0;
int dataadc;
char string[160];
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
unsigned long values[100];
int vin1;
int vin2;
int vin3;
int vin4;
unsigned int i1;
unsigned int z1;
unsigned int i2;
unsigned int z2;
unsigned int i3;
unsigned int z3;
unsigned int i4;
unsigned int z4;
void setup() {
Serial.begin(9600);
Serial.println("GSM Shield testing.");
if (gsm.begin(2400)) {
Serial.println("\nstatus=READY");
started=true;
} else Serial.println("\nstatus=IDLE");
if(started) {
if (sms.SendSMS("081234567890", "Alat Ready"))
Serial.println("\nSMS sent OK");
}
}
void loop() {
z1 = 0;
z2 = 0;
z3 = 0;
z4 = 0;
for(i1=0;i1<100;i1++) {
values[i1] = analogRead(A0);
if (values[i1] >= z1) {
z1 = values[i1];
}
}
for(i2=0;i2<100;i2++) {
values[i2] = analogRead(A0);
if (values[i2] >= z2) {
z2 = values[i2];
}
}
for(i3=0;i3<100;i3++) {
values[i3] = analogRead(A0);
if (values[i3] >= z3) {
z3 = values[i3];
}
}
for(i4=0;i4<100;i4++) {
values[i4] = analogRead(A0);
if (values[i4] >= z4) {
z4 = values[i4];
}
}
vin1 = z1 ;
vin2 = z2 ;
vin3 = z3 ;
vin4 = z4 ;
z1 = 0;
z2 = 0;
z3 = 0;
z4 = 0;
if((vin1 > vin2)&&(vin1 > vin3)&&(vin1 > vin4)){
vout = vin1;
kal = (vout - 515.9) / 0.413 ;
}
else if((vin2 > vin1)&&(vin2 > vin3)&&(vin2 > vin4)){
vout = vin2;
kal = (vout - 515.9) / 0.413 ;
}
else if((vin3 > vin1)&&(vin3 > vin2)&&(vin3 > vin4)){
vout = vin3;
kal = (vout - 515.9) / 0.413 ;
}
else if((vin4 > vin1)&&(vin4 > vin2)&&(vin4 > vin3)){
vout = vin4;
kal = (vout - 515.9) / 0.413 ;
}
if(kal < 0){
kal = 0;
}
Serial.println(kal);
if((kal > 200)&&(kondisi == 1)){
if (sms.SendSMS("081234567890", "Listrik Nyala"))
Serial.println("\nSMS sent OK");
kondisi = 0;
delay(3000);
}
if((kal < 200)&&(kondisi == 0)){
if (sms.SendSMS("081234567890", "Listrik Padam"))
Serial.println("\nSMS sent OK");
kondisi = 1;
delay(3000);
}
delay(200);
}
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
int vin = 0;
int iin = 0;
int vout;
float kal;
int a = 0;
int zero = 1;
int kondisi = 0;
int dataadc;
char string[160];
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
unsigned long values[100];
int vin1;
int vin2;
int vin3;
int vin4;
unsigned int i1;
unsigned int z1;
unsigned int i2;
unsigned int z2;
unsigned int i3;
unsigned int z3;
unsigned int i4;
unsigned int z4;
void setup() {
Serial.begin(9600);
Serial.println("GSM Shield testing.");
if (gsm.begin(2400)) {
Serial.println("\nstatus=READY");
started=true;
} else Serial.println("\nstatus=IDLE");
if(started) {
if (sms.SendSMS("081234567890", "Alat Ready"))
Serial.println("\nSMS sent OK");
}
}
void loop() {
z1 = 0;
z2 = 0;
z3 = 0;
z4 = 0;
for(i1=0;i1<100;i1++) {
values[i1] = analogRead(A0);
if (values[i1] >= z1) {
z1 = values[i1];
}
}
for(i2=0;i2<100;i2++) {
values[i2] = analogRead(A0);
if (values[i2] >= z2) {
z2 = values[i2];
}
}
for(i3=0;i3<100;i3++) {
values[i3] = analogRead(A0);
if (values[i3] >= z3) {
z3 = values[i3];
}
}
for(i4=0;i4<100;i4++) {
values[i4] = analogRead(A0);
if (values[i4] >= z4) {
z4 = values[i4];
}
}
vin1 = z1 ;
vin2 = z2 ;
vin3 = z3 ;
vin4 = z4 ;
z1 = 0;
z2 = 0;
z3 = 0;
z4 = 0;
if((vin1 > vin2)&&(vin1 > vin3)&&(vin1 > vin4)){
vout = vin1;
kal = (vout - 515.9) / 0.413 ;
}
else if((vin2 > vin1)&&(vin2 > vin3)&&(vin2 > vin4)){
vout = vin2;
kal = (vout - 515.9) / 0.413 ;
}
else if((vin3 > vin1)&&(vin3 > vin2)&&(vin3 > vin4)){
vout = vin3;
kal = (vout - 515.9) / 0.413 ;
}
else if((vin4 > vin1)&&(vin4 > vin2)&&(vin4 > vin3)){
vout = vin4;
kal = (vout - 515.9) / 0.413 ;
}
if(kal < 0){
kal = 0;
}
Serial.println(kal);
if((kal > 200)&&(kondisi == 1)){
if (sms.SendSMS("081234567890", "Listrik Nyala"))
Serial.println("\nSMS sent OK");
kondisi = 0;
delay(3000);
}
if((kal < 200)&&(kondisi == 0)){
if (sms.SendSMS("081234567890", "Listrik Padam"))
Serial.println("\nSMS sent OK");
kondisi = 1;
delay(3000);
}
delay(200);
}
c, VIDEO HASILNYA
No comments:
Post a Comment