Skip to the content.

Robotic Arm

For my project, I am building and programming a robotic arm with four joints, two to bend the arm up and down, one to spin its base, and one to open and close the claw. My modification was to separate the controller from the arm and make them communicate via Bluetooth. This is my first time doing a large coding project, and I am very proud with how it turned out!

Engineer School Area of Interest Grade
Scott M West Torrance High School Mechanical Engineering Incoming Junior

IMG_1128

Final Milestone

My final milestone is finishing the modification I made to my robotic arm. The modification I chose was to separate the joysticks from the arm and use two HC05 Bluetooth modules to send commands between the joysticks and the arm, making them wireless. If I turn them on and move around, I can control the arm no matter where I am. I have two separate codes, one for the controller and one for the arm. The controller code takes the x- and y-values from each of the joysticks and turns them into single-character commands, which are then sent to an HC05. This HC05, connected to the controller, sends the characters to the HC05 connected to the arm. The arm then takes those characters and translates them into commands that make the arm move. There were a lot of technical difficulties and small errors I had to fix, but in the end, it works, and I’m really proud of how it turned out.

Second Milestone

My second milestone is finishing the base project of my robotic arm. I assembled all the hardware, and I have all the programming finished. My arm can go up and down, and it can open and close. Unfortunately, it has problems with turning left and right, but it seems like it’s more of a problem with the strength of the base servo than the programming. I reused the code from my first milestone in the final code to measure the joystick coordinates while constantly telling me those coordinates, which is very useful. The hardest part in this milestone was understanding how to do the rest of the code, because none of it made sense to me, and I spent an entire day trying to figure it out on my own without any success. The next day, thankfully, I got help from my instructor and ended up writing all the rest of the code in that one day, which was pretty crazy. This code runs the joystick coordinates through a series of parameters that, depending on the values of the coordinates, move the servos on the arm in different ways.

First Milestone

My first big milestone was being able to understand some of the code that I would be using in this project. I hadn’t had much coding experience, if any, before this, so being able to do what I did here was a big deal to me. At the beginning of the camp, we were given prewritten code in C++ to test the joysticks. When I began writing the code for my project, I took this code and used it in my actual project, after a few tweaks to make it useful. It’s a pretty small thing in itself, but doing this proves I had a general understanding of what the different parts of the code did and how to edit or even create them to make then do what I want to. This milestone isn’t hugely impactful to my actual project, but getting a foundation of understanding in C++ was an immense achievement for me.

Schematics

image

Code

Here’s where you’ll put your code. The syntax below places it into a block of code. Follow the guide here to learn how to customize it to your project needs.

Controller code

#include "src/CokoinoArm.h"
#include <SoftwareSerial.h>

int rx = 3;
int tx = 2;

SoftwareSerial BT_Serial(rx, tx);
char bt_data;

int xL,yL,xR,yR = 0;

void setup() { 
Serial.begin(38400); 
BT_Serial.begin(38400);

//! - if this is false, do this
} 
void loop(){

int xLcenter = 503;
int yLcenter = 513;
int xRcenter = 502;
int yRcenter = 505;
int deadzone = 25;
xL = analogRead(A0);
yL = analogRead(A1); 
xR = analogRead(A2); 
yR = analogRead(A3); 

//L to R, T to B - xL:0<503<1023, yL:1023<512.5<0, xR:0<502<1023, yR:1023<505<0
if((xLcenter - deadzone) < xL && xL < (xLcenter + deadzone) && (yLcenter - deadzone) < yL && yL < (yLcenter + deadzone) && (xRcenter - deadzone) < xR && xR < (xRcenter + deadzone)){
  BT_Serial.write('n');
  Serial.println("no movement");
}
if(!((xLcenter - deadzone) < xL && xL < (xLcenter + deadzone))){
  if(0 <= xL && xL <= 239){
    BT_Serial.write('F');
    Serial.println("sent F");delay(20);}
  if(239 < xL && xL <= 478){
    BT_Serial.write('f');
    Serial.println("sent f");delay(20);}
  if(528 < xL && xL <= 776){
    BT_Serial.write('b');
    Serial.println("sent b");delay(20);}
  if(776 < xL && xL <= 1023){
    BT_Serial.write('B');
    Serial.println("sent B");delay(20);}
}
if(!((yLcenter - deadzone) < yL && yL < (yLcenter + deadzone))){
  if(0 <= yL && yL <= 239){
    BT_Serial.write('R');
    Serial.println("sent R");delay(20);}
  if(239 < yL && yL <= 478){
    BT_Serial.write('r');
    Serial.println("sent r");delay(20);}
  if(528 < yL && yL <= 776){
    BT_Serial.write('l');
    Serial.println("sent l");delay(20);}
  if(776 < yL && yL <= 1023){
    BT_Serial.write('L');
    Serial.println("sent L");delay(20);}
}
if(!((xRcenter - deadzone) < xR && xR < (xRcenter + deadzone))){
  if(0 <= xR && xR <= 239){
    BT_Serial.write('C');
    Serial.println("sent C");delay(20);}
  if(239 < xR && xR <= 478){
    BT_Serial.write('c');
    Serial.println("sent c");delay(20);}
  if(528 < xR && xR <= 776){
    BT_Serial.write('o');
    Serial.println("sent o");delay(20);}
  if(776 < xR && xR <= 1023){
    BT_Serial.write('O');
    Serial.println("sent O");delay(20);}
}
}

Arm code

#include"src/CokoinoArm.h"
#include <SoftwareSerial.h>

int tx = 2;
int rx = 3;

SoftwareSerial BT_Serial(rx, tx);
char bt_data;

CokoinoArm arm;
int xLcenter = 503;
int yLcenter = 513;
int xRcenter = 502;
int yRcenter = 505;
int deadzone = 25;

//bt_data is the variable
//servo1.write

void setup() { 
  arm.ServoAttach(4,5,6,7);
Serial.begin(38400);
BT_Serial.begin(38400); 
int xL,yL,xR,yR;

pinMode(tx, OUTPUT);
pinMode(rx, INPUT);
//! - if this is false, do this
} 
void loop(){

  if (BT_Serial.available() > 0) {
    bt_data = BT_Serial.read();
    Serial.print("Received: ");
    Serial.println(bt_data);
  }
  
  if(bt_data == 'F'){arm.down(50); Serial.println(" down 1");delay(10);}
  if(bt_data == 'f'){arm.down(50); Serial.println(" down 2");delay(10);}
  if(bt_data == 'b'){arm.up(50); Serial.println(" up 2");delay(10);}
  if(bt_data == 'B'){arm.up(50); Serial.println(" up 1");delay(10);}
  if(bt_data == 'R'){arm.right(5); Serial.println(" right 1");delay(10);}
  if(bt_data == 'r'){arm.right(50); Serial.println(" right 2");delay(10);}
  if(bt_data == 'l'){arm.left(50); Serial.println(" left 2");delay(10);}
  if(bt_data == 'L'){arm.left(5); Serial.println(" left 1");delay(10);}
  if(bt_data == 'C'){arm.close(0); Serial.println(" close 1");delay(10);}
  if(bt_data == 'c'){arm.close(50); Serial.println(" close 2");delay(10);}
  if(bt_data == 'o'){arm.open(50); Serial.println(" open 2");delay(10);}
  if(bt_data == 'O'){arm.open(0); Serial.println(" open 1");delay(10);}

Bill of Materials

Here’s where you’ll list the parts in your project. To add more rows, just copy and paste the example rows below. Don’t forget to place the link of where to buy each component inside the quotation marks in the corresponding row after href =. Follow the guide here to learn how to customize this to your project needs.

Part Note Price Link
Robotic Arm Kit Contains physical components used to build the arm $49.99 Link
Servo Shield Expansion shield for Arduino Nano $10.99 Link
Screwdriver Kit Used to help assemble the arm $7.99 Link
Electronics Kit Contains components needed to wire the physical parts together $13.49 Link
9V Barrel Jack Allows 9V batteries to power the Arduinos $5.99 Link
Digital Multimeter Used to measure the strength of electric current $15.99 Link
9V Batteries Used to power the Arduinos $8.99 Link
HC05 Bluetooth Module Connects the controller and arm wirelessly $9.99 Link
Arduino Nano We need an extra Arduino to run the controller $24.99 Link