Translate

Membuat Alat kendali Untuk Tanaman Hidroponik

Membuat Alat kendali Untuk Tanaman Hidroponik


               Malam ini agak tidak enak badan tapi tak mengapa saya tetap akan mem-posting sesuatu yang bisa membuat pecinta elektronik bahagia, kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat kendali otomatis untuk tanaman hidroponik, kendali otomatis yang disediakan pada contoh ini yaitu kendali waktu penyiraman dan kendali waktu kipas on/off serta blower on/off, selain itu juga ada pemantauan suhu dan kelembapan, Alat ini disetting untuk menyirami tanaman 2 kali dalam 1 hari dan juga kipas akan on saat suhu > 32 derajat celcius. berikut listing program dan skematiknya.



a. Skematik Minimum System





b. Program Bascom AVR

$regfile = "m16def.dat"
$crystal = 12000000

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

Cls
Cursor Off

Config Sda = Portc.1
Config Scl = Portc.0

Const Ds1307w = &HD0
Const Ds1307r = &HD1


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

'=========================================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 Detmerah1 As Eram Integer
Dim Detkuning1 As Eram Integer
Dim Dethijau1 As Eram Integer

Dim Merah1 As Integer
Dim Kuning1 As Integer
Dim Hijau1 As Integer

Dim Xjam As Byte
Dim Xmenit As Byte
Dim Ok_jam As Eram Byte
Dim Ok_menit As Eram Byte


Declare Sub Get_th(t As Byte , H As Byte)
Config Serialin = Buffered , Size = 128
Config Serialout = Buffered , Size = 128
Dht_put Alias Portb.2
Dht_get Alias Pinb.2
Dht_io_set Alias Ddrb.2
Dim T As Byte
Dim H As Byte
Dim Crc As Byte
Dim Mybyte As Byte
Dim Sensor_data As String * 40
Dim Tmp_str8 As String * 8
Dim Count As Byte
Enable Interrupts
Set Dht_io_set
Set Dht_put

Dim Jam As Byte , Menit As Byte , Tanggal As Byte , Bulan As Byte , Tahun As Byte
Dim Jamx As Eram Byte , Menitx As Eram Byte , Tanggalx As Eram Byte , Bulanx As Eram Byte , Tahunx As Eram Byte
Dim Lampon As Byte , Lampoff As Byte
Dim Lamponx As Eram Byte , Lampoffx As Eram Byte
Dim Pomon As Byte , Pomon2 As Byte
Dim Pomonx As Eram Byte , Pomon2x As Eram Byte

Dim A As Integer

'pompa air
Ddrb.3 = 1

'lampu LED
Ddrb.4 = 1

'tombol1
Ddrd.2 = 0
'tombol2
Ddrd.3 = 0
'tombol3
Ddrd.6 = 0
'tombol4
Ddrd.7 = 0

Ddrd.4 = 1
Ddrd.5 = 1


Tombolup Alias Pind.2
Tomboldown Alias Pind.3
Tombolselect Alias Pind.6
Tombolset Alias Pind.7

Set Portd.6
Set Portd.7
Set Portd.2
Set Portd.3


I = 13
Line1 = Chr(13)

'_sec = 00
'_hour = Jamx
'_min = 00
'Settime

'_day = 14
'_month = 3
'_year = 15
'Setdate

Main:


Portd.4 = 1
Portd.5 = 1

Lampon = Lamponx
Lampoff = Lampoffx
Pomon = Pomonx
Pomon2 = Pomon2x


A = 0


Do

'untuk menampilkan jam & tanggal
Getdatetime
Upperline
Dispdate
Lowerline
Disptime

Wait 3


If Tombolset = 0 Then
Goto Setting
End If


Call Get_th(t , H)
Cls

Upperline
Lcd "TMP: " ; T ; "C"
Lowerline
Lcd "HUM: " ; H ; "%"

Wait 5

If Tombolset = 0 Then
Goto Setting
End If

Cls

'kipas
Portd.5 = 0

'atur blower
If T > 32 Then
Portd.4 = 0
Else
Portd.4 = 1
End If

If _hour = Lampon Then
Portb.4 = 1
Elseif _hour = Lampoff Then
Portb.4 = 0
End If


If _hour = Pomon And A = 0 Then
Portb.3 = 1
Cls
Upperline
Lcd "POMPA NYALA"
Lowerline
Lcd "WAit 5 Menit"
Wait 300
Cls
Portb.3 = 0
A = 1
End If

If _hour = Pomon2 And A = 1 Then
Portb.3 = 1
Cls
Upperline
Lcd "POMPA NYALA"
Lowerline
Lcd "WAit 5 Menit"
Wait 300
Cls
Portb.3 = 0
A = 2
End If

If _hour = 23 Then
A = 0
End If




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



Sub Get_th(t As Byte , H As Byte)
 Count = 0
 Sensor_data = ""
 Set Dht_io_set
 Reset Dht_put
 Waitms 25
 Set Dht_put
 Waitus 40
 Reset Dht_io_set
 Waitus 40
 If Dht_get = 1 Then
    H = 1
    Exit Sub
 End If
  Waitus 80
  If Dht_get = 0 Then
    H = 2
    Exit Sub
  End If
  While Dht_get = 1 : Wend
   Do
    While Dht_get = 0 : Wend
    Waitus 30
     If Dht_get = 1 Then
       Sensor_data = Sensor_data + "1"
       While Dht_get = 1 : Wend
       Else
       Sensor_data = Sensor_data + "0"
    End If
    Incr Count
   Loop Until Count = 40
   Set Dht_io_set
   Set Dht_put
   Tmp_str8 = Left(sensor_data , 8)
   H = Binval(tmp_str8)
   Tmp_str8 = Mid(sensor_data , 17 , 8)
   T = Binval(tmp_str8)
   Tmp_str8 = Right(sensor_data , 8)
   Crc = Binval(tmp_str8)
   Mybyte = T + H
   If Mybyte <> Crc Then
      H = 3
   End If
End Sub

Return



Setting:

Cls

Do
Locate 1 , 1
Lcd "Set Jam "
Locate 2 , 1
Lcd "jam = " ; Jam

If Tombolup = 0 Then
Incr Jam
If Jam > 23 Then
Jam = 1
End If
Waitms 100
Cls
End If


If Tomboldown = 0 Then
Decr Jam
If Jam < 1 Then
Jam = 23
End If
Waitms 100
Cls
End If

If Tombolselect = 0 Then
Waitms 100
Bitwait Tombolselect , Set
Jamx = Jam
_hour = Jamx
Exit Do
End If
Loop


Cls


Do
Locate 1 , 1
Lcd "Set Menit "
Locate 2 , 1
Lcd "Menit = " ; Menit

If Tombolup = 0 Then
Incr Menit
If Menit > 59 Then
Menit = 0
End If
Waitms 100
Cls
End If


If Tomboldown = 0 Then
Decr Menit
If Menit < 1 Then
Menit = 59
End If
Waitms 100
Cls
End If

If Tombolselect = 0 Then
Waitms 100
Bitwait Tombolselect , Set
Menitx = Menit
_min = Menitx
Exit Do
End If
Loop

Settime

Cls

Do
Locate 1 , 1
Lcd "Set tanggal "
Locate 2 , 1
Lcd "tanggal = " ; Tanggal

If Tombolup = 0 Then
Incr Tanggal
If Tanggal > 31 Then
Tanggal = 1
End If
Waitms 100
Cls
End If


If Tomboldown = 0 Then
Decr Tanggal
If Tanggal < 1 Then
Tanggal = 31
End If
Waitms 100
Cls
End If

If Tombolselect = 0 Then
Waitms 100
Bitwait Tombolselect , Set
Tanggalx = Tanggal
_day = Tanggalx
Exit Do
End If
Loop

Cls

Do
Locate 1 , 1
Lcd "Set Bulan "
Locate 2 , 1
Lcd "bulan = " ; Bulan

If Tombolup = 0 Then
Incr Bulan
If Bulan > 12 Then
Bulan = 1
End If
Waitms 100
Cls
End If


If Tomboldown = 0 Then
Decr Bulan
If Bulan < 1 Then
Bulan = 12
End If
Waitms 100
Cls
End If

If Tombolselect = 0 Then
Waitms 100
Bitwait Tombolselect , Set
Bulanx = Bulan
_month = Bulanx
Exit Do
End If
Loop

Cls

Do
Locate 1 , 1
Lcd "Set Tahun "
Locate 2 , 1
Lcd "tahun = " ; Tahun

If Tombolup = 0 Then
Incr Tahun
If Tahun > 99 Then
Tahun = 0
End If
Waitms 100
Cls
End If


If Tomboldown = 0 Then
Decr Tahun
If Tahun < 1 Then
Tahun = 99
End If
Waitms 100
Cls
End If

If Tombolselect = 0 Then
Waitms 100
Bitwait Tombolselect , Set
Tahunx = Tahun
_year = Tahunx
Exit Do
End If
Loop

Setdate

Cls

Lampon = 0
Lampoff = 0

Do
Locate 1 , 1
Lcd "Lampu ON "
Locate 2 , 1
Lcd "jam = " ; Lampon

If Tombolup = 0 Then
Incr Lampon
If Lampon > 23 Then
Lampon = 0
End If
Waitms 100
Cls
End If


If Tomboldown = 0 Then
Decr Lampon
If Lampon < 1 Then
Lampon = 23
End If
Waitms 100
Cls
End If

If Tombolselect = 0 Then
Waitms 100
Bitwait Tombolselect , Set
Lamponx = Lampon

Exit Do
End If
Loop


Cls

Do
Locate 1 , 1
Lcd "Lampu OFF "
Locate 2 , 1
Lcd "jam = " ; Lampoff

If Tombolup = 0 Then
Incr Lampoff
If Lampoff > 23 Then
Lampoff = 0
End If
Waitms 100
Cls
End If


If Tomboldown = 0 Then
Decr Lampoff
If Lampoff < 1 Then
Lampoff = 23
End If
Waitms 100
Cls
End If

If Tombolselect = 0 Then
Waitms 100
Bitwait Tombolselect , Set
Lampoffx = Lampoff

Exit Do
End If
Loop


Lampon = Lamponx
Lampoff = Lampoffx


'POMPA AIR

Cls

Pomon = 0
Pomon2 = 0

Do
Locate 1 , 1
Lcd "Pompa ON 1 "
Locate 2 , 1
Lcd "jam = " ; Pomon

If Tombolup = 0 Then
Incr Pomon
If Pomon > 23 Then
Pomon = 0
End If
Waitms 100
Cls
End If


If Tomboldown = 0 Then
Decr Pomon
If Pomon < 1 Then
Pomon = 23
End If
Waitms 100
Cls
End If

If Tombolselect = 0 Then
Waitms 100
Bitwait Tombolselect , Set
Pomonx = Pomon

Exit Do
End If
Loop



Cls

Do
Locate 1 , 1
Lcd "Pompa ON 2 "
Locate 2 , 1
Lcd "jam = " ; Pomon2

If Tombolup = 0 Then
Incr Pomon2
If Pomon2 > 23 Then
Pomon2 = 0
End If
Waitms 100
End If


If Tomboldown = 0 Then
Decr Pomon2
If Pomon2 < 1 Then
Pomon2 = 23
End If
Waitms 100
End If

If Tombolselect = 0 Then
Waitms 100
Bitwait Tombolselect , Set
Pomon2x = Pomon2

Exit Do
End If
Loop


Pomon = Pomonx
Pomon2 = Pomon2x

Goto Main
Return






No comments:

Post a Comment