Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat dan mengakses sebuah robot yang dapat dikendalikan menggunakan komputer / laptop via wireless, jadi robot ini menggunakan GUI interface yang terdapat di komputer yang mana fungsinya adalah untuk kendali arah jalan robot, fitur yang tersedia pada GUI interface VB 6 adalah jalan lurus, mundur, stop, belok kanan, dan belok kiri. driver motor yang digunakan adalah L298 dan wireless modulnya menggunakan NRF24L01, prinsip kerjanya yaitu transmitter mengirimkan kode berupa angka 1 samapi 5 sehingga pihak receiver akan menangkap data tersebut dan akan mengolah data itu, outputnya adalah kendali roda pada robot. untuk lebih jelasnya berikut adalah skema dan programnya.
a. Arduino Uno
b. Wireless Modul NRF24L01
- Connect the following pins to your Arduino:
- Pin 9 - CE
- Pin 10 - CS(N)
- Pin 11 - MOSI
- Pin 12 - MISO
- Pin 13 - SCK
- 3.3v - VCC
- GND - GND
c. Driver Motor L298
d. Program Receiver Arduino IDE
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int mtr1 = A5;
int mtr2 = A4;
int mtr3 = A3;
int mtr4 = A2;
void setup(void){
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
pinMode(mtr1, OUTPUT);
pinMode(mtr2, OUTPUT);
pinMode(mtr3, OUTPUT);
pinMode(mtr4, OUTPUT);
}
void loop(void){
if (radio.available()){
bool done = false;
while (!done){
done = radio.read(msg, 1);
Serial.println(msg[0]);
if (msg[0] == 1){
delay(10);
digitalWrite(mtr1, HIGH);
digitalWrite(mtr2, LOW);
digitalWrite(mtr3, HIGH);
digitalWrite(mtr4, LOW);
delay(200);
}
if (msg[0] == 2){
delay(10);
digitalWrite(mtr1, HIGH);
digitalWrite(mtr2, LOW);
digitalWrite(mtr3, LOW);
digitalWrite(mtr4, LOW);
delay(200);
}
if (msg[0] == 3){
delay(10);
digitalWrite(mtr1, LOW);
digitalWrite(mtr2, LOW);
digitalWrite(mtr3, HIGH);
digitalWrite(mtr4, LOW);
delay(200);
}
if (msg[0] == 4){
delay(10);
digitalWrite(mtr1, LOW);
digitalWrite(mtr2, HIGH);
digitalWrite(mtr3, LOW);
digitalWrite(mtr4, HIGH);
delay(200);
}
if (msg[0] == 5){
delay(10);
digitalWrite(mtr1, LOW);
digitalWrite(mtr2, LOW);
digitalWrite(mtr3, LOW);
digitalWrite(mtr4, LOW);
delay(200);
}
delay(10);
}
}
else{
Serial.println("No radio available");
}
}
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int mtr1 = A5;
int mtr2 = A4;
int mtr3 = A3;
int mtr4 = A2;
void setup(void){
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
pinMode(mtr1, OUTPUT);
pinMode(mtr2, OUTPUT);
pinMode(mtr3, OUTPUT);
pinMode(mtr4, OUTPUT);
}
void loop(void){
if (radio.available()){
bool done = false;
while (!done){
done = radio.read(msg, 1);
Serial.println(msg[0]);
if (msg[0] == 1){
delay(10);
digitalWrite(mtr1, HIGH);
digitalWrite(mtr2, LOW);
digitalWrite(mtr3, HIGH);
digitalWrite(mtr4, LOW);
delay(200);
}
if (msg[0] == 2){
delay(10);
digitalWrite(mtr1, HIGH);
digitalWrite(mtr2, LOW);
digitalWrite(mtr3, LOW);
digitalWrite(mtr4, LOW);
delay(200);
}
if (msg[0] == 3){
delay(10);
digitalWrite(mtr1, LOW);
digitalWrite(mtr2, LOW);
digitalWrite(mtr3, HIGH);
digitalWrite(mtr4, LOW);
delay(200);
}
if (msg[0] == 4){
delay(10);
digitalWrite(mtr1, LOW);
digitalWrite(mtr2, HIGH);
digitalWrite(mtr3, LOW);
digitalWrite(mtr4, HIGH);
delay(200);
}
if (msg[0] == 5){
delay(10);
digitalWrite(mtr1, LOW);
digitalWrite(mtr2, LOW);
digitalWrite(mtr3, LOW);
digitalWrite(mtr4, LOW);
delay(200);
}
delay(10);
}
}
else{
Serial.println("No radio available");
}
}
e. Program Transmitter Arduino IDE
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
int datain;
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
void setup(void){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
pinMode(13,OUTPUT);
}
void loop(void){
msg[0] = datain;
radio.write(msg, 1);
//Serial.println(msg[0]);
if (Serial.available() > 0)
{
datain = Serial.parseInt();
//Serial.println(datain);
}
delay(10);
}
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
int datain;
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
void setup(void){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
pinMode(13,OUTPUT);
}
void loop(void){
msg[0] = datain;
radio.write(msg, 1);
//Serial.println(msg[0]);
if (Serial.available() > 0)
{
datain = Serial.parseInt();
//Serial.println(datain);
}
delay(10);
}
f. Program VB 6
Dim arrdata()
Dim TotalBaca As Integer
Dim BMI As Single
Dim Keterangan As String
Const MAKSBACA = 10
'-----------------------------
Private Sub atas_Click()
MSComm2.Output = "1" + Chr(13) 'mengirimkan angka 1 ke serial
End Sub
'-----------------------------
Private Sub bawah_Click()
MSComm2.Output = "4" + Chr(13) 'mengirimkan angka 2 ke serial
End Sub
'-----------------------------
Private Sub berhenti_Click()
start.Enabled = True
berhenti.Enabled = False
TimerBaca.Enabled = False
End Sub
'-----------------------------
Private Sub BUZZ_Click()
MSComm2.Output = "6" + Chr(13)
End Sub
Private Sub Command1_Click()
MSComm2.Output = "5" + Chr(13)
End Sub
'-----------------------------
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Down_Click()
End Sub
'-----------------------------
Private Sub Form_Load()
Dim i As Byte
For i = 1 To 16
ComboCOM.AddItem (i)
Next i
End Sub
Private Sub kanan_Click()
MSComm2.Output = "2" + Chr(13)
End Sub
Private Sub kiri_Click()
MSComm2.Output = "3" + Chr(13)
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
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
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 TimerBaca_Timer()
Dim strInput As String
Dim strPotong As String
Dim singleInput As Single
Dim u As Integer
' strInput = MSComm2.Input
' strPotong = strInput
'Text1.Text = Text1.Text + strPotong + vbCrLf
' singleInput = Val(strPotong)
' If TotalBaca >= MAKSBACA Then
' TimerBaca.Enabled = False
' If MSComm2.PortOpen = True Then MSComm2.PortOpen = False
' Call berhenti_Click
' End If
End Sub
Dim TotalBaca As Integer
Dim BMI As Single
Dim Keterangan As String
Const MAKSBACA = 10
'-----------------------------
Private Sub atas_Click()
MSComm2.Output = "1" + Chr(13) 'mengirimkan angka 1 ke serial
End Sub
'-----------------------------
Private Sub bawah_Click()
MSComm2.Output = "4" + Chr(13) 'mengirimkan angka 2 ke serial
End Sub
'-----------------------------
Private Sub berhenti_Click()
start.Enabled = True
berhenti.Enabled = False
TimerBaca.Enabled = False
End Sub
'-----------------------------
Private Sub BUZZ_Click()
MSComm2.Output = "6" + Chr(13)
End Sub
Private Sub Command1_Click()
MSComm2.Output = "5" + Chr(13)
End Sub
'-----------------------------
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Down_Click()
End Sub
'-----------------------------
Private Sub Form_Load()
Dim i As Byte
For i = 1 To 16
ComboCOM.AddItem (i)
Next i
End Sub
Private Sub kanan_Click()
MSComm2.Output = "2" + Chr(13)
End Sub
Private Sub kiri_Click()
MSComm2.Output = "3" + Chr(13)
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
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
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 TimerBaca_Timer()
Dim strInput As String
Dim strPotong As String
Dim singleInput As Single
Dim u As Integer
' strInput = MSComm2.Input
' strPotong = strInput
'Text1.Text = Text1.Text + strPotong + vbCrLf
' singleInput = Val(strPotong)
' 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