Translate

Membuat Alat Prabayar Pulsa Air Otomatis Menggunakan Arduino Keypad Matrix 4x4 dan RFID RC522 dengan Interface VB 6.0 dan dataase Ms. Access

Membuat Alat Prabayar Pulsa Air Otomatis Menggunakan Arduino Keypad Matrix 4x4 dan RFID RC522 dengan Interface VB 6.0 dan dataase Ms. Access


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang berfungsi untuk topup pulsa air otomatis berbasis RFID jadi seperti halnya pulsa sms atau kuota internet yang harus di topup untuk penggunaannya, alat ini juga seperti itu namun aplikasinya untuk air, jadi kita membeli berapa liter air dan akan disimpan untuk ID kartu tersebut, setelah itu jika ingin membeli air hanya perlu dekatkan kartu kealat kemudian akan dikurangi oleh nilai pembelian sehingga akan tampak saldo yang tersisa. untuk lebih jelasnya berikut adalah skema dan programnya.



a. Arduino Uno




b. RFID RC-522




c. Keypad Matrik 4x4




d. LCD 16x2 + I2C






e. Program Arduino IDE

#include <SPI.h>
#include <Keypad.h>
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
LiquidCrystal_I2C lcd(0x3F, 16, 2); //library i2c lcd

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

int buzzer = 8;

char customKey;
const byte ROWS = 4;
const byte COLS = 4;
long passwd = 0;
long isiku;
long kartu1;
long kartu2;
long kartu3;
long kartu4;
int id;
long beli;

char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,A0,A1}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup()
{
  pinMode(buzzer,OUTPUT);
  digitalWrite(buzzer,LOW);
  lcd.begin(); //set lcd i2c
  lcd.noCursor(); //biar gak ada cursor di lcd
  lcd.clear(); //clear lcd
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
//  Serial.println("Put your card to the reader...");
//  Serial.println();

  delay(1000);

}


void loop()
{

  lcd.setCursor(0,0);
  lcd.print("Pilih Menu");
  lcd.setCursor(0,1);
  lcd.print("A.Isi    B.Bayar");
 
customKey = customKeypad.getKey();

    if(customKey == 'B'){
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Dekatkan Kartu");
    delay(3000);
    lcd.clear();
    isiscan();
    lcd.clear();
    beli = 0;
    bayar();
    }

    if(customKey == 'C'){
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Dekatkan Kartu");
    delay(3000);
    lcd.clear(); 
    cek();
    }
   
    if(customKey == 'A'){
    lcd.clear();
    delay(1000);
    passwd = 0;
    isi();
      lcd.setCursor(0,0);
      lcd.print("Dekatkan Kartu");
    delay(3000);
    lcd.clear();
    isiscan();
    delay(1000);
    isiku = 0;
    scan();
    } 
   
}


void cek(){
 
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
//  Serial.println("Put your card to the reader...");

  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    //return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    //return;
  }
  //Show UID on serial monitor
  //lcd.setCursor(0,0);
//  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
 //    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
 //    Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
//  Serial.println();
//  Serial.print("Message : ");
  content.toUpperCase();

  if (content.substring(1) == "C5 9C F1 29")
  {
     digitalWrite(buzzer,HIGH);
     delay(200);
     digitalWrite(buzzer,LOW);
    
      lcd.setCursor(0,0);
      lcd.print("ID=");
      lcd.print(content.substring(1));
      lcd.setCursor(0,1);
      lcd.print("Saldo=");
      lcd.print(kartu1);
      lcd.print("       ");
      delay(3000);
      lcd.clear();
      return;
  }

 if (content.substring(1) == "94 C6 77 89")
  {
     digitalWrite(buzzer,HIGH);
     delay(200);
     digitalWrite(buzzer,LOW);

      lcd.setCursor(0,0);
      lcd.print("ID=");
      lcd.print(content.substring(1));
      lcd.setCursor(0,1);
      lcd.print("Saldo=");
      lcd.print(kartu2);
      lcd.print("       ");
      delay(3000);
      lcd.clear();
      return;
  }

   if (content.substring(1) == "A3 32 48 83")
  {
     digitalWrite(buzzer,HIGH);
     delay(200);
     digitalWrite(buzzer,LOW);

      lcd.setCursor(0,0);
      lcd.print("ID=");
      lcd.print(content.substring(1));
      lcd.setCursor(0,1);
      lcd.print("Saldo=");
      lcd.print(kartu3);
      lcd.print("       ");
      delay(3000);
      lcd.clear();
      return;
  }

   if (content.substring(1) == "F7 3E B8 73")
  {
     digitalWrite(buzzer,HIGH);
     delay(200);
     digitalWrite(buzzer,LOW);

      lcd.setCursor(0,0);
      lcd.print("ID=");
      lcd.print(content.substring(1));
      lcd.setCursor(0,1);
      lcd.print("Saldo=");
      lcd.print(kartu4);
      lcd.print("       ");
      delay(3000);
      lcd.clear();
      return;
  }

  cek(); 
  }


void isi(){
 
  lcd.setCursor(0,0);
  lcd.print("Input Password");
 
customKey = customKeypad.getKey();

    if(customKey >= '0' && customKey <= '9')
    {
      passwd = passwd * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print(passwd);
    }
  
    if((customKey == 'D')&&(passwd == 112233)){
    lcd.clear();
    delay(1000);
    customKey == ' ';
    return;
    }

    if(customKey == 'C'){
    lcd.clear();
    delay(200);
    passwd = 0;
    }
  
 isi();
  }


void isiscan(){

  lcd.setCursor(0,0);
  lcd.print("Scan Kartu");
 
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
//  Serial.println("Put your card to the reader...");
 
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    //return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    //return;
  }
  //Show UID on serial monitor
  //lcd.setCursor(0,0);
//  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
 //    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
 //    Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
//  Serial.println();
//  Serial.print("Message : ");
  content.toUpperCase();

  if (content.substring(1) == "C5 9C F1 29")
  {
     digitalWrite(buzzer,HIGH);
     delay(200);
     digitalWrite(buzzer,LOW);

      lcd.setCursor(0,1);
      lcd.print(content.substring(1));
      delay(3000);
      id = 1;
      lcd.clear();
      content.substring(1) = "";
      return;
  }

 if (content.substring(1) == "94 C6 77 89")
  {
     digitalWrite(buzzer,HIGH);
     delay(200);
     digitalWrite(buzzer,LOW);

      lcd.setCursor(0,1);
      lcd.print(content.substring(1));
      delay(3000);
      id = 2;
      lcd.clear();
      content.substring(1) = "";
      return;
  }

   if (content.substring(1) == "A3 32 48 83")
  {
     digitalWrite(buzzer,HIGH);
     delay(200);
     digitalWrite(buzzer,LOW);

      lcd.setCursor(0,1);
      lcd.print(content.substring(1));
      delay(3000);
      id = 3;
      lcd.clear();
      content.substring(1) = "";
      return;
  }

   if (content.substring(1) == "F7 3E B8 73")
  {
     digitalWrite(buzzer,HIGH);
     delay(200);
     digitalWrite(buzzer,LOW);

      lcd.setCursor(0,1);
      lcd.print(content.substring(1));
      delay(3000);
      id = 4;
      lcd.clear();
      content.substring(1) = "";
      return;
  }

isiscan(); 
}



void scan(){
 
  lcd.setCursor(0,0);
  lcd.print("Isi Berapa lt?");
 
customKey = customKeypad.getKey();

    if(customKey >= '0' && customKey <= '9')
    {
      isiku = isiku * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print(isiku);
    }
  
    if(customKey == 'C'){
    lcd.clear();
    delay(200);
    isiku = 0;
    }

    if((customKey == 'D')&&(id == 1)){
    lcd.clear();
    delay(2000);
    kartu1 = isiku;
    return;
    }

    if((customKey == 'D')&&(id == 2)){
    lcd.clear();
    delay(2000);
    kartu2 = isiku;
    return;
    }

    if((customKey == 'D')&&(id == 3)){
    lcd.clear();
    delay(2000);
    kartu3 = isiku;
    return;
    }

    if((customKey == 'D')&&(id == 4)){
    lcd.clear();
    delay(2000);
    kartu4 = isiku;
    return;
    }
   
  
 scan();
  }





void bayar(){

  lcd.setCursor(0,0);
  lcd.print("Beli Berapa lt?");
 
customKey = customKeypad.getKey();

    if(customKey >= '0' && customKey <= '9')
    {
      beli = beli * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print(beli);
    }
  
    if(customKey == 'C'){
    lcd.clear();
    delay(200);
    beli = 0;
    }

    if((customKey == 'D')&&(id == 1)){
    lcd.clear();
    delay(2000);
    kartu1 = kartu1 - beli;

    if(kartu1 >= 0){
    Serial.println(id);
    Serial.println(beli);
    Serial.println(kartu1); 
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("BERHASIL");
    lcd.setCursor(0,1);
    lcd.print("SALDO=");
    lcd.print(kartu1);
    delay(5000);
    lcd.clear();
    return;
    }

    if(kartu1 < 0){
    kartu1 = kartu1 + beli; 
    lcd.setCursor(0,0);
    lcd.print("SALDO KURANG");
    lcd.setCursor(0,1);
    lcd.print("SALDO=");
    lcd.print(kartu1);
    delay(5000);
    lcd.clear();
    beli = 0;
    }

    }

    if((customKey == 'D')&&(id == 2)){
    lcd.clear();
    delay(2000);
    kartu2 = kartu2 - beli;

    if(kartu2 >= 0){
    Serial.println(id);
    Serial.println(beli);
    Serial.println(kartu2); 
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("BERHASIL");
    lcd.setCursor(0,1);
    lcd.print("SALDO=");
    lcd.print(kartu2);
    delay(5000);
    lcd.clear();
    return;
    }

    if(kartu2 < 0){
    kartu2 = kartu2 + beli; 
    lcd.setCursor(0,0);
    lcd.print("SALDO KURANG");
    lcd.setCursor(0,1);
    lcd.print("SALDO=");
    lcd.print(kartu2);
    delay(5000);
    lcd.clear();
    beli = 0;
    }

    }

    if((customKey == 'D')&&(id == 3)){
    lcd.clear();
    delay(2000);
    kartu3 = kartu3 - beli;

    if(kartu3 >= 0){
    Serial.println(id);
    Serial.println(beli);
    Serial.println(kartu3);
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("BERHASIL");
    lcd.setCursor(0,1);
    lcd.print("SALDO=");
    lcd.print(kartu3);
    delay(5000);
    lcd.clear();
    return;
    }

    if(kartu3 < 0){
    kartu3 = kartu3 + beli; 
    lcd.setCursor(0,0);
    lcd.print("SALDO KURANG");
    lcd.setCursor(0,1);
    lcd.print("SALDO=");
    lcd.print(kartu3);
    delay(5000);
    lcd.clear();
    beli = 0;
    }

    }

    if((customKey == 'D')&&(id == 4)){
    lcd.clear();
    delay(2000);
    kartu4 = kartu4 - beli;

    if(kartu4 >= 0){
    Serial.println(id);
    Serial.println(beli);
    Serial.println(kartu4);
    delay(1000);
    lcd.setCursor(0,0);
    lcd.print("BERHASIL");
    lcd.setCursor(0,1);
    lcd.print("SALDO=");
    lcd.print(kartu4);
    delay(5000);
    lcd.clear();
    return;
    }

    if(kartu4 < 0){
    kartu4 = kartu4 + beli; 
    lcd.setCursor(0,0);
    lcd.print("SALDO KURANG");
    lcd.setCursor(0,1);
    lcd.print("SALDO=");
    lcd.print(kartu4);
    delay(5000);
    lcd.clear();
    beli = 0;
    }
    }
   
  bayar();
  }



 

 f. Program Interface VB 6.0



- Module 1.bas
Public Conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public SQl As String
Public i As Byte

Public Sub dbConnect()
Set Conn = New ADODB.Connection
Conn.ConnectionString = strConn
Conn.Open
End Sub

Public Function strConn() As String
Set Conn = New ADODB.Connection
Set Rs = New ADODB.Recordset
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\yanuar\Desktop\interface\database\dbsuhu.mdb;Persist Security Info=False"

End Function



- Form 1.frm
Option Explicit
Dim arrdata()
Dim TotalBaca As Integer
Dim BMI As Single
Dim Keterangan As String
Const MAKSBACA = 15

Dim Conn1 As ADODB.Connection
Dim Cmd1 As ADODB.Command
Dim Param1 As ADODB.Parameter
Dim Rs1 As ADODB.Recordset

Private Sub berhenti_Click()
  start.Enabled = True
    berhenti.Enabled = False
    TimerBaca.Enabled = False
End Sub


Private Sub Command1_Click()
Dim SQl As String
   
   Call dbConnect
   
    SQl = "INSERT INTO tbsuhu VALUES('" & Text2(0).Text & "','" & Label4.Caption & "','" & Label2.Caption & "','" & Text2(1).Text & "','" & Text2(2).Text & "')"
   
    Dim Rs As Recordset
    Set Rs = New ADODB.Recordset
    Rs.Open SQl, Conn, adOpenDynamic

End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
Dim i As Byte
For i = 1 To 16
    ComboCOM.AddItem (i)
Next i

End Sub

Private Sub MSComm2_OnComm()
Dim buffer As String
Dim temp As String
Dim pisah() As String
Dim i As Integer

If MSComm2.CommEvent = comEvReceive Then
    buffer = MSComm2.Input
    pisah = Split(buffer, Chr$(13))
On Error Resume Next
If buffer <> " " Then
With Text1
    .SelStart = Len(.Text)
    .SelText = buffer
End With
For i = 0 To 2
    If 0 < 3 Then
        Text2(i).Text = CStr(pisah(i))
        End If
        Next i
    Else
    buffer = " "
    End If
End If
End Sub

Private Sub start_Click()
Dim u As Integer

    On Error GoTo ada_eror
   
    MSComm2.CommPort = ComboCOM.Text
    MSComm2.Settings = "9600,N,8,1"
    MSComm2.RThreshold = 15
    MSComm2.InputLen = 15
    MSComm2.InputMode = comInputModeText
    MSComm2.PortOpen = True ' buka port
   
    ReDim arrdata(1 To MAKSBACA + 1)
    For u = 1 To MAKSBACA
        arrdata(u) = 0
    Next
    TotalBaca = 0
    start.Enabled = False
    berhenti.Enabled = True
    TimerBaca.Enabled = True
    Timer1.Enabled = True
    Timer2.Enabled = True
    Timer3.Enabled = True
ada_eror:
 If ComboCOM.ListIndex < 1 Then
    MsgBox "COM berada di Nomor : " & Err.Number & vbCrLf & Err.Description, vbCritical + vbOKOnly, "ERROR"
    start.Enabled = True
    berhenti.Enabled = True
    ComboCOM.Text = "Pilih COM"
End If

End Sub

Private Sub Timer2_Timer()
Adodc1.Refresh
Dim ok As Integer
Dim mode As Integer


End Sub

Private Sub Timer3_Timer()
MSComm2_OnComm
End Sub

Private Sub Timer4_Timer()
 Label4.Caption = Format(Time, "hh:mm:ss")
 Label2.Caption = Format(Date, "dd:mm:yy")
End Sub

Private Sub TimerBaca_Timer()
Dim strInput As String
Dim strPotong As String
Dim singleInput As Single
Dim u As Integer
    strInput = MSComm2.Input
        strPotong = strInput
        If TotalBaca >= MAKSBACA Then
            TimerBaca.Enabled = False
            If MSComm2.PortOpen = True Then MSComm2.PortOpen = False
            Call berhenti_Click
        End If
 
 
 
End Sub





g. VIDEO HASILNYA







No comments:

Post a Comment