Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah robot yang fungsinya sama seperti mobil remote control mainan, yang jadi pembeda yaitu alat ini bisa dimodif sesuka hati dengan merubah program atau hardwarenya, sehingga sesuai dengan selera pengguna, robot ini menggunakan 2 buah arduino sebagai master dan slave atau transmitter dan receiver, untuk komunikasinya yaitu menggunakan modul wireless 2.4 GHz NRF24L01 sehingga jangkauannya bisa 100 meteran lebih. untuk lebih jelasnya berikut adalah skema dan programnya
a. Arduino Uno
b. Modul Wireless 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. Motor DC
e. Program Arduino Transmitter / Master
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
int datain;
int maju;
int mundur;
int kanan;
int kiri;
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
void setup(void){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
pinMode(13,OUTPUT);
pinMode(7,INPUT);
pinMode(6,INPUT);
pinMode(5,INPUT);
pinMode(4,INPUT);
digitalWrite(7,HIGH);
digitalWrite(6,HIGH);
digitalWrite(5,HIGH);
digitalWrite(4,HIGH);
}
void loop(void){
maju = digitalRead(6);
mundur = digitalRead(4);
kiri = digitalRead(5);
kanan = digitalRead(7);
if(maju == 0){
msg[0] = 1;
radio.write(msg, 1);
//Serial.println(msg[0]);
}
else if(mundur == 0){
msg[0] = 4;
radio.write(msg, 1);
//Serial.println(msg[0]);
}
else if(kiri == 0){
msg[0] = 3;
radio.write(msg, 1);
//Serial.println(msg[0]);
}
else if(kanan == 0){
msg[0] = 2;
radio.write(msg, 1);
//Serial.println(msg[0]);
}
else{
msg[0] = 5;
radio.write(msg, 1);
//Serial.println(msg[0]);
}
}
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
int datain;
int maju;
int mundur;
int kanan;
int kiri;
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
void setup(void){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
pinMode(13,OUTPUT);
pinMode(7,INPUT);
pinMode(6,INPUT);
pinMode(5,INPUT);
pinMode(4,INPUT);
digitalWrite(7,HIGH);
digitalWrite(6,HIGH);
digitalWrite(5,HIGH);
digitalWrite(4,HIGH);
}
void loop(void){
maju = digitalRead(6);
mundur = digitalRead(4);
kiri = digitalRead(5);
kanan = digitalRead(7);
if(maju == 0){
msg[0] = 1;
radio.write(msg, 1);
//Serial.println(msg[0]);
}
else if(mundur == 0){
msg[0] = 4;
radio.write(msg, 1);
//Serial.println(msg[0]);
}
else if(kiri == 0){
msg[0] = 3;
radio.write(msg, 1);
//Serial.println(msg[0]);
}
else if(kanan == 0){
msg[0] = 2;
radio.write(msg, 1);
//Serial.println(msg[0]);
}
else{
msg[0] = 5;
radio.write(msg, 1);
//Serial.println(msg[0]);
}
}
f. Program Arduino Receiver / Slave
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
//kiri
int mtr1 = 2;
int mtr2 = 3;
//kanan
int mtr3 = 4;
int mtr4 = 5;
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);
}
else if (msg[0] == 2){
delay(10);
digitalWrite(mtr1, HIGH);
digitalWrite(mtr2, LOW);
digitalWrite(mtr3, LOW);
digitalWrite(mtr4, LOW);
//delay(200);
}
else if (msg[0] == 3){
delay(10);
digitalWrite(mtr1, LOW);
digitalWrite(mtr2, LOW);
digitalWrite(mtr3, HIGH);
digitalWrite(mtr4, LOW);
//delay(200);
}
else if (msg[0] == 4){
delay(10);
digitalWrite(mtr1, LOW);
digitalWrite(mtr2, HIGH);
digitalWrite(mtr3, LOW);
digitalWrite(mtr4, HIGH);
//delay(200);
}
else {
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;
//kiri
int mtr1 = 2;
int mtr2 = 3;
//kanan
int mtr3 = 4;
int mtr4 = 5;
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);
}
else if (msg[0] == 2){
delay(10);
digitalWrite(mtr1, HIGH);
digitalWrite(mtr2, LOW);
digitalWrite(mtr3, LOW);
digitalWrite(mtr4, LOW);
//delay(200);
}
else if (msg[0] == 3){
delay(10);
digitalWrite(mtr1, LOW);
digitalWrite(mtr2, LOW);
digitalWrite(mtr3, HIGH);
digitalWrite(mtr4, LOW);
//delay(200);
}
else if (msg[0] == 4){
delay(10);
digitalWrite(mtr1, LOW);
digitalWrite(mtr2, HIGH);
digitalWrite(mtr3, LOW);
digitalWrite(mtr4, HIGH);
//delay(200);
}
else {
delay(10);
digitalWrite(mtr1, LOW);
digitalWrite(mtr2, LOW);
digitalWrite(mtr3, LOW);
digitalWrite(mtr4, LOW);
//delay(200);
}
delay(10);
}
}
else{
Serial.println("No radio available");
}
}
g. VIDEO HASILNYA