Devices & Components
Arduino Uno Rev3
Arduino Sensor Shield v5
4WD Robot Chassis Kit
Two-sided Mounting Tape
HM-10 Bluetooth Module
Buzzer
Arduino Smart Robot Car Kit (Optional)
Arduino Power Jack connector
Arduino Cable kit
2x18650 Battery Holder
Smartphone Stand
L298N Dual H-Bridge DC Motor Speed Controller Board
Software & Tools
Arduino IDE
iRobbie-A
Project description
Code
Robbie_A1.ino
arduino
Arduino code. You can also download it from https://www.robbie-app.com
1#include <Servo.h> 2 3Servo servo; 4int angle = 0; 5boolean forward1 = false ; 6String bluetoothRead, Str_x, Str_y, Str_p, Str_s; 7int x ; 8int y ; 9int points; 10int length; 11const int buzzer = 10; 12int s; 13unsigned long previousMillis = millis(); // will store last time LED was updated 14 15const long interval = 1000; // interval at which to blink (milliseconds) 16 17#define ENA 11 18#define ENB 6 19#define IN1 5 20#define IN2 7 21#define IN3 8 22#define IN4 9 23#define DELAY 20 24 25int carSpeed = (y*3); 26int speed_Coeff = (1 + (x/50)); 27 28void setup() { 29 Serial.begin(9600); 30 Serial.flush(); 31 pinMode(IN1,OUTPUT); 32 pinMode(IN2,OUTPUT); 33 pinMode(IN3,OUTPUT); 34 pinMode(IN4,OUTPUT); 35 pinMode(ENA,OUTPUT); 36 pinMode(ENB,OUTPUT); 37 pinMode(buzzer, OUTPUT); 38 stop(); 39 servo.attach(13); 40 servo.write(angle); 41} 42 43void loop() { 44 int i=0; 45 char commandbuffer[200]; 46unsigned long currentMillis = millis(); 47 48 if(Serial.available()){ 49 50 delay(10); 51 52 while( Serial.available() && i< 199) { 53 commandbuffer[i++] = Serial.read(); 54 55 56 } 57 commandbuffer[i++]='\\0'; 58 bluetoothRead = (char*)commandbuffer; 59 length = bluetoothRead.length(); 60 Serial.println(bluetoothRead); 61 62 63 if(bluetoothRead.substring(0, 1).equals("x")){ 64 65 int i=1; 66 while(bluetoothRead.substring(i, i+1) != ("y")){ 67 i++; 68 } 69 70 Str_x = bluetoothRead.substring(1, i); 71 x = Str_x.toInt(); 72 73 Str_y = bluetoothRead.substring(i+1, length - 2); 74 y = Str_y.toInt(); 75 76 Str_p = bluetoothRead.substring(length - 2, length - 1); 77 points = Str_p.toInt(); 78 79 Str_s = bluetoothRead.substring(length - 1, length); 80 s = Str_s.toInt(); 81 82 i = 1; 83 84 Serial.println(x); 85 Serial.println(y); 86 Serial.println(points); 87 Serial.println(s); 88 Serial.println(length ); 89 90 stop(); 91 carSpeed = (y*2.5); 92 speed_Coeff = (1 + (x/50)); 93 94 95 if(points == 1){ 96 forward(); 97 } 98 if(points == 0){ 99 stop(); 100 } 101 if(points == 2){ 102 back(); 103 } 104 105 if(points == 3){ 106 fleft(); 107 } 108 109 if(points == 4){ 110 fright(); 111 } 112 113 if(points == 5){ 114 left(); 115 } 116 117 if(points == 6){ 118 right(); 119 } 120 121 if(points == 7){ 122 bleft(); 123 } 124 125 if(points == 8){ 126 bright(); 127 } 128 129 if(points == 9){ 130 findo(); 131 } 132 133 134 135 if (s == 7){ 136 play_do(); 137 } 138 139 if (s == 6){ 140 play_re(); 141 } 142 143 if (s == 5){ 144 play_mi(); 145 } 146 147 if (s == 4){ 148 play_fa(); 149 } 150 151 if (s == 3){ 152 play_sol(); 153 } 154 155 if (s == 2){ 156 play_la(); 157 } 158 159 if (s == 1){ 160 play_ci(); 161 } 162//When an object is detected the iRobbie App will start sending s = 8 to the Arduino. 163//You can use it in your own Arduino code. The commented lines is an example. 164 165 if (s == 8){ 166 // if (millis() - previousMillis >= DELAY) 167 // {previousMillis += DELAY; 168 // if (forward1) 169 // { 170 // servo.write(-- angle); 171 // if(angle == 0) 172 // forward1 = false; 173// } 174 // else 175// { 176 // servo.write(++ angle); 177 // if (angle == 30) 178 // forward1 = true; 179 // } 180 // } 181 182 // scan from 0 to 180 degrees 183 // for(angle = 10; angle < 90; angle++) 184 // { 185// servo.write(0); 186// delay(15); 187// } 188// servo.write(90); 189 190 // } 191 // servo.write(-90); 192 193// } 194 195 // now scan back from 180 to 0 degrees 196// for(angle = 90; angle > 10; angle--) 197 // { 198 // servo.write(angle); 199 // delay(15); 200// } 201// servomove(); 202 } 203 204} 205} 206} 207 208void servomove(){ 209 unsigned long currentMillis = millis(); 210 if (currentMillis - previousMillis >= interval) { 211 previousMillis = currentMillis; 212 213 for(angle = 0; angle < 60; angle++) 214 { 215 servo.write(angle); 216 previousMillis = currentMillis; 217 delay(10); 218 } 219 // now scan back from 180 to 0 degrees 220 for(angle = 60; angle > 0; angle--) 221 { 222 servo.write(angle); 223 } 224 previousMillis = currentMillis; 225 delay(10); 226} 227} 228 229 230void forward(){ 231 analogWrite(ENA,carSpeed); 232 analogWrite(ENB,carSpeed); 233 digitalWrite(IN1,LOW); 234 digitalWrite(IN2,HIGH); 235 digitalWrite(IN3,LOW); 236 digitalWrite(IN4,HIGH); 237 delay(25); 238// Serial.println("Forward"); 239} 240 241void forwards(){ 242 analogWrite(ENA,carSpeed); 243 analogWrite(ENB,carSpeed); 244 digitalWrite(IN1,LOW); 245 digitalWrite(IN2,HIGH); 246 digitalWrite(IN3,LOW); 247 digitalWrite(IN4,HIGH); 248 delay(25); 249 // Serial.println("Forward_slow"); 250} 251 252void back(){ 253 analogWrite(ENA,(carSpeed - 20)); 254 analogWrite(ENB,(carSpeed - 20)); 255 digitalWrite(IN1,HIGH); 256 digitalWrite(IN2,LOW); 257 digitalWrite(IN3,HIGH); 258 digitalWrite(IN4,LOW); 259 delay(25); 260 // Serial.println("Back"); 261} 262 263void backs(){ 264 analogWrite(ENA,(carSpeed - 20)); 265 analogWrite(ENB,(carSpeed - 20)); 266 digitalWrite(IN1,HIGH); 267 digitalWrite(IN2,LOW); 268 digitalWrite(IN3,HIGH); 269 digitalWrite(IN4,LOW); 270 delay(25); 271// Serial.println("Back_slow"); 272} 273void left(){ 274 analogWrite(ENA,x); 275 analogWrite(ENB,x); 276 digitalWrite(IN1,LOW); 277 digitalWrite(IN2,HIGH); 278 digitalWrite(IN3,HIGH); 279 digitalWrite(IN4,LOW); 280 delay(25); 281// Serial.println("Left"); 282} 283 284void right(){ 285 analogWrite(ENA,x); 286 analogWrite(ENB,x); 287 digitalWrite(IN1,HIGH); 288 digitalWrite(IN2,LOW); 289 digitalWrite(IN3,LOW); 290 digitalWrite(IN4,HIGH); 291 delay(25); 292 // Serial.println("Right"); 293} 294 295 296void fright(){ 297 analogWrite(ENA,carSpeed); 298 analogWrite(ENB,carSpeed/speed_Coeff); 299 digitalWrite(IN1,LOW); 300 digitalWrite(IN2,HIGH); 301 digitalWrite(IN3,LOW); 302 digitalWrite(IN4,HIGH); 303 delay(25); 304// Serial.println("Forward_right"); 305} 306 307 308 309void fleft(){ 310 analogWrite(ENA,carSpeed/speed_Coeff); 311 analogWrite(ENB,carSpeed); 312 digitalWrite(IN1,LOW); 313 digitalWrite(IN2,HIGH); 314 digitalWrite(IN3,LOW); 315 digitalWrite(IN4,HIGH); 316 delay(25); 317// Serial.println("Forward_left"); 318} 319 320void bright(){ 321 analogWrite(ENB,carSpeed); 322 analogWrite(ENA,carSpeed/speed_Coeff); 323 digitalWrite(IN1,HIGH); 324 digitalWrite(IN2,LOW); 325 digitalWrite(IN3,HIGH); 326 digitalWrite(IN4,LOW); 327 delay(25); 328// Serial.println("Back_right"); 329} 330 331 332 333void bleft(){ 334 analogWrite(ENB,carSpeed/speed_Coeff); 335 analogWrite(ENA,carSpeed); 336 digitalWrite(IN1,HIGH); 337 digitalWrite(IN2,LOW); 338 digitalWrite(IN3,HIGH); 339 digitalWrite(IN4,LOW); 340 delay(25); 341 // Serial.println("Back_left"); 342} 343 344void findo(){ 345 analogWrite(ENA,90); 346 analogWrite(ENB,90); 347 digitalWrite(IN1,HIGH); 348 digitalWrite(IN2,LOW); 349 digitalWrite(IN3,LOW); 350 digitalWrite(IN4,HIGH); 351 352 353 delay(25) ; 354 355 356 } 357 358 359void stop(){ 360 digitalWrite(ENA,LOW); 361 digitalWrite(ENB,LOW); 362 // Serial.println("Stop!"); 363} 364 365 366void play_do(){ 367 tone(buzzer, 533); 368 delay(500); 369 noTone(buzzer); 370} 371 372void play_re(){ 373 tone(buzzer, 587); 374 delay(500); 375 noTone(buzzer); 376} 377 378void play_mi(){ 379 tone(buzzer, 659); 380 delay(500); 381 noTone(buzzer); 382} 383 384void play_fa(){ 385 tone(buzzer, 698); 386 delay(500); 387 noTone(buzzer); 388} 389 390void play_sol(){ 391 tone(buzzer, 784); 392 delay(500); 393 noTone(buzzer); 394} 395 396void play_la(){ 397 tone(buzzer, 880); 398 delay(500); 399 noTone(buzzer); 400} 401 402void play_ci(){ 403 tone(buzzer, 987); 404 delay(500); 405 noTone(buzzer); 406} 407
Downloadable files
Assembled car
Function of each part: 1. Battery holder with a switch: provide power supply for the vehicle 2. Electric motors + wheels: drive the vehicle to move 3. Acrylic plates: the frame of the car 4. L298N motor driving board: drive the motors to rotate 5. UNO controller board: the brain of the car 6. V5 sensor expansion board: combined with the UNO, make the connection become more easier 7. Bluetooth module HM-10: provide the Bluetooth connection with iPhone and iRobbie App 8. Smartphone stand: hold the smartphone on the car You can find an example of detailed instructions and diagrams here: https://www.elegoo.com/tutorial/Elegoo%20Smart%20Robot%20Car%20Kit%20V2.0.2019.03.19.zip
Assembled car

Assembled car
Function of each part: 1. Battery holder with a switch: provide power supply for the vehicle 2. Electric motors + wheels: drive the vehicle to move 3. Acrylic plates: the frame of the car 4. L298N motor driving board: drive the motors to rotate 5. UNO controller board: the brain of the car 6. V5 sensor expansion board: combined with the UNO, make the connection become more easier 7. Bluetooth module HM-10: provide the Bluetooth connection with iPhone and iRobbie App 8. Smartphone stand: hold the smartphone on the car You can find an example of detailed instructions and diagrams here: https://www.elegoo.com/tutorial/Elegoo%20Smart%20Robot%20Car%20Kit%20V2.0.2019.03.19.zip
Assembled car

Comments
Only logged in users can leave comments