Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk mengukur tegangan AC dengan mengunakan Arduino UNO dan sensor ZMPT101B, jadi prinsip kerjanya alat ini seperti multimeter atau avometer yaitu mengukur tegangan ac dari 0 sampai 220 VAC. yang paling penting dari alat ini yaitu bagaimana cara kalibrasi dari sensor AC karena output sensor adalah sinyal sinus dan bagaimana mendapatkan Vrms-nya. untuk lebih jelasnya berikut adalah skema dan programnya.
a. Arduino Uno
b. Sensor ZMPT101B
c. LCD 16x2
d. Program Arduino IDE
#include "Wire.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, 9, 8, 7, 6, 5);
int vin = 0;
int iin = 0;
int vout;
float kal;
unsigned long start_times[100];
unsigned long stop_times[100];
unsigned long values[100];
// 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;
void setup() {
lcd.begin(16, 2);
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
}
void loop() {
unsigned int i1;
unsigned int z1;
z1 = 0;
unsigned int i2;
unsigned int z2;
z2 = 0;
unsigned int i3;
unsigned int z3;
z3 = 0;
unsigned int i4;
unsigned int z4;
z4 = 0;
for(i1=0;i1<100;i1++) {
start_times[i1] = micros();
values[i1] = analogRead(A0);
if (values[i1] >= z1) {
z1 = values[i1];
}
stop_times[i1] = micros();
}
for(i2=0;i2<100;i2++) {
start_times[i2] = micros();
values[i2] = analogRead(A0);
if (values[i2] >= z2) {
z2 = values[i2];
}
stop_times[i2] = micros();
}
for(i3=0;i3<100;i3++) {
start_times[i3] = micros();
values[i3] = analogRead(A0);
if (values[i3] >= z3) {
z3 = values[i3];
}
stop_times[i3] = micros();
}
for(i4=0;i4<100;i4++) {
start_times[i4] = micros();
values[i4] = analogRead(A0);
if (values[i4] >= z4) {
z4 = values[i4];
}
stop_times[i4] = micros();
}
int vin1 = z1 ;
int vin2 = z2 ;
int vin3 = z3 ;
int 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;
}
/*
lcd.setCursor(0, 0);
lcd.print("v1= ");
lcd.print(vin1);
lcd.setCursor(0, 1);
lcd.print("v2= ");
lcd.print(vin2);
lcd.setCursor(8, 0);
lcd.print("v3= ");
lcd.print(vin3);
lcd.setCursor(8, 1);
lcd.print("v4= ");
lcd.print(vin4);
*/
lcd.setCursor(0, 0);
lcd.print("adc= ");
lcd.print(vout);
lcd.setCursor(0, 1);
lcd.print("Vrms= ");
lcd.print(kal);
delay(200);
}
e. VIDEO HASILNYA
No comments:
Post a Comment