Components and supplies
Battery Holder, 18650 x 2
Slide Switch
Jumper wires (generic)
DC Motor, 12 V
Arduino UNO
HC-05 Bluetooth Module
L293D Motor Driver for Arduino
18650 Li-lion Battery
Apps and platforms
Bluetooth Electronics App
AFMotor.h Library
Arduino IDE
Project description
Code
Code
c_cpp
1//Note - Disconnect the Bluetooth Module before hiting the upload button otherwise you'll get compilation error message. 2//AFMotor Library https://learn.adafruit.com/adafruit-motor-shield/library-install 3//After downloading the library open Arduino IDE >> go to sketch >> Include Libray >> ADD. ZIP Libray >> Select the downloaded 4//ZIP File >> Open it >> Done 5//Now You Can Upload the Code without any problem but make sure the bt module isn't connected with Arduino while uploading code 6 7 8 9/* 10 * Devloper Krishna Agarwal (DIY Inventor) 11Coder Krishna Agarwal (DIY Inventor) 12Inventor Krishna Agarwal (DIY Inventor) 13Idea By Krishna Agarwal (DIY Inventor) 14 */ 15#include <AFMotor.h> 16 17//initial motors pin 18AF_DCMotor motor1(1, MOTOR12_1KHZ); 19AF_DCMotor motor2(2, MOTOR12_1KHZ); 20AF_DCMotor motor3(3, MOTOR34_1KHZ); 21AF_DCMotor motor4(4, MOTOR34_1KHZ); 22 23int val; 24int Speeed = 255; 25 26 27void setup() 28{ 29 Serial.begin(9600); //Set the baud rate to your Bluetooth module. 30Serial.println("Krishna"); 31 Serial.println("Mr.Robo is Redy"); 32} 33void loop(){ 34 if(Serial.available() > 0){ 35 val = Serial.read(); 36 37 Stop(); //initialize with motors stoped 38 39 if (val == 'F'){ 40 forward(); 41 } 42 43 if (val == 'B'){ 44 back(); 45 } 46 47 if (val == 'L'){ 48 left(); 49 } 50 51 if (val == 'R'){ 52 right(); 53 } 54 if (val == 'I'){ 55 topright(); 56 } 57 58 if (val == 'J'){ 59 topleft(); 60 } 61 62 if (val == 'K'){ 63 bottomright(); 64 } 65 66 if (val == 'M'){ 67 bottomleft(); 68 } 69 if (val == 'T'){ 70 Stop(); 71 } 72 } 73} 74 75 76 77 78 79 80void forward() 81{ 82 Serial.println("Forward"); 83 motor1.setSpeed(Speeed); //Define maximum velocity 84 motor1.run(FORWARD); //rotate the motor clockwise 85 motor2.setSpeed(Speeed); //Define maximum velocity 86 motor2.run(FORWARD); //rotate the motor clockwise 87 motor3.setSpeed(Speeed);//Define maximum velocity 88 motor3.run(FORWARD); //rotate the motor clockwise 89 motor4.setSpeed(Speeed);//Define maximum velocity 90 motor4.run(FORWARD); //rotate the motor clockwise 91 92 93} 94 95void back() 96{ 97 Serial.println("Bacward"); 98 motor1.setSpeed(Speeed); //Define maximum velocity 99 motor1.run(BACKWARD); //rotate the motor anti-clockwise 100 motor2.setSpeed(Speeed); //Define maximum velocity 101 motor2.run(BACKWARD); //rotate the motor anti-clockwise 102 motor3.setSpeed(Speeed); //Define maximum velocity 103 motor3.run(BACKWARD); //rotate the motor anti-clockwise 104 motor4.setSpeed(Speeed); //Define maximum velocity 105 motor4.run(BACKWARD); //rotate the motor anti-clockwise 106} 107 108void left() 109{ 110 Serial.println("Left"); 111 112 motor1.setSpeed(Speeed); //Define maximum velocity 113 motor1.run(BACKWARD); //rotate the motor anti-clockwise 114 motor2.setSpeed(Speeed); //Define maximum velocity 115 motor2.run(BACKWARD); //rotate the motor anti-clockwise 116 motor3.setSpeed(Speeed); //Define maximum velocity 117 motor3.run(FORWARD); //rotate the motor clockwise 118 motor4.setSpeed(Speeed); //Define maximum velocity 119 motor4.run(FORWARD); //rotate the motor clockwise 120} 121 122void right() 123{ 124 Serial.println("Right"); 125 motor1.setSpeed(Speeed); //Define maximum velocity 126 motor1.run(FORWARD); //rotate the motor clockwise 127 motor2.setSpeed(Speeed); //Define maximum velocity 128 motor2.run(FORWARD); //rotate the motor clockwise 129 motor3.setSpeed(Speeed); //Define maximum velocity 130 motor3.run(BACKWARD); //rotate the motor anti-clockwise 131 motor4.setSpeed(Speeed); //Define maximum velocity 132 motor4.run(BACKWARD); //rotate the motor anti-clockwise 133} 134 135void topleft(){ 136 Serial.println("Top Left"); 137 motor1.setSpeed(Speeed); //Define maximum velocity 138 motor1.run(FORWARD); //rotate the motor clockwise 139 motor2.setSpeed(Speeed); //Define maximum velocity 140 motor2.run(FORWARD); //rotate the motor clockwise 141 motor3.setSpeed(Speeed/3.1);//Define maximum velocity 142 motor3.run(FORWARD); //rotate the motor clockwise 143 motor4.setSpeed(Speeed/3.1);//Define maximum velocity 144 motor4.run(FORWARD); //rotate the motor clockwise 145} 146 147void topright() 148{ 149 Serial.println("Top Right"); 150 motor1.setSpeed(Speeed/3.1); //Define maximum velocity 151 motor1.run(FORWARD); //rotate the motor clockwise 152 motor2.setSpeed(Speeed/3.1); //Define maximum velocity 153 motor2.run(FORWARD); //rotate the motor clockwise 154 motor3.setSpeed(Speeed);//Define maximum velocity 155 motor3.run(FORWARD); //rotate the motor clockwise 156 motor4.setSpeed(Speeed);//Define maximum velocity 157 motor4.run(FORWARD); //rotate the motor clockwise 158} 159 160void bottomleft() 161{ 162 Serial.println("Botom Left"); 163 motor1.setSpeed(Speeed); //Define maximum velocity 164 motor1.run(BACKWARD); //rotate the motor anti-clockwise 165 motor2.setSpeed(Speeed); //Define maximum velocity 166 motor2.run(BACKWARD); //rotate the motor anti-clockwise 167 motor3.setSpeed(Speeed/3.1); //Define maximum velocity 168 motor3.run(BACKWARD); //rotate the motor anti-clockwise 169 motor4.setSpeed(Speeed/3.1); //Define maximum velocity 170 motor4.run(BACKWARD); //rotate the motor anti-clockwise 171} 172 173void bottomright() 174{ 175 Serial.println("Bottom Right"); 176 motor1.setSpeed(Speeed/3.1); //Define maximum velocity 177 motor1.run(BACKWARD); //rotate the motor anti-clockwise 178 motor2.setSpeed(Speeed/3.1); //Define maximum velocity 179 motor2.run(BACKWARD); //rotate the motor anti-clockwise 180 motor3.setSpeed(Speeed); //Define maximum velocity 181 motor3.run(BACKWARD); //rotate the motor anti-clockwise 182 motor4.setSpeed(Speeed); //Define maximum velocity 183 motor4.run(BACKWARD); //rotate the motor anti-clockwise 184} 185 186 187void Stop() 188{ 189 Serial.println("Stop"); 190 191 motor1.setSpeed(0); //Define minimum velocity 192 motor1.run(RELEASE); //stop the motor when release the button 193 motor2.setSpeed(0); //Define minimum velocity 194 motor2.run(RELEASE); //rotate the motor clockwise 195 motor3.setSpeed(0); //Define minimum velocity 196 motor3.run(RELEASE); //stop the motor when release the button 197 motor4.setSpeed(0); //Define minimum velocity 198 motor4.run(RELEASE); //stop the motor when release the button 199} 200
Code
c_cpp
1//Note - Disconnect the Bluetooth Module before hiting the upload button otherwise you'll get compilation error message. 2//AFMotor Library https://learn.adafruit.com/adafruit-motor-shield/library-install 3//After downloading the library open Arduino IDE >> go to sketch >> Include Libray >> ADD. ZIP Libray >> Select the downloaded 4//ZIP File >> Open it >> Done 5//Now You Can Upload the Code without any problem but make sure the bt module isn't connected with Arduino while uploading code 6 7 8 9/* 10 * Devloper Krishna Agarwal (DIY Inventor) 11Coder Krishna Agarwal (DIY Inventor) 12Inventor Krishna Agarwal (DIY Inventor) 13Idea By Krishna Agarwal (DIY Inventor) 14 */ 15#include <AFMotor.h> 16 17//initial motors pin 18AF_DCMotor motor1(1, MOTOR12_1KHZ); 19AF_DCMotor motor2(2, MOTOR12_1KHZ); 20AF_DCMotor motor3(3, MOTOR34_1KHZ); 21AF_DCMotor motor4(4, MOTOR34_1KHZ); 22 23int val; 24int Speeed = 255; 25 26 27void setup() 28{ 29 Serial.begin(9600); //Set the baud rate to your Bluetooth module. 30Serial.println("Krishna"); 31 Serial.println("Mr.Robo is Redy"); 32} 33void loop(){ 34 if(Serial.available() > 0){ 35 val = Serial.read(); 36 37 Stop(); //initialize with motors stoped 38 39 if (val == 'F'){ 40 forward(); 41 } 42 43 if (val == 'B'){ 44 back(); 45 } 46 47 if (val == 'L'){ 48 left(); 49 } 50 51 if (val == 'R'){ 52 right(); 53 } 54 if (val == 'I'){ 55 topright(); 56 } 57 58 if (val == 'J'){ 59 topleft(); 60 } 61 62 if (val == 'K'){ 63 bottomright(); 64 } 65 66 if (val == 'M'){ 67 bottomleft(); 68 } 69 if (val == 'T'){ 70 Stop(); 71 } 72 } 73} 74 75 76 77 78 79 80void forward() 81{ 82 Serial.println("Forward"); 83 motor1.setSpeed(Speeed); //Define maximum velocity 84 motor1.run(FORWARD); //rotate the motor clockwise 85 motor2.setSpeed(Speeed); //Define maximum velocity 86 motor2.run(FORWARD); //rotate the motor clockwise 87 motor3.setSpeed(Speeed);//Define maximum velocity 88 motor3.run(FORWARD); //rotate the motor clockwise 89 motor4.setSpeed(Speeed);//Define maximum velocity 90 motor4.run(FORWARD); //rotate the motor clockwise 91 92 93} 94 95void back() 96{ 97 Serial.println("Bacward"); 98 motor1.setSpeed(Speeed); //Define maximum velocity 99 motor1.run(BACKWARD); //rotate the motor anti-clockwise 100 motor2.setSpeed(Speeed); //Define maximum velocity 101 motor2.run(BACKWARD); //rotate the motor anti-clockwise 102 motor3.setSpeed(Speeed); //Define maximum velocity 103 motor3.run(BACKWARD); //rotate the motor anti-clockwise 104 motor4.setSpeed(Speeed); //Define maximum velocity 105 motor4.run(BACKWARD); //rotate the motor anti-clockwise 106} 107 108void left() 109{ 110 Serial.println("Left"); 111 112 motor1.setSpeed(Speeed); //Define maximum velocity 113 motor1.run(BACKWARD); //rotate the motor anti-clockwise 114 motor2.setSpeed(Speeed); //Define maximum velocity 115 motor2.run(BACKWARD); //rotate the motor anti-clockwise 116 motor3.setSpeed(Speeed); //Define maximum velocity 117 motor3.run(FORWARD); //rotate the motor clockwise 118 motor4.setSpeed(Speeed); //Define maximum velocity 119 motor4.run(FORWARD); //rotate the motor clockwise 120} 121 122void right() 123{ 124 Serial.println("Right"); 125 motor1.setSpeed(Speeed); //Define maximum velocity 126 motor1.run(FORWARD); //rotate the motor clockwise 127 motor2.setSpeed(Speeed); //Define maximum velocity 128 motor2.run(FORWARD); //rotate the motor clockwise 129 motor3.setSpeed(Speeed); //Define maximum velocity 130 motor3.run(BACKWARD); //rotate the motor anti-clockwise 131 motor4.setSpeed(Speeed); //Define maximum velocity 132 motor4.run(BACKWARD); //rotate the motor anti-clockwise 133} 134 135void topleft(){ 136 Serial.println("Top Left"); 137 motor1.setSpeed(Speeed); //Define maximum velocity 138 motor1.run(FORWARD); //rotate the motor clockwise 139 motor2.setSpeed(Speeed); //Define maximum velocity 140 motor2.run(FORWARD); //rotate the motor clockwise 141 motor3.setSpeed(Speeed/3.1);//Define maximum velocity 142 motor3.run(FORWARD); //rotate the motor clockwise 143 motor4.setSpeed(Speeed/3.1);//Define maximum velocity 144 motor4.run(FORWARD); //rotate the motor clockwise 145} 146 147void topright() 148{ 149 Serial.println("Top Right"); 150 motor1.setSpeed(Speeed/3.1); //Define maximum velocity 151 motor1.run(FORWARD); //rotate the motor clockwise 152 motor2.setSpeed(Speeed/3.1); //Define maximum velocity 153 motor2.run(FORWARD); //rotate the motor clockwise 154 motor3.setSpeed(Speeed);//Define maximum velocity 155 motor3.run(FORWARD); //rotate the motor clockwise 156 motor4.setSpeed(Speeed);//Define maximum velocity 157 motor4.run(FORWARD); //rotate the motor clockwise 158} 159 160void bottomleft() 161{ 162 Serial.println("Botom Left"); 163 motor1.setSpeed(Speeed); //Define maximum velocity 164 motor1.run(BACKWARD); //rotate the motor anti-clockwise 165 motor2.setSpeed(Speeed); //Define maximum velocity 166 motor2.run(BACKWARD); //rotate the motor anti-clockwise 167 motor3.setSpeed(Speeed/3.1); //Define maximum velocity 168 motor3.run(BACKWARD); //rotate the motor anti-clockwise 169 motor4.setSpeed(Speeed/3.1); //Define maximum velocity 170 motor4.run(BACKWARD); //rotate the motor anti-clockwise 171} 172 173void bottomright() 174{ 175 Serial.println("Bottom Right"); 176 motor1.setSpeed(Speeed/3.1); //Define maximum velocity 177 motor1.run(BACKWARD); //rotate the motor anti-clockwise 178 motor2.setSpeed(Speeed/3.1); //Define maximum velocity 179 motor2.run(BACKWARD); //rotate the motor anti-clockwise 180 motor3.setSpeed(Speeed); //Define maximum velocity 181 motor3.run(BACKWARD); //rotate the motor anti-clockwise 182 motor4.setSpeed(Speeed); //Define maximum velocity 183 motor4.run(BACKWARD); //rotate the motor anti-clockwise 184} 185 186 187void Stop() 188{ 189 Serial.println("Stop"); 190 191 motor1.setSpeed(0); //Define minimum velocity 192 motor1.run(RELEASE); //stop the motor when release the button 193 motor2.setSpeed(0); //Define minimum velocity 194 motor2.run(RELEASE); //rotate the motor clockwise 195 motor3.setSpeed(0); //Define minimum velocity 196 motor3.run(RELEASE); //stop the motor when release the button 197 motor4.setSpeed(0); //Define minimum velocity 198 motor4.run(RELEASE); //stop the motor when release the button 199} 200
Downloadable files
Circuit Diagram
Connection of HC-05 Hook the GND pin (Negative Pin) of HC-05 to Pin GND of Arduino. Connect VCC Pin (Positive Pin) of HC-05 to VCC of Arduino. Connect TX pin (Data Transfer Pin) of HC-05 to RX pin of Arduino. Connect RX Pin of HC-05 to TX Pin of Arduino. Connection of Motor Connect Front Left Motor with M1 of L293D Motor Driver. Connect Front Right Motor with M2 of L293D Motor Driver. Connect Bottom Left Motor with M3 of L293D Motor Driver. Connect Bottom Right Motor with M4 of L293D Motor Driver. Connection of Battery and Switch Connect 2 18650 Battery Positive Wire with Button and 2 Pin of Button with M+ of L293D Connection Negative Wire to Power GND of L293D
Circuit Diagram
Comments
Only logged in users can leave comments