Translate

Membuat alat simulasi traffic light untuk palang pintu kereta api menggunakan sensor jarak Ultrasonik SRF04

Membuat alat simulasi traffic light untuk palang pintu kereta api menggunakan sensor jarak Ultrasonik SRF04


             Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat untuk kendali lampu traffic light palang pintu kereta api, jadi sistem kerjanya yaitu terdapat 3 buah sensor jarak yang mana sensor 1 digunakan untuk medeteksi arah datangnya kereta, sensor 2 untuk medeteksi arah datang kereta dari arah sebaliknya kemudian sensor 3 digunakan untuk mendeteksi selesainya kereta. alat ini menggunakan penampil lcd dan led sebagai lampunya. untuk lebih jelasnya berikut adalah skema dan programnya.



a. Minimum System





b. Sensor Jarak Ultrasonik SRF04





c. LED 





d. Program Bascom AVR

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

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


Config Timer0 = Timer , Prescale = 256

Cls
Cursor Off



Declare Sub Cek_jarak1
Declare Sub Cek_jarak2
Declare Sub Cek_jarak3

Dim Data_jarak1 As Word
Dim Data_jarak_olah1 As Word
Dim Data_jarak_fix1 As Word

Dim Data_jarak2 As Word
Dim Data_jarak_olah2 As Word
Dim Data_jarak_fix2 As Word

Dim Data_jarak3 As Word
Dim Data_jarak_olah3 As Word
Dim Data_jarak_fix3 As Word

Config Porta.1 = Output
Config Pinb.1 = Input

Triger1 Alias Porta.1
Pecho1 Alias Pinb.1

Config Porta.0 = Output
Config Pinb.0 = Input

Triger2 Alias Porta.0
Pecho2 Alias Pinb.0

Config Portd.2 = Output
Config Pind.3 = Input

Triger3 Alias Portd.2
Pecho3 Alias Pind.3

Dim A As Integer

'TL1
Ddrb.2 = 1
Ddrb.3 = 1
Ddrb.4 = 1

'TL2
Ddrb.5 = 1
Ddrb.6 = 1
Ddrb.7 = 1


'TL3
Ddrc.0 = 1
Ddrc.1 = 1
Ddrc.2 = 1

Portb.2 = 0
Portb.3 = 0
Portb.4 = 0

Portb.5 = 0
Portb.6 = 0
Portb.7 = 0

Portc.0 = 0
Portc.1 = 0
Portc.2 = 0


Utama:
A = 0
Do


Call Cek_jarak1
  Data_jarak1 = Data_jarak1
  Data_jarak_olah1 = Data_jarak1 * 100
  Data_jarak_fix1 = Data_jarak_olah1 / 256

Call Cek_jarak2
  Data_jarak2 = Data_jarak2
  Data_jarak_olah2 = Data_jarak2 * 100
  Data_jarak_fix2 = Data_jarak_olah2 / 256

Call Cek_jarak3
  Data_jarak3 = Data_jarak3
  Data_jarak_olah3 = Data_jarak3 * 100
  Data_jarak_fix3 = Data_jarak_olah3 / 256

Upperline
Lcd Data_jarak_fix1 ; "  " ; Data_jarak_fix2 ; "  " ; Data_jarak_fix3

Waitms 200
Cls


If Data_jarak_fix1 < 10 And A = 0 Then

A = 1

End If

If Data_jarak_fix2 < 10 And A = 0 Then

A = 1

End If

If A = 1 Then

Portb.2 = 0
Portb.3 = 1
Portb.4 = 0

Portb.5 = 0
Portb.6 = 1
Portb.7 = 0

Portc.0 = 0
Portc.1 = 0
Portc.2 = 1

Wait 3

Portb.2 = 1
Portb.3 = 0
Portb.4 = 0

Portb.5 = 1
Portb.6 = 0
Portb.7 = 0

Portc.0 = 0
Portc.1 = 0
Portc.2 = 1

A = 2

End If



If A = 2 Then
Portb.2 = 1
Portb.3 = 0
Portb.4 = 0

Portb.5 = 1
Portb.6 = 0
Portb.7 = 0

Portc.0 = 0
Portc.1 = 0
Portc.2 = 1

If Data_jarak_fix3 < 10 And A = 2 Then
Goto Tengah
End If

End If


If A = 0 Then

Portb.2 = 0
Portb.3 = 0
Portb.4 = 1

Portb.5 = 0
Portb.6 = 0
Portb.7 = 1

Portc.0 = 1
Portc.1 = 0
Portc.2 = 0

End If

Loop






Sub Cek_jarak1:
Reset Triger1
Waitus 10
Set Triger1
Waitus 20
Reset Triger1

Tcnt0 = 0
Bitwait Pecho1 , Set
Start Timer0

Do
If Pecho1 = 0 Then
Data_jarak1 = Tcnt0
Stop Timer0
Exit Do
End If

If Tifr.0 = 1 Then
Stop Timer0
Tifr.0 = 1
Data_jarak1 = &HFF
Exit Do
End If
Loop
Stop Timer0
Waitms 15
End Sub



Sub Cek_jarak2:
Reset Triger2
Waitus 10
Set Triger2
Waitus 20
Reset Triger2

Tcnt0 = 0
Bitwait Pecho2 , Set
Start Timer0

Do
If Pecho2 = 0 Then
Data_jarak2 = Tcnt0
Stop Timer0
Exit Do
End If

If Tifr.0 = 1 Then
Stop Timer0
Tifr.0 = 1
Data_jarak2 = &HFF
Exit Do
End If
Loop
Stop Timer0
Waitms 15
End Sub




Sub Cek_jarak3:
Reset Triger3
Waitus 10
Set Triger3
Waitus 20
Reset Triger3

Tcnt0 = 0
Bitwait Pecho3 , Set
Start Timer0

Do
If Pecho3 = 0 Then
Data_jarak3 = Tcnt0
Stop Timer0
Exit Do
End If

If Tifr.0 = 1 Then
Stop Timer0
Tifr.0 = 1
Data_jarak3 = &HFF
Exit Do
End If
Loop
Stop Timer0
Waitms 15
End Sub




Tengah:
Do

Portb.2 = 1
Portb.3 = 0
Portb.4 = 0

Portb.5 = 1
Portb.6 = 0
Portb.7 = 0

Portc.0 = 0
Portc.1 = 0
Portc.2 = 1

Call Cek_jarak1
  Data_jarak1 = Data_jarak1
  Data_jarak_olah1 = Data_jarak1 * 100
  Data_jarak_fix1 = Data_jarak_olah1 / 256

Call Cek_jarak2
  Data_jarak2 = Data_jarak2
  Data_jarak_olah2 = Data_jarak2 * 100
  Data_jarak_fix2 = Data_jarak_olah2 / 256

Call Cek_jarak3
  Data_jarak3 = Data_jarak3
  Data_jarak_olah3 = Data_jarak3 * 100
  Data_jarak_fix3 = Data_jarak_olah3 / 256

Upperline
Lcd Data_jarak_fix1 ; "  " ; Data_jarak_fix2 ; "  " ; Data_jarak_fix3


Waitms 200
Cls

If Data_jarak_fix3 > 10 Then
Goto Utama
End If


Loop






 e. VIDEO HASILNYA











No comments:

Post a Comment