Translate

Membuat Alat Pengaman Dengan SMS Gateway Modem Wavecom dilengkapi GPS EM-411 dan Tilt Sensor GY-61

Membuat Alat Pengaman Dengan SMS Gateway Modem Wavecom dilengkapi GPS EM-411 dan Tilt Sensor GY-61 ( Sensor Kemiringan )


          Kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat pengaman dengan menggunakan 3 device berbeda yaitu sensor kemiringan GY-61, GPS EM-411 dan sms gateway modem wavecom. Sebenarnya kegunaan alat ini yaitu untuk pengaman sepeda motor, jadi saat dicuri akan ada GPS yang melacak, dan juga jika sepeda motor dibawa maling pasti akan terdeteksi kemiringannya, kemudian sms gateway digunakan sebagai media pemberi kabar ke pemilik sepeda motor bahwa motornya dalam keadaan bahaya. Sms gateway yang digunakan yaitu modem wavecom fastrack serial port. jika si pemilik sepeda motor telah mendapatkan pesan bahaya maka untuk mematikannya tinggal sms balik dengan pesan #L. fungsi GPS disini yaitu jika motor dibawa maling pasti akan ada perubahan lokasi, dengan perubahan itulah maka akan memberitahu kepada pemilik via sms. Terlebih dahulu lokasi harus disimpan koordinatnya baru bisa dipakai.



a. Minimum System ATMega164 





b. LCD 16x2




c. Modem Wavecom Serial Port




d. Tilt Sensor GY-61




e. GPS EM-411





f. Program Bascom AVR

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

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

Config Adc = Single , Prescaler = Auto , Reference = Avcc

Config Com1 = 4800 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Com2 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0

Open "com1:" For Binary As #1
Open "Com2:" For Binary As #2

Dim X As Word
Dim Y As Word
Dim Z As Word
Dim A As Integer
A = 0

Dim Pas1 As Word
Dim Pas2 As Word
Dim Pas3 As Word

Dim Data_masuk As String * 100
Dim Cmti_pos As Byte , Cmgr_pos As Byte , Index_pos As Byte , Cmd_pos As Byte
Dim Pjg_sms_index As Byte , Pjg_data As Byte
Dim Sms_index As String * 3
Dim Cmd As String * 4
Dim Cmdbin As Byte
Dim Simpanlatup As Single
Dim Simpanlatbot As Single
Dim Simpanlongup As Single
Dim Simpanlongbot As Single
Dim Ews As String * 10 , Nss As String * 8 , Sat As String * 2
Dim Nssx As String * 8
Dim Hh As String * 2 , Hh2 As Byte , Mm As String * 2 , Ss As String * 2
Dim Ns As String * 1 , Ew As String * 1 , Dw As String * 6
Dim Przecinek As Byte , P As Byte
Dim Run As Byte , Gpgga As Byte , Cntr As Byte , Tudr As Byte , Ok As Bit
Dim Longitude1 As Single
Dim Latitude1 As Single
Dim Longitude1x As Single
Dim Latitude1x As Single
Dim Latx As Word , Longy As Word

Dim Tanda As Integer
Dim Hp As String * 30

Run = 1 : Reset Ok

P = 1
Tanda = 0


Hp = "085726496643"                                         'no HP yang dituju / Target

Ddra.7 = 1

'cdi
Ddra.6 = 1


Cls
Cursor Off

Start Adc


Passwd:
Tanda = 0
On Urxc Uart_rx
Enable Urxc
Enable Interrupts


Porta.6 = 1
Porta.7 = 1

Atas:
Do

While Ok = 0 : Wend

Reset Ok

X = Getadc(0)
Y = Getadc(1)
Z = Getadc(2)


Upperline
Lcd Nss : Lcd " " : Lcd Ns

Lowerline
Lcd Ews : Lcd " " : Lcd Ew


Latitude1 = Val(nss)
Latitude1 = Latitude1 * 100
'Latx = Latitude1

Longitude1 = Val(ews)
Longitude1 = Longitude1 * 100
'Longy = Longitude1


If X > 365 Or X < 310 Then
Goto Kirim
Elseif Y > 365 Or Y < 310 Then
Goto Kirim
End If

Pas1 = Getadc(3)
Pas2 = Getadc(4)
Pas3 = Getadc(5)

'Upperline
'Lcd Pas1 ; " " ; Pas2 ; " " ; Pas3

If Pas1 < 100 And A = 0 Then
Waitms 200

Cls
Upperline
Lcd "Simpan koordinat"
Wait 2
Cls

Simpanlatup = Latitude1 + 10
Simpanlatbot = Latitude1 - 10

Simpanlongup = Longitude1 + 10
Simpanlongbot = Longitude1 - 10

Upperline
Lcd Simpanlatup
Lowerline
Lcd Simpanlatbot

Wait 2

Cls

Upperline
Lcd Simpanlongup
Lowerline
Lcd Simpanlongbot

Wait 2
Cls

Tanda = 1
A = 1
Goto Atas
End If


If Pas2 < 100 And A = 1 Then
Waitms 200
A = 2
End If

If Pas3 < 100 And A = 2 Then
Waitms 200
A = 3
End If

If Pas1 < 100 And A = 3 Then
Waitms 200

Cls
A = 0
Goto Main

End If



If Latitude1 > Simpanlatup And Tanda = 1 Then
Goto Kirimx
Elseif Latitude1 > 1 And Latitude1 < Simpanlatbot And Tanda = 1 Then
Goto Kirimx
End If

If Longitude1 > Simpanlongup And Tanda = 1 Then
Goto Kirimx
Elseif Longitude1 > 1 And Longitude1 < Simpanlongbot And Tanda = 1 Then
Goto Kirimx
End If


Waitms 200

Loop





Main:
Do

X = Getadc(0)
Y = Getadc(1)
Z = Getadc(2)

Upperline
Lcd "x = " ; X ; "  " ; "y = " ; Y
Lowerline
Lcd "z = " ; Z


Waitms 200

Loop




Kirim:
Print #2 , "AT+CMGS=" ; Hp
Wait 1
Print #2 , "Motor dalam keadaan bahaya!!!"
Print #2 , Chr(26)
Wait 1

Porta.6 = 0
Porta.7 = 0

Goto Terima

Return



Kirimx:

Longitude1x = Longitude1 / 100
Latitude1x = Latitude1 / 100

Print #2 , "AT+CMGS=" ; Hp
Wait 1
Print #2 , Latitude1x ; " " ; Longitude1x
Print #2 , Chr(26)
Wait 1

Porta.6 = 0
Porta.7 = 0

Goto Terima

Return




Terima:
Disable Urxc
Disable Interrupts

Cls
 Do


   Upperline
   Lcd "Siap terima"

   Input #2 , Data_masuk
   Pjg_data = Len(data_masuk)

   Cmti_pos = Instr(data_masuk , "CMTI")
   If Cmti_pos <> 0 Then
      Index_pos = Instr(data_masuk , ",")
      Incr Index_pos
      Pjg_sms_index = Pjg_data - Index_pos
      Incr Pjg_sms_index

      Sms_index = Mid(data_masuk , Index_pos , Pjg_sms_index)

      Print #2 , "AT+CMGR=" ; Sms_index ; Chr(13) ; Chr(10)

   End If



   Cmd_pos = Instr(data_masuk , "#")
   If Cmd_pos <> 0 Then
      Incr Cmd_pos
      Cmd = Mid(data_masuk , Cmd_pos , 1)

         If Cmd = "L" Then
         Porta.6 = 1
         Goto Passwd
         End If

      Print #2 , "AT+CMGD=" ; Sms_index ; Chr(13) ; Chr(10)

   End If
Loop





Uart_rx:

If Run <> 0 Then

Run = Udr Xor 36

If Run = 0 Then

Cntr = 0

Nss = ""

Ews = ""

Sat = ""

Ns = ""

Ew = ""

Dw = ""


Hh = ""

Mm = ""

Ss = ""

End If


Else

Select Case Cntr

Case 0 To 4

Tudr = Lookup(cntr , Gga)
'untuk memilih data pada baris "GPGGA"

Run = Udr Xor Tudr

Case 6 To 7
Hh = Hh + Chr(udr)
'UTC Time: "Hour"

Case 8 To 9
Mm = Mm + Chr(udr)
'UTC Time: "minutes"

Case 10 To 11

Ss = Ss + Chr(udr)
'UTC Time: "seconds"

Case 17 To 25

Nss = Nss + Chr(udr)


Case 27

Ns = Ns + Chr(udr)
'stuff latitude flag

Case 29 To 38

Ews = Ews + Chr(udr)
'longitude

Case 40

Ew = Ew + Chr(udr)
'stuff longitude flag

Case 44 To 45

Sat = Sat + Chr(udr)

Case 51 To 54

Dw = Dw + Chr(udr)

Case 55

Set Ok : Run = 1

Case Else

Tudr = Udr

End Select

Incr Cntr

End If

Return



'GPS statement, the head of ASCII code

Gga:

Data 71 , 80 , 71 , 71 , 65                                 'GPGGA

Vtg:

Data 71 , 80 , 86 , 84 , 71                                 'GPVTG

Rmc:

Data 71 , 80 , 82 , 77 , 67                                 'GPRMC






g. Program Tracking System GPS

'program ini akan mengirimkan koordinat tiap 20 detik sekali

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

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

Config Adc = Single , Prescaler = Auto , Reference = Avcc

Config Com1 = 4800 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Com2 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0

Open "com1:" For Binary As #1
Open "Com2:" For Binary As #2

Dim X As Word
Dim Y As Word
Dim Z As Word
Dim A As Integer
A = 0

Dim Pas1 As Word
Dim Pas2 As Word
Dim Pas3 As Word

Dim Data_masuk As String * 100
Dim Cmti_pos As Byte , Cmgr_pos As Byte , Index_pos As Byte , Cmd_pos As Byte
Dim Pjg_sms_index As Byte , Pjg_data As Byte
Dim Sms_index As String * 3
Dim Cmd As String * 4
Dim Cmdbin As Byte
Dim Simpanlatup As Single
Dim Simpanlatbot As Single
Dim Simpanlongup As Single
Dim Simpanlongbot As Single
Dim Ews As String * 10 , Nss As String * 8 , Sat As String * 2
Dim Nssx As String * 8
Dim Hh As String * 2 , Hh2 As Byte , Mm As String * 2 , Ss As String * 2
Dim Ns As String * 1 , Ew As String * 1 , Dw As String * 6
Dim Przecinek As Byte , P As Byte
Dim Run As Byte , Gpgga As Byte , Cntr As Byte , Tudr As Byte , Ok As Bit
Dim Longitude1 As Single
Dim Latitude1 As Single
Dim Longitude1x As Single
Dim Latitude1x As Single
Dim Latx As Word , Longy As Word

Dim Tanda As Integer
Dim Mark As Integer
Dim Hp As String * 30

Dim Count As Integer
Dim Zona As Integer
Count = 0
Zona = 0

Run = 1 : Reset Ok

P = 1
Tanda = 0


Hp = "085726496643"                                         'no HP yang dituju / Target

Ddrb.5 = 1
Ddrb.6 = 1
Ddrb.7 = 1

'cdi
Ddra.6 = 1

Ddrd.4 = 1
Ddrd.5 = 1
Ddrd.6 = 1
Ddrd.7 = 1

Cls
Cursor Off

Start Adc

Mark = 0

Passwd:
Tanda = 0

Portb.5 = 1
Portb.6 = 1
Portb.7 = 1
Portd.5 = 1

Porta.6 = 1
Porta.7 = 1

Portd.6 = 1
Portd.7 = 1

Atas:

On Urxc Uart_rx
Enable Urxc
Enable Interrupts

Do

While Ok = 0 : Wend

Reset Ok

X = Getadc(0)
Y = Getadc(1)
Z = Getadc(2)

Upperline
Lcd Nss : Lcd " " : Lcd Ns

Lowerline
Lcd Ews : Lcd " " : Lcd Ew

Latitude1 = Val(nss)
Latitude1 = Latitude1 * 100
'Latx = Latitude1

Longitude1 = Val(ews)
Longitude1 = Longitude1 * 100
'Longy = Longitude1

If X > 365 Or X < 310 Then
Mark = 1
Elseif Y > 365 Or Y < 310 Then
Mark = 1
End If

Pas1 = Getadc(3)
Pas2 = Getadc(4)
Pas3 = Getadc(5)

'Upperline
'Lcd Pas1 ; " " ; Pas2 ; " " ; Pas3

If Pas1 < 100 And A = 0 Then
Waitms 200

Cls
Upperline
Lcd "Simpan koordinat"
Wait 2
Cls

Simpanlatup = Latitude1 + 10
Simpanlatbot = Latitude1 - 10

Simpanlongup = Longitude1 + 10
Simpanlongbot = Longitude1 - 10

Upperline
Lcd Simpanlatup
Lowerline
Lcd Simpanlatbot

Wait 2

Cls

Upperline
Lcd Simpanlongup
Lowerline
Lcd Simpanlongbot

Wait 2
Cls

Tanda = 1
A = 1
Goto Atas
End If


If Pas2 < 100 And A = 1 Then
Waitms 200
A = 2
End If

If Pas3 < 100 And A = 2 Then
Waitms 200
A = 3
End If

If Pas1 < 100 And A = 3 Then
Waitms 200

Cls
A = 0
Goto Main

End If

If Latitude1 > Simpanlatup And Tanda = 1 Then
Mark = 1
Elseif Latitude1 > 1 And Latitude1 < Simpanlatbot And Tanda = 1 Then
Mark = 1
End If

If Longitude1 > Simpanlongup And Tanda = 1 Then
Mark = 1
Elseif Longitude1 > 1 And Longitude1 < Simpanlongbot And Tanda = 1 Then
Mark = 1
End If

Waitms 200

Incr Count

If Count > 100 Then
Count = 0
End If

If Mark = 1 And Zona = 1 And Count = 100 Then

Longitude1x = 0
Latitude1x = 0

Longitude1x = Longitude1 / 100
Latitude1x = Latitude1 / 100

Print #2 , "AT+CMGS=" ; Hp
Wait 1
Print #2 , "Motor dalam keadaan bahaya!!!"
Print #2 , Longitude1x ; " " ; Latitude1x
Print #2 , Chr(26)
Wait 1

End If

If Mark = 1 And Zona = 0 Then
Zona = 1

Longitude1x = 0
Latitude1x = 0

Longitude1x = Longitude1 / 100
Latitude1x = Latitude1 / 100

Print #2 , "AT+CMGS=" ; Hp
Wait 1
Print #2 , "Motor dalam keadaan bahaya!!!"
Print #2 , Longitude1x ; " " ; Latitude1x
Print #2 , Chr(26)
Wait 1

Porta.6 = 0
Porta.7 = 0

End If

Loop

Main:
Do

X = Getadc(0)
Y = Getadc(1)
Z = Getadc(2)

Upperline
Lcd "x = " ; X ; "  " ; "y = " ; Y
Lowerline
Lcd "z = " ; Z

Waitms 200

Loop

Terima:
'Disable Urxc

Cls
 Do

   Upperline
   Lcd "Siap terima"

   Input #2 , Data_masuk
   Pjg_data = Len(data_masuk)

   Cmti_pos = Instr(data_masuk , "CMTI")
   If Cmti_pos <> 0 Then
      Index_pos = Instr(data_masuk , ",")
      Incr Index_pos
      Pjg_sms_index = Pjg_data - Index_pos
      Incr Pjg_sms_index

      Sms_index = Mid(data_masuk , Index_pos , Pjg_sms_index)

      Print #2 , "AT+CMGR=" ; Sms_index ; Chr(13) ; Chr(10)

   End If

   Cmd_pos = Instr(data_masuk , "#")
   If Cmd_pos <> 0 Then
      Incr Cmd_pos
      Cmd = Mid(data_masuk , Cmd_pos , 1)

         If Cmd = "L" Then
         Porta.6 = 1
         Goto Passwd
         End If

      Print #2 , "AT+CMGD=" ; Sms_index ; Chr(13) ; Chr(10)

   End If
Loop

Uart_rx:

If Run <> 0 Then

Run = Udr Xor 36

If Run = 0 Then

Cntr = 0

Nss = ""

Ews = ""

Sat = ""

Ns = ""

Ew = ""

Dw = ""


Hh = ""

Mm = ""

Ss = ""

End If


Else

Select Case Cntr

Case 0 To 4

Tudr = Lookup(cntr , Gga)
'untuk memilih data pada baris "GPGGA"

Run = Udr Xor Tudr

Case 6 To 7
Hh = Hh + Chr(udr)
'UTC Time: "Hour"

Case 8 To 9
Mm = Mm + Chr(udr)
'UTC Time: "minutes"

Case 10 To 11

Ss = Ss + Chr(udr)
'UTC Time: "seconds"

Case 17 To 25

Nss = Nss + Chr(udr)


Case 27

Ns = Ns + Chr(udr)
'stuff latitude flag

Case 29 To 38

Ews = Ews + Chr(udr)
'longitude

Case 40

Ew = Ew + Chr(udr)
'stuff longitude flag

Case 44 To 45

Sat = Sat + Chr(udr)

Case 51 To 54

Dw = Dw + Chr(udr)

Case 55

Set Ok : Run = 1

Case Else

Tudr = Udr

End Select

Incr Cntr

End If

Return



'GPS statement, the head of ASCII code

Gga:

Data 71 , 80 , 71 , 71 , 65                                 'GPGGA

Vtg:

Data 71 , 80 , 86 , 84 , 71                                 'GPVTG

Rmc:

Data 71 , 80 , 82 , 77 , 67                                 'GPRMC






i. Downloader Software ( Extreme Burner )





j. Cara Sambung Modem Wavecom Ke MCU + RS232







k. VIDEO HASILNYA











Monitoring Gas Menggunakan Internet Web Server dan Arduino + Ethernet

Monitoring Gas Menggunakan Internet Web Server dan Arduino + Ethernet


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat monitoring gas via internet, jadi data yang didapat oleh Arduino dikirimkan ke server online melalui media internet dan router. Data yang dikirimkan adalah data berupa gas yang akan disimpan di hosting server / MySQL Database dan akan ditampilkan melalui HTML / PHP. untuk lebih jelasnya berikut adalah program dan skema alatnya.



a. Arduino UNO + Ethernet Shield




b. Router Support Modem




c. Sensor Gas





d. Program Arduino IDE

#include <SPI.h>
#include <Ethernet.h>

String txData2="";

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  char server[] = "www.monitoring-udara.hol.es";
IPAddress ip(192,168,0,99);

EthernetClient client;

void setup() {
   
  Serial.begin(9600);
  while (!Serial) {
    ;
  }

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    Ethernet.begin(mac, ip);
  }

    delay(1000);
    Serial.println("connecting...");
    kirim ();
   
  }

void loop()
{      
  kirim ();
}


void kirim (){

  int voltage0 = analogRead(A0);

  EthernetClient client;
 
if (client.connect(server, 80)){
    txData2 = "voltage0="+ (String (voltage0));            
    Serial.println("connected");
    Serial.print(txData2);
    client.println("POST /insert.php HTTP/1.1");
    client.println("Host: www.monitoring-udara.hol.es");
    client.println("Connection: close");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(txData2.length());
    client.print("\n\n");
    client.print(txData2);
    Serial.println(txData2);     
    delay (1000);
         
  }   
  else{
    Serial.println("Connection Failed."); 
    Serial.println();
    delay (1500);
  }
}


e. config.php

<?php

$dbhost = 'mysql.idhostinger.com';
$dbuser = 'u76xxxx_local';
$dbpass = '12345';   
$dbname = 'u76xxxx_udara';

$conn = @mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
if(!$conn){
        echo "database gak konek";
    }else{

    }
?>



f. insert.php

<?php
require("config.php");

$query = "INSERT INTO tbudara (voltage0) VALUES('$_POST[voltage0]')";


if(!@mysql_query($query))
{
    echo "&Answer; SQL Error - ".mysql_error();
    return;
}

?>




g. index.php

<html>
<head>
<meta http-equiv="refresh" content="3">
<style>
.bordered { border-style:solid; }
</style>
<link rel="stylesheet" type="text/css" href="latweb.css" />
<title >MONITORING UDARA</title>
</head>
<body>

<CENTER>
<p><h2> MONITORING UDARA</h2></p>

<br>
<input type="button" onclick="location.href='http://monitoring-udara.hol.es/dbshow.php';" value="Lihat Database" />
<br>
</CENTER>

<CENTER>
<p><h3>

Konsentrasi GAS CO =
<?php
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbudara WHERE no IN (SELECT MAX(no) FROM tbudara)");
         
    while ($r=mysql_fetch_array($tampil)){
       echo "$r[voltage0]";
   }
?>

</CENTER>

</body>

</html>




h. dbshow.php

<html>
<head>
<meta http-equiv="refresh" content="3">
<style>
.bordered { border-style:solid; }
</style>
<title >DATABASE</title>
</head>
<body bgcolor = #ffaaff>

<CENTER>
<p><h2> DATABASE MONITORING UDARA</h2></p>

<br>
<input type="button" onclick="location.href='http://monitoring-udara.hol.es/index.php';" value=" HOME " />
<br>
<br>
<br>

<?php
include "config.php";

$tampil = mysql_query("SELECT * FROM tbudara");

 echo "<table border = '1'>
          <tr><th bgcolor = #C87C5B>GAS CO</th></tr>";
  
    while ($r=mysql_fetch_array($tampil)){
       echo "<tr>
             <td bgcolor = #FFC848>$r[voltage0]</td></tr>";
    }
    echo "</table>";

@mysql_close($con);

?>

</CENTER>
</body>
</html>




i. pragram menampilkan jam tanggal (java script)

<script type='text/javascript'>
<!--
var months = ['Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'];
var myDays = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jum&#39;at', 'Sabtu'];
var date = new Date();
var day = date.getDate();
var month = date.getMonth();
var thisDay = date.getDay(),
    thisDay = myDays[thisDay];
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
document.write(thisDay + ', ' + day + ' ' + months[month] + ' ' + year);
//-->
</script>

<br>

<script type="text/javascript">
<!--
var a_p = "";
var d = new Date();
var curr_hour = d.getHours();
if (curr_hour < 12) {
    a_p = "AM";
} else {
    a_p = "PM";
}
if (curr_hour == 0) {
    curr_hour = 12;
}
if (curr_hour > 12) {
    curr_hour = curr_hour - 12;
}

var curr_min = d.getMinutes();
curr_min = curr_min + "";
if (curr_min.length == 1) {
    curr_min = "0" + curr_min;
}
document.write(curr_hour + " : " + curr_min + " " + a_p);
//-->
</script>




j. Contoh Program PHP untuk menghasilkan tampilan koma di index.php

wind speed =
<?php
$a=100;
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbgas WHERE no IN (SELECT MAX(no) FROM tbgas)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r[value1]/$a;
   }
?>



k. Contoh Program Parsing PHP dengan If else

wind direction =
<?php
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbgas WHERE no IN (SELECT MAX(no) FROM tbgas)");
        
    while ($r=mysql_fetch_array($tampil)){

       $b = $r[value2];

if ($r[value2] == 1) {
    echo "NORTH";
}
elseif ($r[value2] == 2) {
    echo "NORTH EAST";
}
elseif ($r[value2] == 3) {
    echo "EAST";
}
elseif ($r[value2] == 4) {
    echo "SOUTH EAST";
}
elseif ($r[value2] == 5) {
    echo "SOUTH";
}
elseif ($r[value2] == 6) {
    echo "SOUTH WEST";
}
elseif ($r[value2] == 7) {
    echo "WEST";
}
elseif ($r[value2] == 8) {
    echo "NORTH WEST";
}


   }
?>





l. Gambar Hasilnya














TUTORIAL BASIC STAMP ADC , LCD 16x2 , LED I/O DAN SENSOR JARAK PING)))

TUTORIAL BASIC STAMP ADC , LCD 16x2 , LED I/O DAN SENSOR JARAK PING)))


            Pada kesempatan yang berbahagia kali ini saya akan menjelaskan mengenai project baru saya yaitu mengenai BASIC STAMP, ada banyak tipe dari mikrokontroller ini, pada tutorial kali ini saya menggunakan Basic Stamp BS2P40 buatan parallax. Kelebihan dari mikrokontroller Basic Stamp ini dibanding mikrokontroller ATMega yaitu kecepatan clocknya. Basic Stamp bisa memiliki kecepatan Clock hingga 20MHz. sehingga untuk pemprosesan sinyal bisa diandalkan. Namun kekurangan mikrokontroller ini yaitu tidak adanya chip ADC sehingga menggunakan chip ADC ekseternal. Pada tutorial kali ini dibahas mengenai bagaimana cara mengakses LED I/O , LCD 16x2 dan Sensor Jarak PING))). berikut adalah skema dan programnya.




a. Basic Stamp BS2P40




b. LED




c. LCD 16x2




d. Sensor Jarak PING)))




e. ADC 8 Bit ( IC ADC0831 )




f. Program I/O Led

    ' {$STAMP BS2p}    ‘A directive to the Stamp that you are Using the Basic Stamp 2
    ' {$PBASIC 2.5}

    Top:             'This is a label that allows you TO refer TO this label later ON in the ‘program.
    HIGH 0         'Set PIN one TO logic HIGH 5 volts
    PAUSE 1500     'PAUSE the program FOR 1 & 1/2 seconds
    LOW 0         'Set the PIN 0 TO LOW OR logic LOW 0 volts.
    PAUSE 1500     'PAUSE program FOR 1 & 1/2 seconds
    GOTO Top        'RETURN TO the label “Top:”




g. Program LCD 16x2 + Sensor Jarak PING )))

' LCDINIT.bsp
' This program demonstrates initialization and printing on a 2 x 16
' character LCD display. The set of "LCD constants", below, are provided
' as pre-defined and useful LCD commands, though not all are actually
' used in this program.

' {$STAMP BS2p}
' {$PBASIC 2.5}

#IF ($STAMP < BS2P) #THEN
  #ERROR "Program requires BS2p, BS2pe or BS2px."
#ENDIF

CmConstant    CON   2260
InConstant    CON   890
cmDistance  VAR   Word
inDistance  VAR   Word
time        VAR   Word

Lcd             PIN     0

LcdCls          CON     $01     ' clear the LCD
LcdHome         CON     $02     ' move cursor home
LcdCrsrL        CON     $10     ' move cursor left
LcdCrsrR        CON     $14     ' move cursor right
LcdDispL        CON     $18     ' shift chars left
LcdDispR        CON     $1C     ' shift chars right
LcdDDRam        CON     $80     ' Display Data RAM
LcdCGRam        CON     $40     ' Character Generator RAM
LcdLine1        CON     $80     ' DDRAM address of line 1
LcdLine2        CON     $C0     ' DDRAM address of line 2


Init_LCD:
  PAUSE 1000                    ' allow LCD to self-initialize first
  LCDCMD Lcd, 110000         ' send wakeup sequence to LCD
  PAUSE 5                       ' pause required by LCD specs
  LCDCMD Lcd, 110000
  PAUSE 0                       ' pause required by LCD specs
  LCDCMD Lcd, 110000
  PAUSE 0                       ' pause required by LCD specs
  LCDCMD Lcd, 100000         ' set data bus to 4-bit mode
  LCDCMD Lcd, 101000         ' set to 2-line mode with 5x8 font
  LCDCMD Lcd, 001100         ' display on without cursor
  LCDCMD Lcd, 000110         ' auto-increment cursor

Main:
  LCDCMD Lcd, LcdCls
  DO

  PULSOUT 15, 5
  PULSIN 15, 1, time
  cmDistance = cmConstant ** time
  inDistance = inConstant ** time
'  DEBUG HOME, DEC3 cmDistance, " cm"
'  DEBUG CR, DEC3 inDistance, " in"
  PAUSE 100

    'LCDOUT Lcd, LcdCls, [DEC3 cmDistance]
    LCDOUT Lcd, LcdLine1, ["Jarak = "]
    LCDOUT Lcd, LcdLine1 + 8 , [DEC3 inDistance]
    LCDOUT Lcd, LcdLine1 + 11 ,[" cm"]

    LCDOUT Lcd, LcdLine2, ["Berat = "]

       PAUSE 200
   ' LCDCMD Lcd, LcdCls
   ' PAUSE 500
  LOOP
  END




h. Program ADC0831 (ADC) + PING))) + LCD
 
' LCDINIT.bsp
' This program demonstrates initialization and printing on a 2 x 16
' character LCD display. The set of "LCD constants", below, are provided
' as pre-defined and useful LCD commands, though not all are actually
' used in this program.

' {$STAMP BS2p}
' {$PBASIC 2.5}

#IF ($STAMP < BS2P) #THEN
  #ERROR "Program requires BS2p, BS2pe or BS2px."
#ENDIF

CmConstant    CON   2260
InConstant    CON   890
cmDistance  VAR   Word
inDistance  VAR   Word
time        VAR   Word

Lcd             PIN     0
CS              PIN     14                       ' chip select
AData           PIN     12                       ' data pin
Clk             PIN     13                       ' clock pin

Berat          VAR     Byte                    ' ADC result


LcdCls          CON     $01     ' clear the LCD
LcdHome         CON     $02     ' move cursor home
LcdCrsrL        CON     $10     ' move cursor left
LcdCrsrR        CON     $14     ' move cursor right
LcdDispL        CON     $18     ' shift chars left
LcdDispR        CON     $1C     ' shift chars right
LcdDDRam        CON     $80     ' Display Data RAM
LcdCGRam        CON     $40     ' Character Generator RAM
LcdLine1        CON     $80     ' DDRAM address of line 1
LcdLine2        CON     $C0     ' DDRAM address of line 2

Setup:
  HIGH CS                                       ' deselect ADC


Init_LCD:
  PAUSE 1000                    ' allow LCD to self-initialize first
  LCDCMD Lcd, 110000         ' send wakeup sequence to LCD
  PAUSE 5                       ' pause required by LCD specs
  LCDCMD Lcd, 110000
  PAUSE 0                       ' pause required by LCD specs
  LCDCMD Lcd, 110000
  PAUSE 0                       ' pause required by LCD specs
  LCDCMD Lcd, 100000         ' set data bus to 4-bit mode
  LCDCMD Lcd, 101000         ' set to 2-line mode with 5x8 font
  LCDCMD Lcd, 001100         ' display on without cursor
  LCDCMD Lcd, 000110         ' auto-increment cursor

Main:
  LCDCMD Lcd, LcdCls
  DO

    LOW CS                                      ' activate the ADC0831
    SHIFTIN AData, Clk, MSBPOST, [Berat\9]     ' shift in the data
    HIGH CS

  PULSOUT 15, 5
  PULSIN 15, 1, time
  cmDistance = cmConstant ** time
  inDistance = inConstant ** time
'  DEBUG HOME, DEC3 cmDistance, " cm"
'  DEBUG CR, DEC3 inDistance, " in"
  PAUSE 100

    'LCDOUT Lcd, LcdCls, [DEC3 cmDistance]
    LCDOUT Lcd, LcdLine1, ["Jarak = "]
    LCDOUT Lcd, LcdLine1 + 8 , [DEC3 inDistance]
    LCDOUT Lcd, LcdLine1 + 11 ,[" cm"]

    LCDOUT Lcd, LcdLine2, ["Berat = "]
    LCDOUT Lcd, LcdLine2 + 8 , [DEC3 Berat ]
    LCDOUT Lcd, LcdLine2 + 11, [" kg"]

    PAUSE 200
   ' LCDCMD Lcd, LcdCls
  LOOP
  END




i. VIDEO HASILNYA
 

 












Membuat Aplikasi Monitoring Tegangan Dengan DELPHI 7 + Database Ms. Access dan ARDUINO

Membuat Aplikasi Monitoring Tegangan Dengan DELPHI 7 + Database Ms. Access dan ARDUINO


          Kali ini saya akan menjelaskan mengenai bagaimana cara membuat software delphi sebagai interface untuk menampilkan data yang dikirimkan oleh Arduino, jadi aplikasi ini hanyalah untuk menampilkan data saja berupa nilai dan grafik real time, selain itu data yang masuk ke grafik akan disimpan ke database Ms. Access dengan time sampling tiap 1 detik. yang perlu diperhatikan disini yaitu bagaimana cara mengkonfigurasikan Ms. Access dan Delphi agar terkoneksi dengan baik dan juga bagaimana install comport agar data dari Arduino bisa tampil di Delphi 7. untuk program dan skemanya dapat dilihat dipenjelasan dibawah ini.



a. Arduino UNO




b. Program Arduino IDE

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  int sensorValue1 = analogRead(A1);
 
  // print out the value you read:
  Serial.print(sensorValue),Serial.println ('a');
  Serial.print(sensorValue1),Serial.println ('b');
 
  delay(100);        // delay in between reads for stability
}



c. Program Delphi 7







unit TA;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,strutils, TeeProcs, TeEngine, Chart, CPort, mmsystem,
  Series, Buttons, DB, ADODB, Grids, DBGrids, DBCtrls;

type
  TForm1 = class(TForm)
    ComPort1: TComPort;
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Chart1: TChart;
    Shape1: TShape;
    Shape2: TShape;
    GroupBox2: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    Label7: TLabel;
    Label8: TLabel;
    GroupBox4: TGroupBox;
    Edit3: TEdit;
    Edit4: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    BitBtn1: TBitBtn;
    Chart2: TChart;
    Series1: TFastLineSeries;
    Series2: TFastLineSeries;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    Timer2: TTimer;
    procedure ComPort1RxChar(Sender: TObject; Count: Integer);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Memo1Change(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
var buff:string;
begin
comport1.ReadStr(buff,count);
memo1.Text:=memo1.Text+buff;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
comport1.ShowSetupDialog;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if button2.Caption='Connect' then
   begin
   button2.Caption:='Disconnect';
   comport1.Open;
   Timer2.Enabled := True;
   end
else if button2.Caption='Disconnect' then
   begin
   button2.Caption:='Connect';
   comport1.Close;
   end;

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Edit1.Color:=clwhite;
Edit2.Color:=clwhite;
edit1.text:='';
edit2.text:='';
memo1.Text:='';
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ThousandSeparator:=',';
DecimalSeparator:='.';
end;

procedure TForm1.Memo1Change(Sender: TObject);
var ruang,kulit:double;
    rin,kin:string;
    jumlahdata:integer;

begin
  shape1.Brush.Color:=clgreen;
  shape2.Brush.Color:=clgreen;
  jumlahdata:=chart1.GetMaxValuesCount;
  form1.Caption:=inttostr(jumlahdata);
  if jumlahdata =10000 then
     begin
     Series1.Clear;
     Series2.Clear;
     end;

  rin:=memo1.Lines[memo1.Lines.count-2];
  kin:=memo1.Lines[memo1.Lines.count-1];

  if rightstr(rin,1)= 'a' then
     begin
     edit1.Text:=leftstr(rin,length(rin)-1);
     ruang:=strtoint(edit1.text);
     Series1.Add(ruang,'',clred) ;
     shape1.Brush.Color:=clred;
     end;
  if rightstr(kin,1)='b' then
     begin
     edit2.Text:=leftstr(kin,length(kin)-1);
     kulit:=strtoint(edit2.text);
     Series2.Add(kulit,'',clgreen) ;
     shape2.Brush.Color:=clred;
     end;


end;


procedure TForm1.Edit1Change(Sender: TObject);
var ruang:double;
begin
ruang:=strtoint(edit1.text);
if ruang<30 then
   begin
   edit1.Color:=clblue;
   edit3.text:= 'Lembab';
   end;
if ruang>31 then
   begin
   edit1.Color:=clred;
   edit3.text:= 'Kering';
   end;
if (ruang>=31) and (ruang<=30) then
   begin
   edit1.Color:=clwhite;
   edit3.text:= 'Normal';
   end;
end;


procedure TForm1.Edit2Change(Sender: TObject);
var kulit:double;
begin
kulit:=strtoint(edit2.text);
if kulit<60 then
   begin
   edit2.Color:=clblue;
   edit4.text:= 'Kering';
   end;
if kulit>61 then
   begin
   edit2.Color:=clred;
   edit4.text:= 'Lembab';
   end;
if (kulit>=61) and (kulit<=60) then
   begin
   edit2.Color:=clwhite;
   edit4.text:= 'Normal';
   end;
end;



procedure TForm1.Timer1Timer(Sender: TObject);
begin
label7.Caption:='Date  '+ FormatdateTime('d/mm/yyyy',Date);
label8.Caption:='Time  '+ FormatDateTime('hh:nn:ss',Time);
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
adotable1.Append;
adotable1.Fields.FieldByName ('Data').Text:=edit1.Text;
adotable1.Fields.FieldByName ('Duty').Text:=edit2.Text;

adotable1.Post;
end;

end.



d. Database Ms. Access 




e. Cara Penggunaan Alat

             Untuk menggunakan alat ini pertama yaitu aktifkan program Arduino dan Upload program diatas. Buat Interface delphi 7 seperti diatas dan masukan programnya, jangan lupa install comport yang sesuai agar bisa berkomunikasi dengan Arduino. jika berhasil maka akan tampil data yang diinginkan ke interface Delphi 7 dan juga data akan tersimpan rapi dalam database.