Perancangan Program Hasil pengukuran Menghitung ketelitian alat Program rangkaian

dan baris berlogika ‘0’ perubahan logika inilah yang diproses oleh mikrokontroler. Skematik dari keypad dibawah ini: Gambar 3.4 Skematik rangkaian keypad

3.2 Perancangan Program

Diagram alir pemrogramannya adalah sebagai berikut : START INIISIALISASI DAN NILAI AWAL BACA SISA KWH KWH = 0 ? TAMPILKAN PADA LCD DAYA YANG DIGUNAKAN BACA ARUS BEBAN AKUMULASIKAN DAYA PADA SISA KWH INIISIALISASI DAN NILAI AWAL ADA INPUT KEYPAD ? VERIFIKASI KODE PASSWORD PASSWORD SESUAI ? TAMBAHKAN KWH PADA MEMORI START TIDAK YA YA TIDAK YA TIDAK Gambar 3.5 Flow Chart Program Sistem Pada saat rangkaian dinyalakan maka LCD akan menampilkan daya yang digunakan dan sisa kWh. Apabila sisa kWh akan habis maka di LCDS akan muncul peringantan pulsa akan Universitas Sumatera Utara habis dan meminta untuk memasukkan angka yang telah program didalamnya, jika angka yang dimasukkan sesuai maka LCD akan menampilkan jumlah kWh yang diisi. Universitas Sumatera Utara BAB 4 PENGUJIAN ALAT DAN PROGRAM

4.1 Hasil pengukuran

Jumlah lampu Jumlah watt pada lampu Pengukuran menggunakan multimeter Pengukuran menggunakan alat Watt Arus ampere Tegangan volt Daya = IV Watt 1 100 0,42 209 87,78 65 2 100 0,84 209 175,56 143 3 100 1,29 209 261,25 226

4.2 Menghitung ketelitian alat

• Ketelitian 1 = 87,78 ���� −65 ���� 87,78 ���� × 100 = 25,95 • Ketelitian 2 = 175,56 ���� −143 ���� 175,56 ���� × 100 = 18,55 • Ketelitian 3 = 261,25 ���� −226 ���� 261,25 ���� × 100 = 13,49 Rata – rata ketelitian = 25,95 + 18,55 + 13,49 3 = 19,33

4.3 Program rangkaian

include mega8.h include delay.h include stdio.h include alcd.h define ADC_VREF_TYPE 0x00 unsigned int read_adcunsigned char adc_input { ADMUX=adc_input | ADC_VREF_TYPE 0xff; Delay needed for the stabilization of the ADC input voltage delay_us10; Universitas Sumatera Utara Start the AD conversion ADCSRA|=0x40; Wait for the AD conversion to complete while ADCSRA 0x10==0; ADCSRA|=0x10; return ADCW; } void Read_keyvoid; void Passkeyvoid; unsigned char dt, dtkey,j; unsigned int X; void Displayvoid; void Rsetvoid; unsigned char eeprom addr_eeprom; unsigned int P,k,I,KWH,X; unsigned int DATA,W; unsigned char V,j,Batas; char buf[33]; char Password[9]; void mainvoid { InputOutput Ports initialization Port B initialization PORTB=0xFF; DDRB=0x38; PORTC=0x00; DDRC=0x01; PORTD=0x02; DDRD=0x00; ADC initialization ADMUX=ADC_VREF_TYPE 0xff; ADCSRA=0x82; Universitas Sumatera Utara lcd_init16; lcd_gotoxy0,0; lcd_putsf DIGITAL ; lcd_gotoxy0,1; lcd_putsf KWH METER ; delay_ms2000; lcd_clear; Batas = 200; Passkey; QZ: addr_eeprom = 0;delay_ms5; W = addr_eeprom ;delay_ms5; Display; if W200 {PORTC.0 = 1;} while 1 { for j=0;j10;j++{ I = read_adc4; if I 40 {k = 0;} if I = 40 {k = 9;} P = I k10; sprintfbuf,DAYA : i W ,P; lcd_gotoxy0,0; lcd_putsbuf; X = P100; delay_ms1000; Universitas Sumatera Utara while W = Batas {PORTC.0 = 0;lcd_gotoxy0,0;lcd_putsf KUOTA HABIS ;lcd_gotoxy0,1;lcd_putsf SISTEM CUTOFF ;delay_ms1000;Passkey;goto QZ;} if W = Batas - 2 {lcd_gotoxy0,0;lcd_putsf PERINGATAN ;lcd_gotoxy0,1;lcd_putsfKUOTA AKAN HABIS;delay_ms1000;} } W = W + X; addr_eeprom = 0;delay_ms5; addr_eeprom = W;delay_ms5; Display; } } void Rsetvoid { PORTC.0 = 1; addr_eeprom = 0;delay_ms5; addr_eeprom = 0;delay_ms5; delay_ms2000; } void Displayvoid { if W 10{ lcd_gotoxy0,1;lcd_putsfKWH : 0. WH; lcd_gotoxy8,1; lcd_putcharW 10 + 0x30;} if W = 10{ lcd_gotoxy0,1;lcd_putsfKWH : WH; Universitas Sumatera Utara lcd_gotoxy6,1; lcd_putcharW10 10 + 0x30; lcd_putchar.; lcd_putcharW 10 + 0x30;} if W = 100{ lcd_gotoxy0,1;lcd_putsfKWH : WH; lcd_gotoxy6,1; lcd_putcharW100 10 + 0x30; lcd_putcharW10 10 + 0x30; lcd_putchar.; lcd_putcharW 10 + 0x30;} } void Passkeyvoid { Ret: j=1;lcd_clear; lcd_gotoxy0,0; lcd_putsfINPUT PASS KEY ; lcd_gotoxy4,1; lcd_putsfN : ; while j =9 { while PIND.1 == 1 { Read_key; X = dtkey; lcd_gotoxy9,1; sprintfbuf,i ,X; lcd_putsbuf; lcd_gotoxy5,1; sprintfbuf,i ,j; lcd_putsbuf; delay_ms200; } Universitas Sumatera Utara while PIND.1 == 0{} Password[j] = X;j++;delay_ms200; } if Password[1] == 3{ if Password[2] == 7{if Password[3] == 9{if Password[4] == 2{if Password[5] == 4{if Password[6] == 2{if Password[7] == 8{if Password[8] == 6{lcd_clear;lcd_gotoxy0,0;lcd_putsf RELOAD SUCCESS ;Rset;goto ex;}}}}}}}} if Password[1] == 4{ if Password[2] == 2{if Password[3] == 7{if Password[4] == 5{if Password[5] == 9{if Password[6] == 7{if Password[7] == 2{if Password[8] == 4{lcd_clear;lcd_gotoxy0,0;lcd_putsf RELOAD SUCCESS ;Rset;goto ex;}}}}}}}} if Password[1] == 8{ if Password[2] == 6{if Password[3] == 5{if Password[4] == 7{if Password[5] == 4{if Password[6] == 6{if Password[7] == 5{if Password[8] == 3{lcd_clear;lcd_gotoxy0,0;lcd_putsf RELOAD SUCCESS ;Rset;goto ex;}}}}}}}} if Password[1] == 2{ if Password[2] == 8{if Password[3] == 4{if Password[4] == 2{if Password[5] == 3{if Password[6] == 5{if Password[7] == 7{if Password[8] == 1{lcd_clear;lcd_gotoxy0,0;lcd_putsf RELOAD SUCCESS ;Rset;goto ex;}}}}}}}} if Password[1] == 1{ if Password[2] == 2{if Password[3] == 3{if Password[4] == 4{if Password[5] == 5{if Password[6] == 6{if Password[7] == 7{if Password[8] == 8{lcd_clear;lcd_gotoxy0,0;lcd_putsf RELOAD SUCCESS ;Rset;goto ex;}}}}}}}} lcd_clear;lcd_gotoxy0,0;lcd_putsf RELOAD FAIL ;lcd_gotoxy0,1;lcd_putsf PLEASE RETRY ;delay_ms2000; goto Ret; ex: } void Read_keyvoid { PORTB.3=0; dt=~PINB 0x07; switch dt { case 1: dtkey=1; break; case 2: dtkey=4; break; case 4: dtkey=7; Universitas Sumatera Utara break; }; PORTB.3=1; PORTB.4=0; dt=~PINB 0x07; switch dt { case 1: dtkey=2; break; case 2: dtkey=5; break; case 4: dtkey=8; break; }; PORTB.4=1; PORTB.5=0; dt=~PINB 0x07; switch dt { case 1: dtkey=3; break; case 2: dtkey=6; break; case 4: dtkey=9; break; }; PORTB.5=1; } Universitas Sumatera Utara BAB 5 KESIMPULAN DAN SARAN

5.1 Kesimpulan