Wireless Joystick controlled Robot Car using Arduino, 433Mhz RF and L298N Motor Driver
Description:
wireless joystick-In this project, 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.
Depending on the movement of the joystick and the value of the VRx and VRy, the speed of the dc motors can be controlled in realTime which gives you more control over the Robot Car….
in this tutorial I explained the joystick pinouts, its basic working principle, its interfacing with Arduino and basic programming to control some led’s depending on the movement of the joystick.
The Amazon Purchase links are given below:
Robot Car chassis kit: https://amzn.to/2tTpkgo
L298N dual H-Bridge motor driver: https://amzn.to/2XF4sam
Joystick: https://amzn.to/2E2Q0kI
433Mhz tx and rx: best offer https://amzn.to/2EkVMyN
Arduino Uno: https://amzn.to/39aq6ZT
Mega 2560: https://amzn.to/2SszMsI
lm7805 Voltage Regulator: https://amzn.to/2ERYoTJ
330-ohm resistors pack: https://amzn.to/2Qj1Igg
female DC power jack socket: https://amzn.to/377Pg9M
470uf capacitors: https://amzn.to/2MrN3xR
5×7 cm Vero board: https://amzn.to/37b7KWO
female headers: https://amzn.to/350w6RE
connection wires: https://amzn.to/2MvOJXd
Super Starter kit for Beginners: https://amzn.to/398dliF
Jumper Wires: https://amzn.to/2SrnBwo
Bread Board: https://amzn.to/2MxV5FM
12v Adaptor: https://amzn.to/2MuOlZk
PCB plate: https://amzn.to/2MuwNMB
Variable Supply: https://amzn.to/39d0KdP
Digital Multimeter: https://amzn.to/34WbVoa
Vero Board / stripboard: https://amzn.to/39nL9Zg
Soldering iron kit: “best” You guys should definitely purchase this: https://amzn.to/2PVwexF
Solder wire: https://amzn.to/2QlOvTS
Wire Stripper: https://amzn.to/353tYJa
wirecutter: https://amzn.to/2tV2lFj
PCB small portable drill machine: https://amzn.to/2MvQqnx
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!
Interfacing:
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 a 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…
Programming:
In this project two Programs are used, one program is written for the Transmitter side and another program is written for the Receiver side. So first let’s start with the Transmitter side. In both the Programming the Virtual Wire library is used which you can download by clicking on the download button below.
wireless joystick Transmitter Programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
// Robot Transmitter programming #include <VirtualWire.h> const int transmit_pin = 12; String str; char cstr[100]; String message = ""; unsigned int mlength; // message length // for joystick int flag = 0; int buttonf = 0; int power = 7; int button = 4; int vrx = A1; int vry = A2; int xdata = 0; int ydata = 0; void setup() { // Initialise the IO and ISR vw_set_tx_pin(transmit_pin); vw_setup(2000); // Bits per sec Serial.begin(9600); pinMode(vrx, INPUT); pinMode(vry, INPUT); pinMode(power, OUTPUT); digitalWrite(power, HIGH); pinMode(button, INPUT); digitalWrite(button , HIGH); } void loop() { control(); if( buttonf == 1) { xdata = analogRead(vrx); ydata = analogRead(vry); //Serial.println(xdata); //Serial.println(ydata); SendData(xdata,ydata,buttonf); //delay(100); } if(buttonf == 0) { SendData(0,0,0); // send 0 to the receiver. delay(100); } } // this function takes 5 arguments as the input // the sensors and the sensors group number. // let's say we are using multiple sensors, the sensors //can be divided into groups. void SendData( int xvalue,int yvalue,int buttonstatus) { message = message + xvalue +"," + yvalue + "," + buttonstatus ; mlength = message.length(); // find the number of characters in a message. str = message; str.toCharArray(cstr,100); vw_send((uint8_t *)cstr, mlength); // vw_wait_tx(); // Wait until the whole message is gone str = ""; message = ""; } void control() { if (( digitalRead(button) == LOW ) && (buttonf == 0)) { Serial.println(" Started"); buttonf = 1; delay(1000); } if (( digitalRead(button) == LOW ) && (buttonf == 1)) { Serial.println("ended"); buttonf = 0; delay(1000); } digitalWrite(button , HIGH); } |
wireless joystick Receiver Programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
// receiver Programming #include <VirtualWire.h> const int receive_pin = 3; String message; String myString; // for joystick int xvalue; int yvalue; int buttonf; int xdata; int ydata; int bfdata; // buttonflag // for L298N motor driver int ena = 5; int enb = 6; int in1 = 8; int in2 = 9; int in3 = 10; int in4 = 11; void setup() { delay(1000); Serial.begin(9600); // Debugging only pinMode(ena, OUTPUT); pinMode(enb, OUTPUT); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(in3, OUTPUT); pinMode(in4, OUTPUT); analogWrite(ena, 0); analogWrite(enb, 0); delay(1000); Serial.println("setup"); // Initialise the IO and ISR vw_set_rx_pin(receive_pin); vw_set_ptt_inverted(true); // Required for DR3100 vw_setup(2000); // Bits per sec vw_rx_start(); // Start the receiver PLL running } void loop() { uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; if (vw_get_message(buf, &buflen)) // Non-blocking { int i; // Message with a good checksum received, dump it. //Serial.print("Got: "); for (i = 0; i < buflen; i++) { char c = (buf[i]); message = message + c ; // make a message from the received characters } myString = message; Serial.println(message); String l = getValue(myString, ',', 0); // xvalue String m = getValue(myString, ',', 1); // yvalue String n = getValue(myString, ',', 2); // buttonf xdata = l.toInt(); ydata = m.toInt(); bfdata = n.toInt(); /* Serial.println("*********from Transmitter************"); Serial.println(xdata); Serial.println(ydata); Serial.println(bfdata); */ /* when the joystic is at normal position we get x = 450 to 550 y= 450 to 550 for the these values we want the robot not to move */ if ( ((xdata >= 480)&&(xdata <= 510)) && ( (ydata>=480) && (ydata<=510) ) ) { Serial.println("Stopped"); analogWrite(ena, 0); analogWrite(enb, 0); digitalWrite(in1, LOW); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); } // if button on the joystick is pressed if (bfdata == 0) { analogWrite(ena, 0); analogWrite(enb, 0); digitalWrite(in1, LOW); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); } /* for the forward movement * the value of the x increases above 550 to 1023 while the value of the y statys between 450 and 550 */ if ( ((xdata > 510)&&(xdata <= 1023)) && ( (ydata>=480) && (ydata<=510) ) ) { Serial.println("forward"); int xmapped = map(xmapped, xdata, 1023, 255,0); int ymapped = map(ymapped, xdata, 1023, 255,0); analogWrite(ena, xmapped); analogWrite(enb, ymapped); digitalWrite(in1, HIGH); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, HIGH); } /* for the Reverse movement * the value of the x increases above 550 to 1023 while the value of the y statys between 450 and 550 */ if ( ((xdata >= 0)&&(xdata < 480)) && ( (ydata>=480) && (ydata<=510) ) ) { Serial.println("reverse"); int xmapped = map(xmapped, xdata, 479, 255,0); int ymapped = map(ymapped, xdata, 479, 255,0); analogWrite(ena, xmapped); analogWrite(enb, ymapped); digitalWrite(in1, LOW); digitalWrite(in2, HIGH); digitalWrite(in3, HIGH); digitalWrite(in4, LOW); } // for right movement if ( ( (ydata> 510) && (ydata <= 1023) ) && ( bfdata == 1) ) { Serial.println("Right"); int ymapped = map(ymapped, ydata, 1023, 255,0); analogWrite(ena, ymapped); analogWrite(enb, 0); digitalWrite(in1, HIGH); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); } // for left movement if ( ( (ydata >= 0) && (ydata <= 479) && ( bfdata == 1) ) ) { Serial.println("left"); int ymapped = map(ymapped, ydata, 479, 255,0); analogWrite(ena, 0); analogWrite(enb, ymapped); digitalWrite(in1, LOW); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, HIGH); } message = ""; } } String getValue(String data, char separator, int index) { int found = 0; int strIndex[] = { 0, -1 }; int maxIndex = data.length() - 1; for (int i = 0; i <= maxIndex && found <= index; i++) { if (data.charAt(i) == separator || i == maxIndex) { found++; strIndex[0] = strIndex[1] + 1; strIndex[1] = (i == maxIndex) ? i+1 : i; } } return found > index ? data.substring(strIndex[0], strIndex[1]) : ""; } |
As someone who is passionate about learning and personal growth, I can say without hesitation that this blog is one of my favorites. The author’s writing is both substantive and interesting, and their ability to provide insights and perspectives that are truly unique is truly commendable. I appreciate the level of research and attention to detail that goes into each post, and the author’s commitment to providing factual and balanced perspectives. What I love most about this blog is its ability to challenge my assumptions and make me think deeply about important issues. I can’t recommend this blog enough.