Introduction: My Eighth Project: Robot Arm With Smart Tank Chassis and Bluetooth

The robot arm is a very interesting stuff. It can move and hold something, but it is confined in a specific place. How about if we put it on a robot car and let the car bring the robot arm to do certain jobs? This is an idea of this project.

Step 1: Parts

Robot Arm Set, or here

Smart Tank Chassis, or here

Arduino MEGA 2560 R3

Bluetooth Module

Buck Regulator with Indicator

7.4V Li-Po Battery

Charger

JST female connector

Small Breadboard

9V Battery Box

Switch

Step 2: Assembly

In this project I need the higher part of the robot arm set only. Take this part off the set and fix it on the smart tank chassis. To make the claw picks thing easily, I have also adjusted the angle of the claw servo and make the claw in horizontal direction when the servo is 0 degree. I've realised that the voltage of Li-Po battery is too strong for the robot arm and the smart tank, so I also bought a buck regulator to reduce the voltage. This buck regulator is so convenient because we can read the voltage of input and output through the indicator. We can use a multimeter to calibrate the indicator at the first time. After that the voltage can easily be adjusted with a screw driver. Let's set the voltage to 5.8V. I fix Arduino MEGA 2560, small breadboard, the buck regulator and 9V battery box on the chassis first and then do wiring.

Step 3: Wiring

The Li-Po battery is connected to the input of the buck regulator and VCC of the output is wiring with a switch and then to breadboard. GND of the output is connected directly to the breadboard. GND and VCC of all servos and two sides of the chassis are linked to GND and VCC of the output with breadboard. To share the same ground, pin GND on Arduino is also connected to GND on the breadboard.

The wiring of the chassis is the same as in the third project. I just copy it as follow:

IB on the right side > pin 8

IA on the left side > pin 9

IA on the right side > pin 10

IB on the left side > pin 11

Let the servo at the bottom be servo1, the middle servo2 and the claw servo3 and they are linked to Arduino as follow:

Servo 1 > pin 5

Servo 2 > pin 6

Servo 3 > pin 7

Step 4: 1st Test

To ensure all the wiring are correct I do a test with the codes below:

For smart tank chassis:

int motorPin = 8; //right side to IB - forward

int motorPin2 = 9; //left side to IA - forward

int motorPin3 = 10; //right side to IA - backward

int motorPin4 = 11; //left side to IB - backward

void setup() {

Serial.begin (9600);

pinMode(motorPin, OUTPUT);

pinMode(motorPin2, OUTPUT);

pinMode(motorPin3, OUTPUT);

pinMode(motorPin4, OUTPUT);

}

void forward(){

digitalWrite(motorPin, HIGH);

digitalWrite(motorPin2, HIGH);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

}

void backward() {

digitalWrite(motorPin, LOW);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, HIGH);

digitalWrite(motorPin4, HIGH);

}

void turnLeft() {

digitalWrite(motorPin, HIGH);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, HIGH);

}

void turnRight() {

digitalWrite(motorPin, LOW);

digitalWrite(motorPin2, HIGH);

digitalWrite(motorPin3, HIGH);

digitalWrite(motorPin4, LOW);

}

void loop () {

forward();

delay(10000);

backward();

delay(10000);

turnLeft();

delay(10000);

turnRight();

delay(10000);

}

For robot arm:

#include <Servo.h>

Servo servo1;

Servo servo2;

Servo servo3;

void setup()

{

servo1.attach(5);

servo2.attach(6);

servo3.attach(7);

}

void loop()

{

servo1.write(40); // move down

servo2.write(0); //turn anticlockwise

servo3.write(40); //claw open

delay(5000);

servo1.write(180); // move up

servo2.write(180); //turn clockwise

servo3.write(110); //claw close

delay(5000);

}

The range of 3 servos are adjusted to avoid any interrupt.

Step 5: 2nd Test

Great! It moves perfectly! So I add the Bluetooth module to Arduino:

VCC > 5V

GND > GND

TXD > pin 3

RXD > pin 2

Upload the code in the 4th project:

#include <SoftwareSerial.h>

SoftwareSerial BT(3, 2); //set TX and RX on bluetooth to pin 3 and 2 respectively

char command;

int motorPin = 8; //right side to IB - forward

int motorPin2 = 9; //left side to IA - forward

int motorPin3 = 10; //right side to IA - backward

int motorPin4 = 11; //left side to IB - backward

void setup() {

BT.begin (9600);

pinMode(motorPin, OUTPUT);

pinMode(motorPin2, OUTPUT);

pinMode(motorPin3, OUTPUT);

pinMode(motorPin4, OUTPUT);

}

void stop() {

digitalWrite(motorPin, LOW);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

}

void forward(){

digitalWrite(motorPin, HIGH);

digitalWrite(motorPin2, HIGH);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

}

void backward() {

digitalWrite(motorPin, LOW);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, HIGH);

digitalWrite(motorPin4, HIGH);

}

void turnLeft() {

digitalWrite(motorPin, HIGH);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, HIGH);

}

void turnRight() {

digitalWrite(motorPin, LOW);

digitalWrite(motorPin2, HIGH);

digitalWrite(motorPin3, HIGH);

digitalWrite(motorPin4, LOW);

}

void loop() {

if (BT.available() > 0) {

command = BT.read();

switch (command) {

case 'w' :

forward();

break;

case 'x' :

backward();

break;

case 'a' :

turnLeft();

break;

case 'd' :

turnRight();

break;

case 's' :

stop();

break;

}

}

}

And use the Android app in the 4th project to test it......

No response.

I've test the robot arm and smart tank separately and both are fine, and I am pretty sure that the Bluetooth module works properly. The problem should be on the wiring. I did swap the RX and TX pin but it didn't work... So discouraging... : (

So I try begging an answer from google and get this information by chance:

http://www.arduino.cc/en/Reference/SoftwareSerialExample

Note:

Not all pins on the Mega and Mega 2560 support change interrupts,

so only the following can be used for RX:

10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

The Bluetooth module failed to communicate with Arduino just because I've used the wrong pin! So I shift TX and RX to 52 and 53 respectively and try again. It works!

Step 6: App

As the Android app before supports the movement of the tank only, I've modified the app and added several buttons to it in MIT App Inventor. For the framework of the app please refer to the photo. The concept is very simple actually: Press a button and send a letter to Arduino via Bluetooth. When Arduino gets a letter, it will do the job I've assigned to this letter. Besides of five buttons before, six more buttons are added to the app: Open, Close, ↶, ↷, ↑ and ↓. If you remember, you will know that I tested and adjusted the range of the three servos in the 1st test. The buttons "↑" and "↓" correspond to up and down movement of Servo 1. "↶" and "↷" to anticlockwise and clockwise movement of Servo 2. "Open" and "Close" to open claw and close claw of Servo 3.

Step 7: Code

Then I combine the code in the 2nd test with servos and enable the servos move in designated ranges.

#include <SoftwareSerial.h>

#include <Servo.h>

SoftwareSerial BT(52, 53); //set TX and RX on bluetooth to pin 52 and 53 respectively

Servo servo1;

Servo servo2;

Servo servo3;

char command;

int motorPin = 8; //right side to IB - forward

int motorPin2 = 9; //left side to IA - forward

int motorPin3 = 10; //right side to IA - backward

int motorPin4 = 11; //left side to IB - backward

int pos1 = 90;

int pos2 = 90;

int pos3 = 90;

void setup() {

BT.begin (9600);

Serial.begin (9600);

pinMode(motorPin, OUTPUT);

pinMode(motorPin2, OUTPUT);

pinMode(motorPin3, OUTPUT);

pinMode(motorPin4, OUTPUT);

servo1.attach(5);

servo1.write(pos1);

servo2.attach(6);

servo2.write(pos2);

servo3.attach(7);

servo3.write(pos3);

}

void stop() {

digitalWrite(motorPin, LOW);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

}

void forward(){

digitalWrite(motorPin, HIGH);

digitalWrite(motorPin2, HIGH);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

}

void backward() {

digitalWrite(motorPin, LOW);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, HIGH);

digitalWrite(motorPin4, HIGH);

}

void turnLeft() {

digitalWrite(motorPin, HIGH);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, HIGH);

}

void turnRight() {

digitalWrite(motorPin, LOW);

digitalWrite(motorPin2, HIGH);

digitalWrite(motorPin3, HIGH);

digitalWrite(motorPin4, LOW);

}

void open() {

for(pos3 = 110; pos3 > 40; pos3 -= 1)

{servo3.write(pos3);

}

}

void close() {

for(pos3 = 40; pos3 < 110; pos3 += 1)

{servo3.write(pos3);

}

}

void antiClockwise() {

for(pos2 = 90; pos2 > 0; pos2 -= 1)

{servo2.write(pos2);

}

}

void clockwise() {

for(pos2 = 0; pos2 < 90; pos2 += 1)

{servo2.write(pos2);

}

}

void up () {

for(pos1 = 50; pos1 < 180; pos1 +=1)

{servo1.write(pos1);

}

}

void down() {

for(pos1 = 180; pos1 > 50; pos1 -= 1)

{servo1.write(pos1);

}

}

void loop() {

if (BT.available() > 0) {

command = BT.read();

switch (command) {

case 'w':

forward();

break;

case 'x':

backward();

break;

case 'a':

turnLeft();

break;

case 'd':

turnRight();

break;

case 's':

stop();

break;

case 'y':

open();

break;

case 'u':

close();

break;

case 'h':

antiClockwise();

break;

case 'j':

clockwise();

break;

case 'n':

up();

break;

case 'm':

down();

break;

}

}

}

Step 8: Result

Do the pairing with my Android phone and open the app. Cool! I got stuck in the problem for a few day and now it works! In this project I've learnt more about troubleshooting: Some problems may not caused by either wiring or coding, but different properties among Arduino boards. This board supports the code doesn't entails that other board can support it. I should pay more attention to it if using different boards. This is the end of this project. Hope I can find other interesting project to start. See you!