Grabber (Crab) Robot - Arduino | Bluetooth | Remote Control via Application



In this project we will make a fun robot. This robot looks like a crab. With a phone application you can control the robot via bluetooth and grab (pick up) anything that is on the ground. In this project you can learn to create an android application and control Arduino via the HC-06 or HC-05 bluetooth module. Required Hardware Arduino Board -- https://goo.gl/RcRmi1 Plastic Grab Arm -- https://goo.gl/1pTZ8D Chassis Model 1 -- https://goo.gl/BNW9Vd Chassis Model 2 -- https://goo.gl/ihAU41 Chassis Model 3 -- https://goo.gl/pPQ6mg Motor Shield L293D -- https://goo.gl/vP6jkm Servo Motor MG996R -- https://goo.gl/gj2cZs Bluetooth Module -- https://goo.gl/HVaxpo Li-ion Battery -- https://goo.gl/en2fyC Li-ion Battery Holder -- https://goo.gl/B7DX8D 9V Rechargeable Battery -- https://goo.gl/xaD6Tf Jumper Wires -- https://goo.gl/94xaTi Hot Glue Gun -- https://goo.gl/2znyr6 Braid Line -- https://goo.gl/EhSdXM For Motor Shield Modification Male Pin Header -- https://goo.gl/ZC7hBE Soldering Tool Kit -- https://goo.gl/2oZhtu Soldering Stand -- https://goo.gl/2n8gds Solder Wire -- https://goo.gl/FC7W6o Arduino Basic Starter Kit -- https://goo.gl/ZJ6jxV ------------------------------------------------------ How to Install Library -- https://youtu.be/Es8D1q_b-c4 AFMotor Library -- https://goo.gl/rK9QvV ------------------------------------------------------ Application aia and apk files -- https://goo.gl/s46KJr MIT App Inventor -- http://appinventor.mit.edu ------------------------------------------------------

Source Code:
/* Before you can use the Motor shield, you must install the AF_Motor Arduino library
https://github.com/adafruit/Adafruit-Motor-Shield-library 
Install and Use Arduino Libraries -- https://youtu.be/Es8D1q_b-c4 */
#include <AFMotor.h>

/*include Servo motor library*/
#include <Servo.h>

/* Create the AF_DCMotor object with AF_DCMotor(motor#, frequency)
The first is which port the motor is connected to, 1, 2, 3 or 4.
frequency is how fast the speed controlling signal is. 
For motors 1 and 2 you can choose MOTOR12_64KHZ, MOTOR12_8KHZ, MOTOR12_2KHZ, orMOTOR12_1KHZ. 
A high speed like 64KHz wont be audible but a low speed like 1KHz will use less power. 
Motors 3 & 4 are only possible to run at 1KHz and will ignore any setting given */
AF_DCMotor leftMotor(1, MOTOR12_8KHZ);
AF_DCMotor rightMotor(2, MOTOR12_8KHZ);

/*Define Servo Name*/
Servo servo1;

/*Set the speed of the motor
The speed ranges from 0 (stopped) to 255 (full speed) 
You can set the speed whenever you want.*/
#define rightSpeed 160
#define leftSpeed 110

String readString;

void setup() {
  Serial.begin(9600);

  /*Digital 10 pin controls the Servo#1 input
  Digital 9 pin controls the Servo#2 input */
  servo1.attach(10);
  
  /*Servo motor starting position*/
  servo1.write(175);

  /*you can set the speed of the motor using setSpeed(speed)*/
  rightMotor.setSpeed(rightSpeed);
  leftMotor.setSpeed(leftSpeed);
}

void loop() {
  while(Serial.available()){
    delay(50);
    char c=Serial.read();
    readString+=c;
  }
  if(readString.length()>0){
    Serial.println(readString);

    /*To run the motor, call run(direction) where direction is FORWARD, BACKWARD or RELEASE.*/
    if (readString =="FORWARD"){
      rightMotor.run (FORWARD);
      leftMotor.run (FORWARD);
    }
    
    if (readString =="BACK"){
      rightMotor.run (BACKWARD);
      leftMotor.run (BACKWARD);
    }
    
    if (readString =="LEFT"){
      rightMotor.run (FORWARD);
      leftMotor.run (BACKWARD);
    }
    
    if (readString =="RIGHT"){
      rightMotor.run (BACKWARD);
      leftMotor.run (FORWARD);
    }
    
    if (readString =="STOP"){
      rightMotor.run (RELEASE);
      leftMotor.run (RELEASE);
    }

    if (readString == "GRAB"){
      servo1.write(90);
    }

    if (readString == "DROP"){
      servo1.write(175);
    }

    readString="";
  }
}