Translate

Membuat Alat Kendali Dengan Kontrol Waktu dari Android

Membuat Alat Kendali Dengan Kontrol Waktu dari Android


        Malam yang indah ditemani lagu Avenged Sevenfold hehehehe...... kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat yang bisa dikendalikan waktu nyala dan matinya menggunakan device Android, jadi device Android baik itu berupa HP atau Tablet bisa di gunakan untuk mengendalikan misalnya lampu AC atau pompa air yang watt-nya rendah. Alat ini dilengkapi dengan RTC (Real Time Clock) yang berfungsi untuk memproses hari, tanggal dan jam sekarang, sehingga pada saat alat ini mati atau OFF, RTC akan tetap berjalan / ON, yang akan mengakibatkan saat mikrokontroller menyala, waktu yang ditnjukkan adalah waktu sekarang. Komunikasi antara Alat dengan Device Android menggunakan Bluetooth HC-05. Untuk lebih jelasnya berikut Gambar dan Programnya.



a. Minimum System 




 
 b. Bluetooth HC-06


*NOTE = Pakailah HC-06 untuk hasil yang maksimal



 c. Relay Modul




d. Modul RTC






e. Program Bascom AVR

$regfile = "m8def.dat"
$crystal = 8000000
$baud = 9600

Config Lcdpin = Pin , Rs = Portd.2 , E = Portd.3 , Db4 = Portd.4
Config Lcdpin = Pin , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7
Config Lcd = 16 * 2

Cls
Cursor Off
Main:

Config Sda = Portc.4
Config Scl = Portc.5

Const Ds1307w = &HD0
Const Ds1307r = &HD1

On Urxc Getchar

Dim Inchar As String * 20

Enable Interrupts
Enable Urxc

Dim _sec As Byte
Dim _min As Byte
Dim _hour As Byte
Dim _day As Byte
Dim _month As Byte
Dim _year As Byte
Dim _weekday As Byte

Dim Sa(3) As String * 2
Dim Sb(3) As String * 2

Declare Sub Getdatetime
Declare Sub Settime
Declare Sub Getsec
Declare Sub Disptime
Declare Sub Dispdate
Declare Sub Format_00
Declare Sub Setdate
Declare Sub Subset

Dim I As Byte
Dim Flagset As Bit                                          '0 = Waktu, 1 = Tanggal
Dim Flagreset As Bit
Dim Line1 As String * 1
Dim Zx As Integer
Dim Datas As String * 20
Dim Id As String * 20
Dim Data1 As String * 2
Dim Data2 As String * 2
Dim Data3 As String * 2
Dim Data4 As String * 2
'=========================================RTC

Dim Weekday As Byte
Dim Jam_puluhan As Integer
Dim Jam_satuan As Integer
Dim Min_puluhan As Integer
Dim Min_satuan As Integer
Dim Sec_puluhan As Integer
Dim Sec_satuan As Integer
Dim Ax As Integer

Dim Datain1 As Integer
Dim Datain2 As Integer
Dim Datain3 As Integer
Dim Datain4 As Integer

Datain1 = 0
Datain2 = 0
Datain3 = 0
Datain4 = 0

Ddrb.0 = 1

I = 13
Line1 = Chr(13)

'_sec = 00
'_hour = 11
'_min = 38
'Settime

'_day = 1
'_month = 8
'_year = 15
'Setdate

Datas = ""
Zx = 0

Datain1 = Val(data1)
Datain2 = Val(data2)
Datain3 = Val(data3)
Datain4 = Val(data4)

Cls

Do

Getdatetime
Upperline
Dispdate
Lowerline
Disptime

If _hour = Datain1 And _min = Datain2 Then
Portb.0 = 1
End If

If _hour = Datain3 And _min = Datain4 Then
Portb.0 = 0
End If

Zx = 0

Loop

Sub Getdatetime:

I2cstart                                                    ' Generate start code
I2cwbyte Ds1307w                                            ' send address

I2cwbyte 0                                                  ' start address in 1307

I2cstart                                                    ' Generate start code
I2cwbyte Ds1307r                                            ' send address

I2crbyte _sec , Ack
I2crbyte _min , Ack                                         ' MINUTES
I2crbyte _hour , Ack                                        ' Hours
I2crbyte _weekday , Ack                                     ' Day of Week
I2crbyte _day , Ack                                         ' Day of Month
I2crbyte _month , Ack                                       ' Month of Year
I2crbyte _year , Nack                                       ' Year

I2cstop

_sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
_day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
End Sub

Sub Settime:
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)

I2cstart                                                    ' Generate start code
I2cwbyte Ds1307w                                            ' send address
I2cwbyte 0                                                  ' starting address in 1307
I2cwbyte _sec                                               ' Send Data to SECONDS
I2cwbyte _min                                               ' MINUTES
I2cwbyte _hour                                              ' Hours
I2cstop

End Sub

Sub Setdate

_day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)

I2cstart                                                    ' Generate start code
I2cwbyte Ds1307w                                            ' send address
I2cwbyte 4                                                  ' starting address in 1307
I2cwbyte _day                                               ' Send Data to SECONDS
I2cwbyte _month                                             ' MINUTES
I2cwbyte _year                                              ' Hours
I2cstop

End Sub

Sub Dispdate
Sa(1) = Str(_day)
Sa(2) = Str(_month)
Sa(3) = Str(_year)
Format_00
Lcd "Date: " ; Sb(1) ; "-" ; Sb(2) ; "-" ; Sb(3)
End Sub

Sub Disptime
Sa(1) = Str(_hour)
Sa(2) = Str(_min)
Sa(3) = Str(_sec)
Format_00
Lcd "Time: " ; Sb(1) ; ":" ; Sb(2) ; ":" ; Sb(3)
End Sub

Sub Format_00
For I = 1 To 3 Step 1
Sb(i) = Format(sa(i) , "00")
Next I
End Sub
Return



Getchar:
Cls
Zx = 1
Datas = ""

Do
Inchar = Inkey()

Datas = Datas + Inchar
Id = Left(datas , 20 )

Incr Zx

Loop Until Zx > 20000


Upperline
Lcd Id
Wait 3


If Zx > 20000 Then

'parsing data
Data1 = Left(datas , 2)
Data2 = Mid(datas , 3 , 2)
Data3 = Mid(datas , 5 , 2)
Data4 = Mid(datas , 7 , 2)


Upperline
Lcd Data1 ; " " ; Data2 ; " " ; Data3 ; " " ; Data4

Wait 3

Goto Main
End If
Return





f. Program Android







g. VIDEO HASILNYA








No comments:

Post a Comment