View on GitHub

Robotic_Arm_JunsaH

This is a robotic arm that is controlled by potentiometers and later on I will add a mod for the controller(glove controller).

Robotic Arm

This is a robotic arm that is controlled by potentiometers and later on I will add a mod for the controller(glove controller).

Engineer School Area of Interest Grade
Junsa H Homestead High School Mechanical Engineering Incoming Sophmore

Final Overhead Robot Arm




Demo Night Video(Junsa H)

Demo Night Video(Junsa H)


    Reflecting on my three weeks at BlueStamp Engineering, I learned so many valuable things. To elaborate, My wiring and power issues showed me how to keep a clean desk space while working, so that I could more clearly see what I did and what needs to be done. Secondly, time management and planning in advanced is vital for all activities and projects, but especially with engineering, it is even more important to stay on track and see progress.

Third Milestone


Milestone 3 (Demo)

    This final milestone had multiple setbacks such as power issues and because I had to finish in three weeks, I had to get an entirely new robot arm. Moreover, they could have been a short circuit with the battery pack and my rewiring could have potentially had a mistake, which I will talk about later. All that being said, the accelerometer and flex sensor was successful including the code, wiring, and functionality.


    A few challenges I had, besides the power issue, was finding sufficient pins on the ESP 32 that worked consistently. Contrary to the last robot arm, I remembered to take off all of the protective plastic on all the parts, which saved a lot of time, which cut down on the build time. To review, a major contributor to my wiring mistake and power issue has to do with having a clean workspace, and I learned to keep a clean work area as well as clean wires; this would allow me to see what is done and what has to be worked on. Moving on to the successes I had with this milestone was finding out the optimal voltage for the servos and sensors, which is about 6 volts.



    The image on the right shows what I used to control the claw servo, which is a flex sensor. Essentially, a flex sensor is a bendable plastic sensor and it is a variable resistor, meaning that the value changes depending on the amount you bed/flex it.






    In addition to the flex sensor, I used an accelerometer, which detects gravity and the direction/rotation of the sensor. For example, in the demo video, you could see that I rotate the accelerometer side to side, and I coded so the Z-axis made the base swivel.





    To make things easier to see, I had two separate codes open and made sure everything functioned well, and then combined everything on a separate page. After I combined all the libraries and code I finetuned all the formatting and tweaked the variables to match.



See code below:


#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <ESP32Servo.h>

Adafruit_MPU6050 mpu;


Servo myservo; 
Servo myservo2;
Servo myservo3;
Servo myservo4;

int pos = 90;
int pos2 = 90;
int pos3 = 90;
int pos4 = 90;

int servoPin = 32;
int servoPin2 = 33;
int servoPin3 = 27;
int servoPin4 = 25;

float ax;
float ay;
float az;

int axservo;
int ayservo;
int azservo;

float gz;

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

  // Try to initialize!
  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
    delay(10);
    }
  }
  Serial.println("MPU6050 Found!");

  // set accelerometer range to +-8G
  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);

  // set gyro range to +- 500 deg/s
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);

  // set filter bandwidth to 21 Hz
  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);

  ESP32PWM::allocateTimer(0);
  ESP32PWM::allocateTimer(1);
  ESP32PWM::allocateTimer(2);
  ESP32PWM::allocateTimer(3);
  myservo.setPeriodHertz(50);    // standard 50 hz servo
  myservo.attach(servoPin, 400, 2400);
  myservo.write(45);

  myservo2.setPeriodHertz(50);    // standard 50 hz servo
  myservo2.attach(servoPin2, 400, 2400);
  myservo2.write(90);

  myservo3.setPeriodHertz(50);    // standard 50 hz servo
  myservo3.attach(servoPin3, 400, 2400);
  myservo3.write(90);

  myservo4.setPeriodHertz(50);    // standard 50 hz servo
  myservo4.attach(servoPin4, 400, 2400);
  myservo4.write(90);

  delay(100);
}

void loop() {
  int flexpos;
  flexpos = analogRead(26);
  Serial.print("flexpos  ");
  Serial.println(flexpos);
  flexpos = map(flexpos, 45, 4095, 0, 180);
  
  /* Get new sensor events with the readings */
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);
  ax = a.acceleration.x;
  ay = a.acceleration.y;
  az = a.acceleration.z;

  gz = g.gyro.z;

  /* Print out the values */
  Serial.print("Acceleration X: ");
  Serial.print(a.acceleration.x);
  Serial.print(", Y: ");
  Serial.print(a.acceleration.y);
  Serial.print(", Z: ");
  Serial.print(a.acceleration.z);
  Serial.println(" m/s^2");

  Serial.print("Rotation X: ");
  Serial.print(g.gyro.x);
  Serial.print(", Y: ");
  Serial.print(g.gyro.y);
  Serial.print(", Z: ");
  Serial.print(g.gyro.z);
  Serial.println(" rad/s");

  Serial.print("Temperature: ");
  Serial.print(temp.temperature);
  Serial.println(" degC");

  Serial.println("");
  delay(100);
  
  ax = mapfloat(ax, -10, 10, 0, 180);
  Serial.print(" ax ");
  Serial.println(ax);
  ay = mapfloat(ay, -10, 10, 0, 180);
  Serial.print(" ay ");
  Serial.println(ay);
  az = mapfloat(az, -10, 10, 0, 180);
  Serial.print(" az ");
  Serial.println(az);

  axservo = ax;
  ayservo = ay;
  azservo = az;



  while(gz>0.2){
    sensors_event_t a, g, temp;
    mpu.getEvent(&a, &g, &temp);
    ax = a.acceleration.x;
    ay = a.acceleration.y;
    az = a.acceleration.z;

    gz = g.gyro.z;
    Serial.println("Servo moving left");
     pos2+=5;
    if (pos2>180){
      pos2 = 180;
    
    }
     
    myservo2.write(pos2);
    delay(10);
    
    
  }
    while(gz<-0.2){
    sensors_event_t a, g, temp;
    mpu.getEvent(&a, &g, &temp);
    ax = a.acceleration.x;
    ay = a.acceleration.y;
    az = a.acceleration.z;

    gz = g.gyro.z;
   
    
    Serial.println("Servo moving right");
    pos2-=5;
    if (pos2<0){
      pos2 = 0;
    
    }
    myservo2.write(pos2);
    delay(10);
    
    
  }
   myservo.write(axservo);
   myservo4.write(ayservo);
   myservo3.write(flexpos);
}


float mapfloat(float x, float in_min, float in_max, float out_min, float out_max) {
  return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min;
}



Second Milestone

JunsaH Milestone 2


    My second milestone consisted of my getting all 5 servos to turn with the potentiometers while them being attached to the robot arm itself. This was a quite quick milestone because the servos and potentiometers are already set up with the wiring and code. Moreover, The building process was pretty seamless, although the instructions were pretty confusing with the kit. The last part of the build process was the plastic protective sticker on the actual parts of the robot arm; I didn’t notice that the plastic was on, so taking them off took surprisingly long.


    Secondly, because the weight of the plastic parts of the robot arm makes it harder for the servos to turn. Due to this, I had to add an ANKER battery pack, which was much more power than the AA batteries I used to power the servos previously. I first started by cutting the USB that connects to the battery pack and soldered the red(power) and black(ground) so that I could connect it to the positive and negative rail on my breadboard.




    Lastly, I rewired all the wires that were going to affect the organization of my overall project, which made it much cleaner and easier to access certain wires. This tiny detail made the other processes faster, which was an overall plus to the timeline of my project. I talk about this briefly in my second milestone video.













First Milestone

Junsa H Milestone 1



    For my first milestone, my goal was to get 5 servo motors to move while I controlled it by a potentiometer, which is a variable resistor. To begin, the basics of a circuit are the fundamentals of how the servos are being controlled by the potentiometer. As seen below, there is 5v(5 volts) wired to the positive side of the servo, which serves as the positive side of the circuit. Moreover, the bottom wire with the three lines in the ground, meaning that the voltage is 0; completes the circuit. Lastly, there is PIN 3 attached to the middle, which allows the potentiometers to connect with the certain motor, which I will talk about later with the coding aspect.



    As for the servos, you can see the three different colored wires, brown(GND), red(power), and orange(digital pin). More specifically, the analog is for a yes or no command, while the digital pins are used for reading or scouting for demands.






    Moving on to how I wired my project, I started by connecting the 5v to the positive side and GND(ground) to the negative side, which allowed me to connect the potentiometers to the sides of the breadboard as well as add multiple servos and potentiometers. Furthermore, knowing how a breadboard is set up as seen on the left, it is connected by a wire that does from one positive end to the other as well as the negative. Moreover, the other rows(a-j) are connected horizontally. That being said I connected the left side of the potentiometer to the positive side of the breadboard and the right side to the negative side; the middle was wired to an analog slot on the Arduino.











    Lastly, the coding was pretty similar to coding for one potentiometer and servo motor. Moreover, I first coded for the variables as well as match the potentiometers to each servo(ap12 = A1). For the last final steps, I made a loop so that my machine takes in the input from the potentiometer and the output is scaled from the potentiometer to the angle at which the servo moves.


#include <Servo.h>

Servo servo8, servo9, servo10, servo11, servo12; // create servo object to control a servo
int ap12 = A1, ap11 = A2, ap10 = A3, ap9 = A4, ap8 = A5;    // variables where the potentiometer is connected
int var8, var9, var10, var11, var12;                   // variables to store from the anolog potentiometer

void setup() {
servo8.attach(8);    // attaches the first servo on pin 8 to the servo object
servo9.attach(9);    // attaches the second servo on pin 9 to the servo object
servo10.attach(10);  // attaches the third servo on pin 10 to the servo object
servo11.attach(11);  // attaches the fourth servo on pin 11 to the servo object
servo12.attach(12);  // attaches the fifth servo on pin 12 to the servo object
}

void loop() {
var8 = analogRead(ap8);
var8 = map(var8, 0, 1023, 0, 90);
servo8.write(var8); 
delay(10);  

var9 = analogRead(ap9);
var9 = map(var9, 0, 1023, 0, 90);
servo9.write(var9);
delay(10);  

var10 = analogRead(ap10);
var10 = map(var10, 0, 1023, 0, 90);
servo10.write(var10);
delay(10);  

var11 = analogRead(ap11);
var11 = map(var11, 0, 1023, 0, 90);
servo11.write(var11);
delay(10);  

var12 = analogRead(ap12);
var12 = map(var12, 0, 1023, 0, 90);
servo12.write(var12);
delay(10);             


}