How To Make Smartphone Control Bluetooth Car | School and College project
This is my “Arduino Projects” video series. It clearly explains to you how to make a mobile controlled Arduino 4WD robot car. Here I used ‘Arduino Nano’ for my project and if you want to work with another type of board you may have to re-edit a little bit the given code. For Bluetooth communication, I have used an HC-05 Bluetooth module. Every connection of the circuit configuration is clearly mentioned in the video.
Componants:
- 4WD total set :
- L298 Motor driver : https://amzn.to/2G0BAVP
- Arduino Nano : https://amzn.to/3ct8KJJ
- HC-05 Bluetooth Module : https://amzn.to/2S2gHw1
- Battery Holder : https://amzn.to/3i0HDXM
Diagram :
Code :
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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
#define light_FR 14 //LED Front Right pin A0 for Arduino Uno #define light_FL 15 //LED Front Left pin A1 for Arduino Uno #define light_BR 16 //LED Back Right pin A2 for Arduino Uno #define light_BL 17 //LED Back Left pin A3 for Arduino Uno #define horn_Buzz 18 //Horn Buzzer pin A4 for Arduino Uno #define ENA_m1 10 // Enable/speed motor Front Right #define ENB_m1 11 // Enable/speed motor Back Right #define ENA_m2 5 // Enable/speed motor Front Left #define ENB_m2 6 // Enable/speed motor Back Left #define IN_11 2 // L298N #1 in 1 motor Front Right #define IN_12 3 // L298N #1 in 2 motor Front Right #define IN_13 4 // L298N #1 in 3 motor Back Right #define IN_14 7 // L298N #1 in 4 motor Back Right #define IN_21 8 // L298N #2 in 1 motor Front Left #define IN_22 9 // L298N #2 in 2 motor Front Left #define IN_23 12 // L298N #2 in 3 motor Back Left #define IN_24 13 // L298N #2 in 4 motor Back Left int command; //Int to store app command state. int speedCar = 100; // 50 - 255. int speed_Coeff = 4; boolean lightFront = false; boolean lightBack = false; boolean horn = false; void setup() { pinMode(light_FR, OUTPUT); pinMode(light_FL, OUTPUT); pinMode(light_BR, OUTPUT); pinMode(light_BL, OUTPUT); pinMode(horn_Buzz, OUTPUT); pinMode(ENA_m1, OUTPUT); pinMode(ENB_m1, OUTPUT); pinMode(ENA_m2, OUTPUT); pinMode(ENB_m2, OUTPUT); pinMode(IN_11, OUTPUT); pinMode(IN_12, OUTPUT); pinMode(IN_13, OUTPUT); pinMode(IN_14, OUTPUT); pinMode(IN_21, OUTPUT); pinMode(IN_22, OUTPUT); pinMode(IN_23, OUTPUT); pinMode(IN_24, OUTPUT); Serial.begin(9600); } void goAhead(){ digitalWrite(IN_11, HIGH); digitalWrite(IN_12, LOW); analogWrite(ENA_m1, speedCar); digitalWrite(IN_13, LOW); digitalWrite(IN_14, HIGH); analogWrite(ENB_m1, speedCar); digitalWrite(IN_21, LOW); digitalWrite(IN_22, HIGH); analogWrite(ENA_m2, speedCar); digitalWrite(IN_23, HIGH); digitalWrite(IN_24, LOW); analogWrite(ENB_m2, speedCar); } void goBack(){ digitalWrite(IN_11, LOW); digitalWrite(IN_12, HIGH); analogWrite(ENA_m1, speedCar); digitalWrite(IN_13, HIGH); digitalWrite(IN_14, LOW); analogWrite(ENB_m1, speedCar); digitalWrite(IN_21, HIGH); digitalWrite(IN_22, LOW); analogWrite(ENA_m2, speedCar); digitalWrite(IN_23, LOW); digitalWrite(IN_24, HIGH); analogWrite(ENB_m2, speedCar); } void goRight(){ digitalWrite(IN_11, LOW); digitalWrite(IN_12, HIGH); analogWrite(ENA_m1, speedCar); digitalWrite(IN_13, HIGH); digitalWrite(IN_14, LOW); analogWrite(ENB_m1, speedCar); digitalWrite(IN_21, LOW); digitalWrite(IN_22, HIGH); analogWrite(ENA_m2, speedCar); digitalWrite(IN_23, HIGH); digitalWrite(IN_24, LOW); analogWrite(ENB_m2, speedCar); } void goLeft(){ digitalWrite(IN_11, HIGH); digitalWrite(IN_12, LOW); analogWrite(ENA_m1, speedCar); digitalWrite(IN_13, LOW); digitalWrite(IN_14, HIGH); analogWrite(ENB_m1, speedCar); digitalWrite(IN_21, HIGH); digitalWrite(IN_22, LOW); analogWrite(ENA_m2, speedCar); digitalWrite(IN_23, LOW); digitalWrite(IN_24, HIGH); analogWrite(ENB_m2, speedCar); } void goAheadRight(){ digitalWrite(IN_11, HIGH); digitalWrite(IN_12, LOW); analogWrite(ENA_m1, speedCar/speed_Coeff); digitalWrite(IN_13, LOW); digitalWrite(IN_14, HIGH); analogWrite(ENB_m1, speedCar/speed_Coeff); digitalWrite(IN_21, LOW); digitalWrite(IN_22, HIGH); analogWrite(ENA_m2, speedCar); digitalWrite(IN_23, HIGH); digitalWrite(IN_24, LOW); analogWrite(ENB_m2, speedCar); } void goAheadLeft(){ digitalWrite(IN_11, HIGH); digitalWrite(IN_12, LOW); analogWrite(ENA_m1, speedCar); digitalWrite(IN_13, LOW); digitalWrite(IN_14, HIGH); analogWrite(ENB_m1, speedCar); digitalWrite(IN_21, LOW); digitalWrite(IN_22, HIGH); analogWrite(ENA_m2, speedCar/speed_Coeff); digitalWrite(IN_23, HIGH); digitalWrite(IN_24, LOW); analogWrite(ENB_m2, speedCar/speed_Coeff); } void goBackRight(){ digitalWrite(IN_11, LOW); digitalWrite(IN_12, HIGH); analogWrite(ENA_m1, speedCar/speed_Coeff); digitalWrite(IN_13, HIGH); digitalWrite(IN_14, LOW); analogWrite(ENB_m1, speedCar/speed_Coeff); digitalWrite(IN_21, HIGH); digitalWrite(IN_22, LOW); analogWrite(ENA_m2, speedCar); digitalWrite(IN_23, LOW); digitalWrite(IN_24, HIGH); analogWrite(ENB_m2, speedCar); } void goBackLeft(){ digitalWrite(IN_11, LOW); digitalWrite(IN_12, HIGH); analogWrite(ENA_m1, speedCar); digitalWrite(IN_13, HIGH); digitalWrite(IN_14, LOW); analogWrite(ENB_m1, speedCar); digitalWrite(IN_21, HIGH); digitalWrite(IN_22, LOW); analogWrite(ENA_m2, speedCar/speed_Coeff); digitalWrite(IN_23, LOW); digitalWrite(IN_24, HIGH); analogWrite(ENB_m2, speedCar/speed_Coeff); } void stopRobot(){ digitalWrite(IN_11, LOW); digitalWrite(IN_12, LOW); analogWrite(ENA_m1, speedCar); digitalWrite(IN_13, LOW); digitalWrite(IN_14, LOW); analogWrite(ENB_m1, speedCar); digitalWrite(IN_21, LOW); digitalWrite(IN_22, LOW); analogWrite(ENA_m2, speedCar); digitalWrite(IN_23, LOW); digitalWrite(IN_24, LOW); analogWrite(ENB_m2, speedCar); } void loop(){ if (Serial.available() > 0) { command = Serial.read(); stopRobot(); //Initialize with motors stopped. if (lightFront) {digitalWrite(light_FR, HIGH); digitalWrite(light_FL, HIGH);} if (!lightFront) {digitalWrite(light_FR, LOW); digitalWrite(light_FL, LOW);} if (lightBack) {digitalWrite(light_BR, HIGH); digitalWrite(light_BL, HIGH);} if (!lightBack) {digitalWrite(light_BR, LOW); digitalWrite(light_BL, LOW);} if (horn) {digitalWrite(horn_Buzz, HIGH);} if (!horn) {digitalWrite(horn_Buzz, LOW);} switch (command) { case 'F':goAhead();break; case 'B':goBack();break; case 'L':goRight();break; case 'R':goLeft();break; case 'I':goAheadRight();break; case 'G':goAheadLeft();break; case 'J':goBackRight();break; case 'H':goBackLeft();break; case '0':speedCar = 100;break; case '1':speedCar = 115;break; case '2':speedCar = 130;break; case '3':speedCar = 145;break; case '4':speedCar = 160;break; case '5':speedCar = 175;break; case '6':speedCar = 190;break; case '7':speedCar = 205;break; case '8':speedCar = 220;break; case '9':speedCar = 235;break; case 'q':speedCar = 255;break; case 'W':lightFront = true;break; case 'w':lightFront = false;break; case 'U':lightBack = true;break; case 'u':lightBack = false;break; case 'V':horn = true;break; case 'v':horn = false;break; } } } |