Wireless Joystick controlled Robot Car using Arduino– In this tutorial, you will learn how to control a Robot Car wirelessly using Arduino, L298N Motor driver, and 433 Mhz RF transmitter and Receiver. The robot control system can be activated and de-activated using the Built-in Joystick push Button.
Arduino Uno
Arduino Nano
Mega 2560:
Robot Car chassis kit:
L298N motor driver:
2-Axis Analog Joystick
433 MHz Transmitter and Receiver Modules:
DISCLAIMER:
Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
wireless joystick Interfacing:
Watch this tutorial for the robot parts assembling and connections.
All the connections are exactly the same as explained in my previous tutorial. The only modification that I did is the addition of the 433 Mhz RF receiver module…the VCC pin of the receiver module is connected with the 5 volts…the ground pin of the receiver is connected with the Arduino’s ground…while the data pin of the receiver is connected with pin number 3 of the Arduino… everything else remains the same as explained in the getting started tutorial…
This is the Joystick Transmitter Side, the 433 Mhz RF transmitter VCC pin is connected with the Arduino’s 5 volts, the ground pin of the transmitter is connected with the Arduino ground while the data pin is connected with the Arduino’s pin number 12…
as you can see I have also solder wire with the transmitter to slightly increase the range…while the joystick connections are exactly the same as explained in the joystick getting started tutorial.
wireless joystick Robot Car Transmitter Arduino Programming:
Code:
#include <VirtualWire.h>
const int X_AX = A0;
const int Y_AX = A1;
void setup()
{
Serial.begin(9600);
Serial.println("setup");
vw_setup(2000);
vw_set_tx_pin(13);
}
void loop()
{
int xval = analogRead(X_AX);
int yval = analogRead(Y_AX);
if(xval<=261&&xval>=0)
{
char *msg2 = "a";//send a to the receiver
vw_send((uint8_t *)msg2, strlen(msg2));
vw_wait_tx();
Serial.println("a");
}
else if(xval<=1023&&xval>=782)
{
char *msg2 = "b";
vw_send((uint8_t *)msg2, strlen(msg2));
vw_wait_tx();
Serial.println("b");
}
else if(yval<=261&&yval>=0)
{
char *msg2 = "c";
vw_send((uint8_t *)msg2, strlen(msg2));
vw_wait_tx();
Serial.println("c");
}
else if(yval<=1023&&yval>=782)
{
char *msg2 = "d";
vw_send((uint8_t *)msg2, strlen(msg2));
vw_wait_tx();
Serial.println("d");
}
else
{
char *msg2 = "e";
vw_send((uint8_t *)msg2, strlen(msg2));
vw_wait_tx();
Serial.println("e");
}
}
wireless joystick Receiver Arduino Programming:
Code:
#include <VirtualWire.h>
const int motorPin1 = 9; // Pin 9 of L293D
const int motorPin2 = 10; // Pin 10 of L293D
const int motorPin3 = 11; // Pin 11 of L293D
const int motorPin4 = 12; // Pin 12 of L293D
void setup() {
Serial.begin(9600);
Serial.println("setup");
vw_setup(2000);
vw_set_rx_pin(8);
vw_rx_start();
pinMode(13, OUTPUT);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
}
void loop() {
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) {
for (int i = 0; i < buflen; i++) {
switch (buf[i]) {
case 'a': // Forward
digitalWrite(13, HIGH);
Serial.println("Forward");
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH); // FORWARD
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
break;
case 'b': // Backward
digitalWrite(13, HIGH);
Serial.println("Backward");
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW); // REVERSE
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
break;
case 'c': // Left
digitalWrite(13, HIGH);
Serial.println("Left");
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW); // LEFT
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
break;
case 'd': // Right
digitalWrite(13, HIGH);
Serial.println("Right");
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH); // RIGHT
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
break;
case 'e': // Stop
digitalWrite(13, LOW);
Serial.println("Stop");
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW); // STOP
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
break;
default:
break;
}
}
Serial.println("");
}
}
Comments
Post a Comment