Components and supplies
Voltage Sensor Module
Mechanical Endstop Limit Switch (No 2 Limit Switches required)
Angle Tilt Sensor SW520D
PWM Motor Speed Control
DC Motor Blade 12V 8000Rpm
Bubble Level Round
8x8 dot matrix module MAX7219
Arduino Mega 2560
Worm Geared Motor 12VDC 27rpm
Bluetooth Module HC-05
30Pcs Lawn Mower Blade
Blade Motor Flange 5mm
USB-A to B Cable
USB extension cord type B male/female
Wheel Motor Flanged connection 8mm
Ultrasonic Sensor hc sr04
Lipo Battery 3S (11.1V)
Relay Board
T-plug connector
Motor driver board module L298N
Waterproof Metal Push Button Switch LED Light
Buzzer Module
Red mushroom head emergency stop button switch
Toggle Switch, Toggle
Tools and machines
Multitool, Screwdriver
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)
Soldering iron (generic)
3D Printer (generic)
Apps and platforms
Fusion 360
Bluetooth RC Controller
Arduino IDE
Project description
Code
Mowerino
c_cpp
Arduino Software
1#include <L298N.h> // Library for L298N Motor Driver Module 2#include <Ultrasonic.h> // Library for Ultrasonic sensor 3#include <LedControl.h> // Library for Led Matrix 8x8 4 5//START CONFIGURATION LED MATRIX 6int DIN = 35; 7int CS = 34; 8int CLK = 32; 9LedControl lc = LedControl(DIN, CLK, CS, 0); 10int NUMBYTE = 1; 11String NUMBYTE_str; 12//END CONFIGURATION LED MATRIX 13 14//START CONFIGURATION Voltage sensor 15const int voltageSensorPin = A3; // sensor pin 16float vIn; // measured voltage (3.3V = max. 16.5V, 5V = max 25V) 17float vOut; 18float voltageSensorVal; // value on pin A3 (0 - 1023) 19const float factor = 5.128; // reduction factor of the Voltage Sensor shield 20const float vCC = 5.00; // Arduino input voltage (measurable by voltmeter) 21//END CONFIGURATION Voltage sensor 22 23//START CONFIGURATION Front Ultrasonic Module pins 24const int trigPin = 52; // 10 microsecond high pulse causes chirp , wait 50 us 25const int echoPin = 53; // Width of high pulse indicates distance 26//END CONFIGURATION Front Ultrasonic Module pins 27 28// START CONFIGURATION Left Ultrasonic Module pins 29const int Left_trigPin = 46; // 10 microsecond high pulse causes chirp , wait 50 us 30const int Left_echoPin = 47; // Width of high pulse indicates distance 31// END CONFIGURATION Left Ultrasonic Module pins 32 33// START CONFIGURATION RightUltrasonic Module pins 34const int Right_trigPin = 40; // 10 microsecond high pulse causes chirp , wait 50 us 35const int Right_echoPin = 41; // Width of high pulse indicates distance 36// END CONFIGURATION RightUltrasonic Module pins 37 38boolean first_run = true; 39int randNumberdelay = 2000; // Initialize Variable 40int buzzerPin = 2; 41int pin_AUTO = 8; //switch Auto /man (REMINDER: ENABLE PULL UP RESISTOR) 42int pin_RIGHT = 23; //Right Limit switch 43int pin_LEFT = 22; //Left Limit switch 44int pin_BLADES = 4; //Relay for blade motor 45int pin_anti_tipping = 24; // Overturning Sensor 46 47// Read distance from the ultrasonic sensor , return distance in mm // 48// Speed of sound in dry air , 20C is 343 m/s 49// pulseIn returns time in microseconds (10^-6) 50// 2d=p*10^-6s*343m/s=p*0.00343m=p*0.343mm/us 51unsigned int readDistance() 52{ 53 digitalWrite ( trigPin , HIGH ); 54 delayMicroseconds (10); 55 digitalWrite ( trigPin , LOW ); 56 unsigned long period = pulseIn ( echoPin, HIGH ); 57 return period * 343 / 2000; 58} 59Ultrasonic ultrasonic(52, 53); 60int distance; 61 62unsigned int readDistance_Left() 63{ 64 digitalWrite ( Left_trigPin , HIGH ); 65 delayMicroseconds (10); 66 digitalWrite ( Left_trigPin , LOW ); 67 unsigned long period = pulseIn ( Left_echoPin, HIGH ); 68 return period * 343 / 2000; 69} 70Ultrasonic Left_ultrasonic(46, 47); 71int Left_distance; 72 73unsigned int readDistance_Right() 74{ 75 digitalWrite ( Right_trigPin , HIGH ); 76 delayMicroseconds (10); 77 digitalWrite ( Right_trigPin , LOW ); 78 unsigned long period = pulseIn ( Right_echoPin, HIGH ); 79 return period * 343 / 2000; 80} 81Ultrasonic Right_ultrasonic(40, 41); 82int Right_distance; 83 84/* The setup() function is called when a sketch starts. It is used to initialize variables, pin modes, start using libraries, etc. This function will only run once, after each power up or reset of the Arduino board. */ 85void setup() 86 87{ 88 Serial.begin(9600); // Baud Rate for Serial Communication 89 Serial1.begin (9600); // Baud Rate for Serial Bluetooth Communication 90 91 pinMode(10, INPUT); // Digital Pin 10 as Input Pin for Motor A 92 pinMode(9, INPUT); // Digital Pin 9 as Input Pin for Motor A 93 pinMode(7, INPUT); // Digital Pin 7 as Input Pin for Motor B 94 pinMode(6, INPUT); // Digital Pin 6 as Input Pin for Motor B 95 pinMode(11, INPUT); // PWM Pin 11 as Input Pin for Motor A 96 pinMode(5, INPUT); // PWM Pin 5 as Input Pin for Motor B 97 pinMode(pin_BLADES, OUTPUT); // Relay for blade motor 98 pinMode(buzzerPin, OUTPUT); // Buzzer 99 pinMode(pin_AUTO, INPUT); //switch Auto / BLUETOOTH man 100 digitalWrite(pin_AUTO, HIGH); //enable pull up resistor (Needed because the switch does not have resistence) 101 pinMode(pin_RIGHT, INPUT); // Digital Pin 22 as Input Pin for Right Limit switch 102 pinMode(pin_LEFT, INPUT); // Digital Pin 23 as Input Pin for Left Limit switch 103 pinMode(pin_anti_tipping, INPUT); // Digital Pin 24 as Input Pin for Overturning Sensor 104 105 //LED MATRIX 106 lc.shutdown(0, false); 107 lc.setIntensity(0, 15); //Adjust the brightness maximum is 15 108 lc.clearDisplay(0); 109} 110 111void loop() 112// put your main code here, to run repeatedly: 113// FOR DEBUG PURPOSE UNCOMMENT Serial.print() 114{ 115 // START LED MATRIX 116 //Facial Expression 117 byte smile[8] = {0x3C, 0x42, 0x99, 0xA5, 0x81, 0xA5, 0x42, 0x3C}; 118 byte neutral[8] = {0x3C, 0x42, 0xBD, 0x81, 0x81, 0xA5, 0x42, 0x3C}; 119 byte sad[8] = {0x3C, 0x42, 0xA5, 0x99, 0x81, 0xA5, 0x42, 0x3C}; 120 121 //Arrow 122 byte arrow_up[8] = {0x18, 0x3C, 0x7E, 0xFF, 0x18, 0x18, 0x18, 0x18}; 123 byte arrow_down[8] = {0x18, 0x18, 0x18, 0x18, 0xFF, 0x7E, 0x3C, 0x18}; 124 byte arrow_left[8] = {0x08, 0x0C, 0x0E, 0xFF, 0xFF, 0x0E, 0x0C, 0x08}; 125 byte arrow_right[8] = {0x10, 0x30, 0x70, 0xFF, 0xFF, 0x70, 0x30, 0x10}; 126 byte arrow_up_right[8] = {0x03, 0x87, 0x8E, 0x9C, 0xB8, 0xF0, 0xE0, 0xFE}; 127 byte arrow_down_right[8] = {0xFE, 0xE0, 0xF0, 0xB8, 0x9C, 0x8E, 0x87, 0x03}; 128 byte arrow_up_left[8] = {0xC1, 0xE1, 0x71, 0x39, 0x1D, 0x0F, 0x07, 0xFF}; 129 byte arrow_down_left[8] = {0x7F, 0x07, 0x0F, 0x1D, 0x39, 0x71, 0xE1, 0xC0}; 130 131 //Alternate Pattern 132 byte d1[8] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55}; 133 byte d2[8] = {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA}; 134 135 //Moving car 136 byte b1[8] = {0x00, 0x00, 0x00, 0x00, 0x18, 0x3C, 0x18, 0x3C}; 137 byte b2[8] = {0x00, 0x00, 0x00, 0x18, 0x3C, 0x18, 0x3C, 0x00}; 138 byte b3[8] = {0x00, 0x00, 0x18, 0x3C, 0x18, 0x3C, 0x00, 0x00}; 139 byte b4[8] = {0x00, 0x18, 0x3C, 0x18, 0x3C, 0x00, 0x00, 0x00}; 140 byte b5[8] = {0x18, 0x3C, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00}; 141 byte b6[8] = {0x3C, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x18}; 142 byte b7[8] = {0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3C}; 143 byte b8[8] = {0x3C, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3C, 0x18}; 144 145 //STOP 146 byte halt[8] = {0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81}; 147 // END LED MATRIX 148 149 voltageSensorVal = analogRead(voltageSensorPin); // read the current sensor value (0 - 1023) 150 vOut = (voltageSensorVal / 1024) * vCC; // convert the value to the real voltage on the analog pin 151 vIn = vOut * factor; // convert the voltage on the source by multiplying with the factor 152 153 /* Serial.print("Voltage = "); 154 Serial.print(vIn); 155 Serial.println("V"); 156 //delay(1000); 157 */ 158 // val = digitalRead(pin_AUTO); 159 if (digitalRead(pin_AUTO) == HIGH) // read the AUTO/Bluetooth switch 160 { 161 162 //************************START AUTO MODE************************ 163 if (first_run == true) { 164 if (vIn < 9) 165 { 166 printByte(sad); //If voltage battery is below 9V the facial expression is sad 167 } else { 168 printByte(smile);//If voltage battery is over 9V the facial expression is smile 169 } 170 // at the beginning wait 5sec and activate the buzzer three times 171 delay(5000); 172 digitalWrite(buzzerPin, HIGH); 173 delay(1000); 174 digitalWrite(buzzerPin, LOW); 175 delay(1000); 176 digitalWrite(buzzerPin, HIGH); 177 delay(1000); 178 digitalWrite(buzzerPin, LOW); 179 delay(1000); 180 digitalWrite(buzzerPin, HIGH); 181 delay(1000); 182 digitalWrite(buzzerPin, LOW); 183 delay(1000); 184 185 digitalWrite(pin_BLADES, HIGH); 186 first_run = false; 187 188 //Serial.println("first_run! "); 189 } 190 distance = ultrasonic.read(); 191 Left_distance = Left_ultrasonic.read(); 192 Right_distance = Right_ultrasonic.read(); 193 //Serial.println(distance); 194 int vicino; 195 int randNumberL; 196 int randNumberR; 197 int randNumberRETRO; 198 199 //Serial.print("distance in cm: "); 200 //Serial.println(distance); 201 //delay(1000); 202 203 204 if (digitalRead(pin_LEFT) == LOW) // read the LEFT limit switch 205 { 206 //Serial.print("PHISICAL OBSTACLE ON LEFT! "); 207 Stop(); 208 printByte(halt); 209 delay(1000); 210 //GO REAR 211 printByte(arrow_up); 212 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 213 digitalWrite(9, LOW); // Pin 9 is Low 214 digitalWrite(6, LOW); // Pin 6 is Low 215 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 216 delay(1000); 217 Stop(); 218 delay(1000); 219 //TURN RIGHT 220 printByte(arrow_right); 221 digitalWrite(10, LOW); // Pin 10 is Low 222 digitalWrite(9, HIGH); // Pin 9 is High for Motor A 223 digitalWrite(6, LOW); // Pin 6 is Low 224 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 225 randNumberdelay = random(2000, 3000); 226 delay(randNumberdelay); 227 Stop(); 228 delay(1000); 229 } else if (digitalRead(pin_RIGHT) == LOW) // read the RIGHT limit switch 230 { 231 //Serial.print("PHISICAL OBSTACLE ON RIGHT! "); 232 Stop(); 233 printByte(halt); 234 delay(1000); 235 //GO REAR 236 printByte(arrow_up); 237 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 238 digitalWrite(9, LOW); // Pin 9 is Low 239 digitalWrite(6, LOW); // Pin 6 is Low 240 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 241 delay(1000); 242 Stop(); 243 delay(1000); 244 //TURN LEFT 245 printByte(arrow_left); 246 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 247 digitalWrite(9, LOW); // Pin 9 is Low 248 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 249 digitalWrite(7, LOW); // Pin 7 is Low 250 randNumberdelay = random(2000, 3000); 251 delay(randNumberdelay); 252 Stop(); 253 delay(1000); 254 } 255 256 //ANTI-TIPPING SENSOR 257 else if (digitalRead(pin_anti_tipping) == LOW) 258 { 259 //Serial.print("DANGER! "); 260 digitalWrite(pin_BLADES, LOW); 261 printByte(sad); 262 Stop(); 263 first_run = true; 264 delay(5000); 265 // END ANTI-TIPPING 266 } 267 else if (Left_distance < 20 ) { 268 // Serial.print("OBSTACLE ON LEFT! "); 269 Stop(); 270 printByte(halt); 271 delay(1000); 272 //GO REAR 273 printByte(arrow_up); 274 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 275 digitalWrite(9, LOW); // Pin 9 is Low 276 digitalWrite(6, LOW); // Pin 6 is Low 277 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 278 delay(1000); 279 Stop(); 280 delay(1000); 281 //TURN RIGHT 282 printByte(arrow_right); 283 digitalWrite(10, LOW); // Pin 10 is Low 284 digitalWrite(9, HIGH); // Pin 9 is High for Motor A 285 digitalWrite(6, LOW); // Pin 6 is Low 286 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 287 randNumberdelay = random(2000, 3000); 288 delay(randNumberdelay); 289 Stop(); 290 } 291 else if (Right_distance < 20 ) { 292 // Serial.print("OBSTACLE ON RIGHT! "); 293 Stop(); 294 printByte(halt); 295 delay(1000); 296 //GO REAR 297 printByte(arrow_up); 298 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 299 digitalWrite(9, LOW); // Pin 9 is Low 300 digitalWrite(6, LOW); // Pin 6 is Low 301 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 302 delay(1000); 303 Stop(); 304 delay(1000); 305 //TURN LEFT 306 printByte(arrow_left); 307 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 308 digitalWrite(9, LOW); // Pin 9 is Low 309 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 310 digitalWrite(7, LOW); // Pin 7 is Low 311 randNumberdelay = random(2000, 3000); 312 delay(randNumberdelay); 313 Stop(); 314 } 315 else if (distance > 20 ) { 316 //GO FORWARD 317 // Serial.print("FORWARD! "); 318 switch (NUMBYTE) { 319 case 1: 320 printByte(b1); 321 break; 322 case 2: 323 printByte(b2); 324 break; 325 case 3: 326 printByte(b3); 327 break; 328 case 4: 329 printByte(b4); 330 break; 331 case 5: 332 printByte(b5); 333 break; 334 case 6: 335 printByte(b6); 336 break; 337 case 7: 338 printByte(b7); 339 break; 340 case 8: 341 printByte(b8); 342 break; 343 default: 344 printByte(b1); 345 break; 346 } 347 348 delay(50); 349 NUMBYTE = NUMBYTE + 1; 350 if (NUMBYTE > 8) { 351 NUMBYTE = 1; 352 } 353 354 digitalWrite(10, LOW); // Pin 10 is Low 355 digitalWrite(9, HIGH); // Pin 9 is High for Motor A 356 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 357 digitalWrite(7, LOW); // Pin 7 is Low 358 analogWrite(11, 255 * 0.8); 359 analogWrite(5, 255 * 0.8); 360 361 } else 362 { 363 Stop(); 364 printByte(halt); 365 delay(1000); 366 //GO REAR 367 printByte(arrow_up); 368 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 369 digitalWrite(9, LOW); // Pin 9 is Low 370 digitalWrite(6, LOW); // Pin 6 is Low 371 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 372 delay(1000); 373 Stop(); 374 delay(1000); 375 //TURN LEFT 376 printByte(arrow_left); 377 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 378 digitalWrite(9, LOW); // Pin 9 is Low 379 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 380 digitalWrite(7, LOW); // Pin 7 is Low 381 randNumberdelay = random(2000, 3000); 382 delay(randNumberdelay); 383 Stop(); 384 } 385 //************************END AUTO MODE************************ 386 } 387 else { 388 389 //Serial.println("Bluetooth"); 390 //Stop(); 391 //************************START BLUETOOTH MANUAL MODE************************ 392 //USE BLUETOOTH RC CONTROL APP TO CONNECT 393 if (Serial1.available() > 0) // Check if Data is available 394 395 { 396 397 int data = Serial1.read(); // Read the Data 398 399 Stop(); 400 if (data == 'L') // For Left Movement 401 { 402 //Serial.println("BLUETOOTH LEFT! "); 403 analogWrite(11, 250); 404 analogWrite(5, 250); 405 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 406 digitalWrite(9, LOW); // Pin 9 is Low 407 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 408 digitalWrite(7, LOW); // Pin 7 is Low 409 printByte(arrow_left); 410 } 411 else if (data == 'R') // For Right Movement 412 { 413 //Serial.println("BLUETOOTH RIGHT! "); 414 analogWrite(11, 250); 415 analogWrite(5, 250); 416 digitalWrite(10, LOW); // Pin 10 is Low 417 digitalWrite(9, HIGH); // Pin 9 is High for Motor A 418 digitalWrite(6, LOW); // Pin 6 is Low 419 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 420 printByte(arrow_right); 421 } 422 else if (data == 'F') // For Forward Movement 423 { 424 //Serial.println("BLUETOOTH FORWARD! "); 425 analogWrite(11, 250); 426 analogWrite(5, 250); 427 digitalWrite(10, LOW); // Pin 10 is Low 428 digitalWrite(9, HIGH); // Pin 9 is High for Motor A 429 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 430 digitalWrite(7, LOW); // Pin 7 is Low 431 //GO FORWARD 432 //Serial.print("FORWARD! "); 433 switch (NUMBYTE) { 434 case 1: 435 printByte(b1); 436 break; 437 case 2: 438 printByte(b2); 439 break; 440 case 3: 441 printByte(b3); 442 break; 443 case 4: 444 printByte(b4); 445 break; 446 case 5: 447 printByte(b5); 448 break; 449 case 6: 450 printByte(b6); 451 break; 452 case 7: 453 printByte(b7); 454 break; 455 case 8: 456 printByte(b8); 457 break; 458 default: 459 printByte(b1); 460 break; 461 } 462 //delay(50); 463 NUMBYTE = NUMBYTE + 1; 464 if (NUMBYTE > 8) { 465 NUMBYTE = 1; 466 } 467 } 468 else if (data == 'B') // For Backward Movement 469 { 470 //Serial.println("BACKWARD ! "); 471 analogWrite(11, 250); 472 analogWrite(5, 250); 473 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 474 digitalWrite(9, LOW); // Pin 9 is Low 475 digitalWrite(6, LOW); // Pin 6 is Low 476 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 477 478 switch (NUMBYTE) { 479 case 1: 480 printByte(b1); 481 break; 482 case 2: 483 printByte(b2); 484 break; 485 case 3: 486 printByte(b3); 487 break; 488 case 4: 489 printByte(b4); 490 break; 491 case 5: 492 printByte(b5); 493 break; 494 case 6: 495 printByte(b6); 496 break; 497 case 7: 498 printByte(b7); 499 break; 500 case 8: 501 printByte(b8); 502 break; 503 default: 504 printByte(b1); 505 break; 506 } 507 //delay(50); 508 NUMBYTE = NUMBYTE - 1; 509 if (NUMBYTE < 1) { 510 NUMBYTE = 9; 511 } 512 } 513 else if (data == 'G') // Forward left 514 { 515 //Serial.println("BLUETOOTH FORWARD LEFT! "); 516 analogWrite(11, 50); 517 analogWrite(5, 255); 518 digitalWrite(10, LOW); // Pin 10 is Low 519 digitalWrite(9, HIGH); // Pin 9 is High for Motor A 520 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 521 digitalWrite(7, LOW); // Pin 7 is Low 522 printByte(arrow_up_left); 523 } 524 else if (data == 'I') // Forward right 525 { 526 analogWrite(11, 255); 527 analogWrite(5, 50); 528 digitalWrite(10, LOW); // Pin 10 is Low 529 digitalWrite(9, HIGH); // Pin 9 is High for Motor A 530 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 531 digitalWrite(7, LOW); // Pin 7 is Low 532 printByte(arrow_up_right); 533 } 534 else if (data == 'J') // Back right 535 { 536 analogWrite(11, 255); 537 analogWrite(5, 50); 538 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 539 digitalWrite(9, LOW); // Pin 9 is Low 540 digitalWrite(6, LOW); // Pin 6 is Low 541 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 542 printByte(arrow_down_right); 543 } 544 else if (data == 'H') // Back left 545 { 546 analogWrite(11, 50); 547 analogWrite(5, 255); 548 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 549 digitalWrite(9, LOW); // Pin 9 is Low 550 digitalWrite(6, LOW); // Pin 6 is Low 551 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 552 printByte(arrow_down_left); 553 } 554 else if (data == 'q') // For 100% speed 555 { 556 analogWrite(11, 255); 557 analogWrite(5, 255); 558 } 559 else if (data == '9') // For 90% speed 560 { 561 analogWrite(11, 255 * 0.9); 562 analogWrite(5, 255 * 0.9); 563 } 564 else if (data == '8') // For 80% speed 565 { 566 analogWrite(11, 255 * 0.8); 567 analogWrite(5, 255 * 0.8); 568 } 569 else if (data == '7') // For 70% speed 570 { 571 analogWrite(11, 255 * 0.7); 572 analogWrite(5, 255 * 0.7); 573 } 574 else if (data == '6') // For 60% speed 575 { 576 analogWrite(11, 255 * 0.6); 577 analogWrite(5, 255 * 0.6); 578 } 579 else if (data == '5') // For 50% speed 580 { 581 analogWrite(11, 255 * 0.5); 582 analogWrite(5, 255 * 0.5); 583 } 584 else if (data == '4') // For 40% speed 585 { 586 analogWrite(11, 255 * 0.4); 587 analogWrite(5, 255 * 0.4); 588 } 589 else if (data == '3') // For 30% speed 590 { 591 analogWrite(11, 255 * 0.3); 592 analogWrite(5, 255 * 0.3); 593 } 594 else if (data == '2') // For 20% speed 595 { 596 analogWrite(11, 255 * 0.2); 597 analogWrite(5, 255 * 0.2); 598 } 599 else if (data == '1') // For 10% speed 600 { 601 analogWrite(11, 255 * 0.1); 602 analogWrite(5, 255 * 0.1); 603 } 604 else if (data == '0') // For 0% speed 605 { 606 Stop(); 607 } 608 else if (data == 'X') // Activate relay 609 { 610 digitalWrite(pin_BLADES, HIGH); 611 } 612 else if (data == 'x') // deactivate relay 613 { 614 digitalWrite(pin_BLADES, LOW); 615 } 616 else if (data == 'V') // Activate Buzzer 617 { 618 digitalWrite(buzzerPin, HIGH); 619 } 620 else if (data == 'v') // deactivate Buzzer 621 { 622 digitalWrite(buzzerPin, LOW); 623 } 624 625 626 627 } 628 first_run = true; 629 630 } 631 //************************END BLUETOOTH MANUAL MODE************************ 632} 633void Stop() // Function to Stop the Motor 634 635{ 636 digitalWrite(10, LOW); // Pin 10 is Low 637 digitalWrite(9, LOW); // Pin 9 is Low 638 digitalWrite(6, LOW); // Pin 6 is Low 639 digitalWrite(7, LOW); // Pin 7 is Low 640} 641//PRINT ON MATRIX DISPLAY 8x8 642void printByte(byte character []) 643{ 644 int i = 0; 645 for (i = 0; i < 8; i++) 646 { 647 lc.setRow(0, i, character[i]); 648 } 649}
Mowerino
c_cpp
Arduino Software
1#include <L298N.h> // Library for L298N Motor Driver Module 2#include <Ultrasonic.h> // Library for Ultrasonic sensor 3#include <LedControl.h> // Library for Led Matrix 8x8 4 5//START CONFIGURATION LED MATRIX 6int DIN = 35; 7int CS = 34; 8int CLK = 32; 9LedControl lc = LedControl(DIN, CLK, CS, 0); 10int NUMBYTE = 1; 11String NUMBYTE_str; 12//END CONFIGURATION LED MATRIX 13 14//START CONFIGURATION Voltage sensor 15const int voltageSensorPin = A3; // sensor pin 16float vIn; // measured voltage (3.3V = max. 16.5V, 5V = max 25V) 17float vOut; 18float voltageSensorVal; // value on pin A3 (0 - 1023) 19const float factor = 5.128; // reduction factor of the Voltage Sensor shield 20const float vCC = 5.00; // Arduino input voltage (measurable by voltmeter) 21//END CONFIGURATION Voltage sensor 22 23//START CONFIGURATION Front Ultrasonic Module pins 24const int trigPin = 52; // 10 microsecond high pulse causes chirp , wait 50 us 25const int echoPin = 53; // Width of high pulse indicates distance 26//END CONFIGURATION Front Ultrasonic Module pins 27 28// START CONFIGURATION Left Ultrasonic Module pins 29const int Left_trigPin = 46; // 10 microsecond high pulse causes chirp , wait 50 us 30const int Left_echoPin = 47; // Width of high pulse indicates distance 31// END CONFIGURATION Left Ultrasonic Module pins 32 33// START CONFIGURATION RightUltrasonic Module pins 34const int Right_trigPin = 40; // 10 microsecond high pulse causes chirp , wait 50 us 35const int Right_echoPin = 41; // Width of high pulse indicates distance 36// END CONFIGURATION RightUltrasonic Module pins 37 38boolean first_run = true; 39int randNumberdelay = 2000; // Initialize Variable 40int buzzerPin = 2; 41int pin_AUTO = 8; //switch Auto /man (REMINDER: ENABLE PULL UP RESISTOR) 42int pin_RIGHT = 23; //Right Limit switch 43int pin_LEFT = 22; //Left Limit switch 44int pin_BLADES = 4; //Relay for blade motor 45int pin_anti_tipping = 24; // Overturning Sensor 46 47// Read distance from the ultrasonic sensor , return distance in mm // 48// Speed of sound in dry air , 20C is 343 m/s 49// pulseIn returns time in microseconds (10^-6) 50// 2d=p*10^-6s*343m/s=p*0.00343m=p*0.343mm/us 51unsigned int readDistance() 52{ 53 digitalWrite ( trigPin , HIGH ); 54 delayMicroseconds (10); 55 digitalWrite ( trigPin , LOW ); 56 unsigned long period = pulseIn ( echoPin, HIGH ); 57 return period * 343 / 2000; 58} 59Ultrasonic ultrasonic(52, 53); 60int distance; 61 62unsigned int readDistance_Left() 63{ 64 digitalWrite ( Left_trigPin , HIGH ); 65 delayMicroseconds (10); 66 digitalWrite ( Left_trigPin , LOW ); 67 unsigned long period = pulseIn ( Left_echoPin, HIGH ); 68 return period * 343 / 2000; 69} 70Ultrasonic Left_ultrasonic(46, 47); 71int Left_distance; 72 73unsigned int readDistance_Right() 74{ 75 digitalWrite ( Right_trigPin , HIGH ); 76 delayMicroseconds (10); 77 digitalWrite ( Right_trigPin , LOW ); 78 unsigned long period = pulseIn ( Right_echoPin, HIGH ); 79 return period * 343 / 2000; 80} 81Ultrasonic Right_ultrasonic(40, 41); 82int Right_distance; 83 84/* The setup() function is called when a sketch starts. It is used to initialize variables, pin modes, start using libraries, etc. This function will only run once, after each power up or reset of the Arduino board. */ 85void setup() 86 87{ 88 Serial.begin(9600); // Baud Rate for Serial Communication 89 Serial1.begin (9600); // Baud Rate for Serial Bluetooth Communication 90 91 pinMode(10, INPUT); // Digital Pin 10 as Input Pin for Motor A 92 pinMode(9, INPUT); // Digital Pin 9 as Input Pin for Motor A 93 pinMode(7, INPUT); // Digital Pin 7 as Input Pin for Motor B 94 pinMode(6, INPUT); // Digital Pin 6 as Input Pin for Motor B 95 pinMode(11, INPUT); // PWM Pin 11 as Input Pin for Motor A 96 pinMode(5, INPUT); // PWM Pin 5 as Input Pin for Motor B 97 pinMode(pin_BLADES, OUTPUT); // Relay for blade motor 98 pinMode(buzzerPin, OUTPUT); // Buzzer 99 pinMode(pin_AUTO, INPUT); //switch Auto / BLUETOOTH man 100 digitalWrite(pin_AUTO, HIGH); //enable pull up resistor (Needed because the switch does not have resistence) 101 pinMode(pin_RIGHT, INPUT); // Digital Pin 22 as Input Pin for Right Limit switch 102 pinMode(pin_LEFT, INPUT); // Digital Pin 23 as Input Pin for Left Limit switch 103 pinMode(pin_anti_tipping, INPUT); // Digital Pin 24 as Input Pin for Overturning Sensor 104 105 //LED MATRIX 106 lc.shutdown(0, false); 107 lc.setIntensity(0, 15); //Adjust the brightness maximum is 15 108 lc.clearDisplay(0); 109} 110 111void loop() 112// put your main code here, to run repeatedly: 113// FOR DEBUG PURPOSE UNCOMMENT Serial.print() 114{ 115 // START LED MATRIX 116 //Facial Expression 117 byte smile[8] = {0x3C, 0x42, 0x99, 0xA5, 0x81, 0xA5, 0x42, 0x3C}; 118 byte neutral[8] = {0x3C, 0x42, 0xBD, 0x81, 0x81, 0xA5, 0x42, 0x3C}; 119 byte sad[8] = {0x3C, 0x42, 0xA5, 0x99, 0x81, 0xA5, 0x42, 0x3C}; 120 121 //Arrow 122 byte arrow_up[8] = {0x18, 0x3C, 0x7E, 0xFF, 0x18, 0x18, 0x18, 0x18}; 123 byte arrow_down[8] = {0x18, 0x18, 0x18, 0x18, 0xFF, 0x7E, 0x3C, 0x18}; 124 byte arrow_left[8] = {0x08, 0x0C, 0x0E, 0xFF, 0xFF, 0x0E, 0x0C, 0x08}; 125 byte arrow_right[8] = {0x10, 0x30, 0x70, 0xFF, 0xFF, 0x70, 0x30, 0x10}; 126 byte arrow_up_right[8] = {0x03, 0x87, 0x8E, 0x9C, 0xB8, 0xF0, 0xE0, 0xFE}; 127 byte arrow_down_right[8] = {0xFE, 0xE0, 0xF0, 0xB8, 0x9C, 0x8E, 0x87, 0x03}; 128 byte arrow_up_left[8] = {0xC1, 0xE1, 0x71, 0x39, 0x1D, 0x0F, 0x07, 0xFF}; 129 byte arrow_down_left[8] = {0x7F, 0x07, 0x0F, 0x1D, 0x39, 0x71, 0xE1, 0xC0}; 130 131 //Alternate Pattern 132 byte d1[8] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55}; 133 byte d2[8] = {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA}; 134 135 //Moving car 136 byte b1[8] = {0x00, 0x00, 0x00, 0x00, 0x18, 0x3C, 0x18, 0x3C}; 137 byte b2[8] = {0x00, 0x00, 0x00, 0x18, 0x3C, 0x18, 0x3C, 0x00}; 138 byte b3[8] = {0x00, 0x00, 0x18, 0x3C, 0x18, 0x3C, 0x00, 0x00}; 139 byte b4[8] = {0x00, 0x18, 0x3C, 0x18, 0x3C, 0x00, 0x00, 0x00}; 140 byte b5[8] = {0x18, 0x3C, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00}; 141 byte b6[8] = {0x3C, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x18}; 142 byte b7[8] = {0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3C}; 143 byte b8[8] = {0x3C, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3C, 0x18}; 144 145 //STOP 146 byte halt[8] = {0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81}; 147 // END LED MATRIX 148 149 voltageSensorVal = analogRead(voltageSensorPin); // read the current sensor value (0 - 1023) 150 vOut = (voltageSensorVal / 1024) * vCC; // convert the value to the real voltage on the analog pin 151 vIn = vOut * factor; // convert the voltage on the source by multiplying with the factor 152 153 /* Serial.print("Voltage = "); 154 Serial.print(vIn); 155 Serial.println("V"); 156 //delay(1000); 157 */ 158 // val = digitalRead(pin_AUTO); 159 if (digitalRead(pin_AUTO) == HIGH) // read the AUTO/Bluetooth switch 160 { 161 162 //************************START AUTO MODE************************ 163 if (first_run == true) { 164 if (vIn < 9) 165 { 166 printByte(sad); //If voltage battery is below 9V the facial expression is sad 167 } else { 168 printByte(smile);//If voltage battery is over 9V the facial expression is smile 169 } 170 // at the beginning wait 5sec and activate the buzzer three times 171 delay(5000); 172 digitalWrite(buzzerPin, HIGH); 173 delay(1000); 174 digitalWrite(buzzerPin, LOW); 175 delay(1000); 176 digitalWrite(buzzerPin, HIGH); 177 delay(1000); 178 digitalWrite(buzzerPin, LOW); 179 delay(1000); 180 digitalWrite(buzzerPin, HIGH); 181 delay(1000); 182 digitalWrite(buzzerPin, LOW); 183 delay(1000); 184 185 digitalWrite(pin_BLADES, HIGH); 186 first_run = false; 187 188 //Serial.println("first_run! "); 189 } 190 distance = ultrasonic.read(); 191 Left_distance = Left_ultrasonic.read(); 192 Right_distance = Right_ultrasonic.read(); 193 //Serial.println(distance); 194 int vicino; 195 int randNumberL; 196 int randNumberR; 197 int randNumberRETRO; 198 199 //Serial.print("distance in cm: "); 200 //Serial.println(distance); 201 //delay(1000); 202 203 204 if (digitalRead(pin_LEFT) == LOW) // read the LEFT limit switch 205 { 206 //Serial.print("PHISICAL OBSTACLE ON LEFT! "); 207 Stop(); 208 printByte(halt); 209 delay(1000); 210 //GO REAR 211 printByte(arrow_up); 212 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 213 digitalWrite(9, LOW); // Pin 9 is Low 214 digitalWrite(6, LOW); // Pin 6 is Low 215 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 216 delay(1000); 217 Stop(); 218 delay(1000); 219 //TURN RIGHT 220 printByte(arrow_right); 221 digitalWrite(10, LOW); // Pin 10 is Low 222 digitalWrite(9, HIGH); // Pin 9 is High for Motor A 223 digitalWrite(6, LOW); // Pin 6 is Low 224 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 225 randNumberdelay = random(2000, 3000); 226 delay(randNumberdelay); 227 Stop(); 228 delay(1000); 229 } else if (digitalRead(pin_RIGHT) == LOW) // read the RIGHT limit switch 230 { 231 //Serial.print("PHISICAL OBSTACLE ON RIGHT! "); 232 Stop(); 233 printByte(halt); 234 delay(1000); 235 //GO REAR 236 printByte(arrow_up); 237 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 238 digitalWrite(9, LOW); // Pin 9 is Low 239 digitalWrite(6, LOW); // Pin 6 is Low 240 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 241 delay(1000); 242 Stop(); 243 delay(1000); 244 //TURN LEFT 245 printByte(arrow_left); 246 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 247 digitalWrite(9, LOW); // Pin 9 is Low 248 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 249 digitalWrite(7, LOW); // Pin 7 is Low 250 randNumberdelay = random(2000, 3000); 251 delay(randNumberdelay); 252 Stop(); 253 delay(1000); 254 } 255 256 //ANTI-TIPPING SENSOR 257 else if (digitalRead(pin_anti_tipping) == LOW) 258 { 259 //Serial.print("DANGER! "); 260 digitalWrite(pin_BLADES, LOW); 261 printByte(sad); 262 Stop(); 263 first_run = true; 264 delay(5000); 265 // END ANTI-TIPPING 266 } 267 else if (Left_distance < 20 ) { 268 // Serial.print("OBSTACLE ON LEFT! "); 269 Stop(); 270 printByte(halt); 271 delay(1000); 272 //GO REAR 273 printByte(arrow_up); 274 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 275 digitalWrite(9, LOW); // Pin 9 is Low 276 digitalWrite(6, LOW); // Pin 6 is Low 277 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 278 delay(1000); 279 Stop(); 280 delay(1000); 281 //TURN RIGHT 282 printByte(arrow_right); 283 digitalWrite(10, LOW); // Pin 10 is Low 284 digitalWrite(9, HIGH); // Pin 9 is High for Motor A 285 digitalWrite(6, LOW); // Pin 6 is Low 286 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 287 randNumberdelay = random(2000, 3000); 288 delay(randNumberdelay); 289 Stop(); 290 } 291 else if (Right_distance < 20 ) { 292 // Serial.print("OBSTACLE ON RIGHT! "); 293 Stop(); 294 printByte(halt); 295 delay(1000); 296 //GO REAR 297 printByte(arrow_up); 298 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 299 digitalWrite(9, LOW); // Pin 9 is Low 300 digitalWrite(6, LOW); // Pin 6 is Low 301 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 302 delay(1000); 303 Stop(); 304 delay(1000); 305 //TURN LEFT 306 printByte(arrow_left); 307 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 308 digitalWrite(9, LOW); // Pin 9 is Low 309 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 310 digitalWrite(7, LOW); // Pin 7 is Low 311 randNumberdelay = random(2000, 3000); 312 delay(randNumberdelay); 313 Stop(); 314 } 315 else if (distance > 20 ) { 316 //GO FORWARD 317 // Serial.print("FORWARD! "); 318 switch (NUMBYTE) { 319 case 1: 320 printByte(b1); 321 break; 322 case 2: 323 printByte(b2); 324 break; 325 case 3: 326 printByte(b3); 327 break; 328 case 4: 329 printByte(b4); 330 break; 331 case 5: 332 printByte(b5); 333 break; 334 case 6: 335 printByte(b6); 336 break; 337 case 7: 338 printByte(b7); 339 break; 340 case 8: 341 printByte(b8); 342 break; 343 default: 344 printByte(b1); 345 break; 346 } 347 348 delay(50); 349 NUMBYTE = NUMBYTE + 1; 350 if (NUMBYTE > 8) { 351 NUMBYTE = 1; 352 } 353 354 digitalWrite(10, LOW); // Pin 10 is Low 355 digitalWrite(9, HIGH); // Pin 9 is High for Motor A 356 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 357 digitalWrite(7, LOW); // Pin 7 is Low 358 analogWrite(11, 255 * 0.8); 359 analogWrite(5, 255 * 0.8); 360 361 } else 362 { 363 Stop(); 364 printByte(halt); 365 delay(1000); 366 //GO REAR 367 printByte(arrow_up); 368 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 369 digitalWrite(9, LOW); // Pin 9 is Low 370 digitalWrite(6, LOW); // Pin 6 is Low 371 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 372 delay(1000); 373 Stop(); 374 delay(1000); 375 //TURN LEFT 376 printByte(arrow_left); 377 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 378 digitalWrite(9, LOW); // Pin 9 is Low 379 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 380 digitalWrite(7, LOW); // Pin 7 is Low 381 randNumberdelay = random(2000, 3000); 382 delay(randNumberdelay); 383 Stop(); 384 } 385 //************************END AUTO MODE************************ 386 } 387 else { 388 389 //Serial.println("Bluetooth"); 390 //Stop(); 391 //************************START BLUETOOTH MANUAL MODE************************ 392 //USE BLUETOOTH RC CONTROL APP TO CONNECT 393 if (Serial1.available() > 0) // Check if Data is available 394 395 { 396 397 int data = Serial1.read(); // Read the Data 398 399 Stop(); 400 if (data == 'L') // For Left Movement 401 { 402 //Serial.println("BLUETOOTH LEFT! "); 403 analogWrite(11, 250); 404 analogWrite(5, 250); 405 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 406 digitalWrite(9, LOW); // Pin 9 is Low 407 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 408 digitalWrite(7, LOW); // Pin 7 is Low 409 printByte(arrow_left); 410 } 411 else if (data == 'R') // For Right Movement 412 { 413 //Serial.println("BLUETOOTH RIGHT! "); 414 analogWrite(11, 250); 415 analogWrite(5, 250); 416 digitalWrite(10, LOW); // Pin 10 is Low 417 digitalWrite(9, HIGH); // Pin 9 is High for Motor A 418 digitalWrite(6, LOW); // Pin 6 is Low 419 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 420 printByte(arrow_right); 421 } 422 else if (data == 'F') // For Forward Movement 423 { 424 //Serial.println("BLUETOOTH FORWARD! "); 425 analogWrite(11, 250); 426 analogWrite(5, 250); 427 digitalWrite(10, LOW); // Pin 10 is Low 428 digitalWrite(9, HIGH); // Pin 9 is High for Motor A 429 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 430 digitalWrite(7, LOW); // Pin 7 is Low 431 //GO FORWARD 432 //Serial.print("FORWARD! "); 433 switch (NUMBYTE) { 434 case 1: 435 printByte(b1); 436 break; 437 case 2: 438 printByte(b2); 439 break; 440 case 3: 441 printByte(b3); 442 break; 443 case 4: 444 printByte(b4); 445 break; 446 case 5: 447 printByte(b5); 448 break; 449 case 6: 450 printByte(b6); 451 break; 452 case 7: 453 printByte(b7); 454 break; 455 case 8: 456 printByte(b8); 457 break; 458 default: 459 printByte(b1); 460 break; 461 } 462 //delay(50); 463 NUMBYTE = NUMBYTE + 1; 464 if (NUMBYTE > 8) { 465 NUMBYTE = 1; 466 } 467 } 468 else if (data == 'B') // For Backward Movement 469 { 470 //Serial.println("BACKWARD ! "); 471 analogWrite(11, 250); 472 analogWrite(5, 250); 473 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 474 digitalWrite(9, LOW); // Pin 9 is Low 475 digitalWrite(6, LOW); // Pin 6 is Low 476 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 477 478 switch (NUMBYTE) { 479 case 1: 480 printByte(b1); 481 break; 482 case 2: 483 printByte(b2); 484 break; 485 case 3: 486 printByte(b3); 487 break; 488 case 4: 489 printByte(b4); 490 break; 491 case 5: 492 printByte(b5); 493 break; 494 case 6: 495 printByte(b6); 496 break; 497 case 7: 498 printByte(b7); 499 break; 500 case 8: 501 printByte(b8); 502 break; 503 default: 504 printByte(b1); 505 break; 506 } 507 //delay(50); 508 NUMBYTE = NUMBYTE - 1; 509 if (NUMBYTE < 1) { 510 NUMBYTE = 9; 511 } 512 } 513 else if (data == 'G') // Forward left 514 { 515 //Serial.println("BLUETOOTH FORWARD LEFT! "); 516 analogWrite(11, 50); 517 analogWrite(5, 255); 518 digitalWrite(10, LOW); // Pin 10 is Low 519 digitalWrite(9, HIGH); // Pin 9 is High for Motor A 520 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 521 digitalWrite(7, LOW); // Pin 7 is Low 522 printByte(arrow_up_left); 523 } 524 else if (data == 'I') // Forward right 525 { 526 analogWrite(11, 255); 527 analogWrite(5, 50); 528 digitalWrite(10, LOW); // Pin 10 is Low 529 digitalWrite(9, HIGH); // Pin 9 is High for Motor A 530 digitalWrite(6, HIGH); // Pin 6 is High for Motor B 531 digitalWrite(7, LOW); // Pin 7 is Low 532 printByte(arrow_up_right); 533 } 534 else if (data == 'J') // Back right 535 { 536 analogWrite(11, 255); 537 analogWrite(5, 50); 538 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 539 digitalWrite(9, LOW); // Pin 9 is Low 540 digitalWrite(6, LOW); // Pin 6 is Low 541 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 542 printByte(arrow_down_right); 543 } 544 else if (data == 'H') // Back left 545 { 546 analogWrite(11, 50); 547 analogWrite(5, 255); 548 digitalWrite(10, HIGH); // Pin 10 is High for Motor A 549 digitalWrite(9, LOW); // Pin 9 is Low 550 digitalWrite(6, LOW); // Pin 6 is Low 551 digitalWrite(7, HIGH); // Pin 7 is High for Motor B 552 printByte(arrow_down_left); 553 } 554 else if (data == 'q') // For 100% speed 555 { 556 analogWrite(11, 255); 557 analogWrite(5, 255); 558 } 559 else if (data == '9') // For 90% speed 560 { 561 analogWrite(11, 255 * 0.9); 562 analogWrite(5, 255 * 0.9); 563 } 564 else if (data == '8') // For 80% speed 565 { 566 analogWrite(11, 255 * 0.8); 567 analogWrite(5, 255 * 0.8); 568 } 569 else if (data == '7') // For 70% speed 570 { 571 analogWrite(11, 255 * 0.7); 572 analogWrite(5, 255 * 0.7); 573 } 574 else if (data == '6') // For 60% speed 575 { 576 analogWrite(11, 255 * 0.6); 577 analogWrite(5, 255 * 0.6); 578 } 579 else if (data == '5') // For 50% speed 580 { 581 analogWrite(11, 255 * 0.5); 582 analogWrite(5, 255 * 0.5); 583 } 584 else if (data == '4') // For 40% speed 585 { 586 analogWrite(11, 255 * 0.4); 587 analogWrite(5, 255 * 0.4); 588 } 589 else if (data == '3') // For 30% speed 590 { 591 analogWrite(11, 255 * 0.3); 592 analogWrite(5, 255 * 0.3); 593 } 594 else if (data == '2') // For 20% speed 595 { 596 analogWrite(11, 255 * 0.2); 597 analogWrite(5, 255 * 0.2); 598 } 599 else if (data == '1') // For 10% speed 600 { 601 analogWrite(11, 255 * 0.1); 602 analogWrite(5, 255 * 0.1); 603 } 604 else if (data == '0') // For 0% speed 605 { 606 Stop(); 607 } 608 else if (data == 'X') // Activate relay 609 { 610 digitalWrite(pin_BLADES, HIGH); 611 } 612 else if (data == 'x') // deactivate relay 613 { 614 digitalWrite(pin_BLADES, LOW); 615 } 616 else if (data == 'V') // Activate Buzzer 617 { 618 digitalWrite(buzzerPin, HIGH); 619 } 620 else if (data == 'v') // deactivate Buzzer 621 { 622 digitalWrite(buzzerPin, LOW); 623 } 624 625 626 627 } 628 first_run = true; 629 630 } 631 //************************END BLUETOOTH MANUAL MODE************************ 632} 633void Stop() // Function to Stop the Motor 634 635{ 636 digitalWrite(10, LOW); // Pin 10 is Low 637 digitalWrite(9, LOW); // Pin 9 is Low 638 digitalWrite(6, LOW); // Pin 6 is Low 639 digitalWrite(7, LOW); // Pin 7 is Low 640} 641//PRINT ON MATRIX DISPLAY 8x8 642void printByte(byte character []) 643{ 644 int i = 0; 645 for (i = 0; i < 8; i++) 646 { 647 lc.setRow(0, i, character[i]); 648 } 649}
Downloadable files
Mowerino schematics
This diagram shows how to connect all sensors and items to Arduino Board. Color code: RED = 12VDC, BLACK= GND, ORANGE= 5VDC
Mowerino schematics
Mowerino schematics
This diagram shows how to connect all sensors and items to Arduino Board. Color code: RED = 12VDC, BLACK= GND, ORANGE= 5VDC
Mowerino schematics
Documentation
Right Bulkhead
Right Bulkhead
Motor Support Right
Motor Support Right
Motor Support Left
Motor Support Left
Motor Support Cover Left
Motor Support Cover Left
Rear Bulkhead
Rear Bulkhead
Chassis
Chassis
Motor Support Cover Right
Motor Support Cover Right
Wheel
Print two times
Wheel
Cutter Disk
The slot allows you to tighten the motor fixing screws
Cutter Disk
Top Cover
Top Cover
Front Bulkhead
Front Bulkhead
Front Wheel Support Left
Front Wheel Support Left
Left Bulkhead
Left Bulkhead
Front Wheel Support Right
Front Wheel Support Right
Front Bulkhead
Front Bulkhead
Top Cover
Top Cover
Motor Support Cover Right
Motor Support Cover Right
Motor Support Left
Motor Support Left
Motor Support Cover Left
Motor Support Cover Left
Front Wheel Support Left
Front Wheel Support Left
Rear Bulkhead
Rear Bulkhead
Blade motor Support
Blade motor Support
Left Bulkhead
Left Bulkhead
Wheel
Print two times
Wheel
Chassis
Chassis
Front Wheel Support Right
Front Wheel Support Right
Cutter Disk
The slot allows you to tighten the motor fixing screws
Cutter Disk
Motor Support Right
Motor Support Right
Right Bulkhead
Right Bulkhead
Comments
Only logged in users can leave comments