How to assemble and control a robot arm with an Arduino

How to assemble and control a robot arm with an Arduino

Hello, welcome back. In this tutorial, we will learn how to assemble and control a robotic arm with an Arduino. A robot arm kit has been used for this project. You can easily buy it in the market. Also, four servo motors are required for this robot arm and a PWM servo motor driver board has been used to control them. The Arduino UNO board is used to control all of these components. Keep reading.

What is a robotic arm?

A robotic arm is a programmed mechanical system. These are works like a normal human hand. Also, this is called a robot arm because it works according to a program. We can see these from small sizes to very large sizes. These robotic arms are specially used for industrial purposes. Through these, various activities that can not be done by a normal human being can be done. Also, we can see in the market a variety of robot arms designed to facilitate everyday work in our home. This tutorial covers how to assemble a robot arm kit for sale in the market step by step and how it works with an Arduino. Also, use this tutorial to understand how a robotic arm works.

Ok, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, take the robotic arm kit and remove the parts one by one. Afterwards, remove the stickers.

Step 3

Thirdly, connect the first servo motor as follows.

Step 4

After, connect the robot arm based part. Use four screws to do this.

Step 5

Next, connect the rotating part of the grounded servo motor. For that, use the servo motor horns and screws.

Step 6

OK, now connect the servo motors on both sides.

Step 7

Next, connect the left side servo motor rotation parts. For that, use the servo motor horns and screws.

Step 8

Then, Next, connect the right side servo motor rotation parts. For that, use the servo motor horns and screws.

Step 9

Now, connect the below parts to the main rotation part.

Step 10

After, connect the below part to the left side servo motor part. After, connect it to the main rotation part.

Step 11

Now, connect the right side servo motor part to the main rotation part.

Step 12

After, connect the robot arm elbow parts. For that, use the pictures below.

Step 13

Okay, now let’s set the fingers of the robot’s arm. For that, connect the last servo motor as follows.

Step 14

Next, connect the servo motor rotation wheel and servo motor horns.

Step 15

Then, attach one finger to it.

Step 16

After, connect the other finger.

Step 17

Finally, connect the above part with the main robot arm.

Step 18

Ok, the robot arm is done. Now, attach the PWM servo motor driver board and connect the motors to it. For that, use the circuit diagram below.

How to assemble and control a robot arm with an Arduino

Step 19

Afterwards, connect the PWM servo motor driver to the Arduino board and connect the 5v external power supply to this robot arm. For that, use the circuit diagram above.

Step 20

OK, now connect this robot arm to the computer and let’s creates the program for this project. It is as follows.

  • PWM servo motor driver library — Download
  • The complete program of this project – download
/*Robot arm control with Arduino
   https://srituhobby.com
*/

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver srituhobby = Adafruit_PWMServoDriver();

#define servo1 0
#define servo2 1
#define servo3 2
#define servo4 3


void setup() {
  Serial.begin(9600);
  srituhobby.begin();
  srituhobby.setPWMFreq(60);
  srituhobby.setPWM(servo1, 0, 330);
  srituhobby.setPWM(servo2, 0, 150);
  srituhobby.setPWM(servo3, 0, 300);
  srituhobby.setPWM(servo4, 0, 410);
  delay(3000);
}

void loop() {

  for (int S1value = 330; S1value >= 250; S1value--) {
    srituhobby.setPWM(servo1, 0, S1value);
    delay(10);
  }

  for (int S2value = 150; S2value <= 380; S2value++) {
    srituhobby.setPWM(servo2, 0, S2value);
    delay(10);
  }

  for (int S3value = 300; S3value <= 380; S3value++) {
    srituhobby.setPWM(servo3, 0, S3value);
    delay(10);
  }

  for (int S4value = 410; S4value <= 510; S4value++) {
    srituhobby.setPWM(servo4, 0, S4value);
    delay(10);
  }
  ////////////////////////
  delay(2000);
  for (int S4value = 510; S4value > 410; S4value--) {
    srituhobby.setPWM(servo4, 0, S4value);
    delay(10);
  }

  for (int S3value = 380; S3value > 300; S3value--) {
    srituhobby.setPWM(servo3, 0, S3value);
    delay(10);
  }

  for (int S2value = 380; S2value > 150; S2value--) {
    srituhobby.setPWM(servo2, 0, S2value);
    delay(10);
  }

  for (int S1value = 250; S1value < 450; S1value++) {
    srituhobby.setPWM(servo1, 0, S1value);
    delay(10);
  }
  //////////////////////
  for (int S2value = 150; S2value <= 380; S2value++) {
    srituhobby.setPWM(servo2, 0, S2value);
    delay(10);
  }

  for (int S3value = 300; S3value <= 380; S3value++) {
    srituhobby.setPWM(servo3, 0, S3value);
    delay(10);
  }

  for (int S4value = 410; S4value <= 510; S4value++) {
    srituhobby.setPWM(servo4, 0, S4value);
    delay(10);
  }

  for (int S4value = 510; S4value > 410; S4value--) {
    srituhobby.setPWM(servo4, 0, S4value);
    delay(10);
  }
  ///////////////////
  for (int S3value = 380; S3value > 300; S3value--) {
    srituhobby.setPWM(servo3, 0, S3value);
    delay(10);
  }

  for (int S2value = 380; S2value > 150; S2value--) {
    srituhobby.setPWM(servo2, 0, S2value);
    delay(10);
  }

  for (int S1value = 450; S1value > 330; S1value--) {
    srituhobby.setPWM(servo1, 0, S1value);
    delay(10);
  }
}

Code explanation

Firstly, the PWM servo motor and wire libraries have been included.

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Secondly, the object has been created for the PWM servo motor library.

Adafruit_PWMServoDriver srituhobby = Adafruit_PWMServoDriver();

Thirdly, servo motors are defined.

#define servo1 0
#define servo2 1
#define servo3 2
#define servo4 3

In the setup function,

void setup() {
//The serial monitor starts
  Serial.begin(9600);
//This code starts the library
  srituhobby.begin();
  srituhobby.setPWMFreq(60);
//Sets the robot arm starting points
  srituhobby.setPWM(servo1, 0, 330);
  srituhobby.setPWM(servo2, 0, 150);
  srituhobby.setPWM(servo3, 0, 300);
  srituhobby.setPWM(servo4, 0, 410);
  delay(3000);
}

The loop function includes the movements of the robotic arm. For that, enter different values and test this robotic arm. Keep this fact in mind [0 degree = 150 and 180 degree = 600]. If you don’t understand this, click this link.

void loop() {

  for (int S1value = 330; S1value >= 250; S1value--) {
    srituhobby.setPWM(servo1, 0, S1value);
    delay(10);
  }

  for (int S2value = 150; S2value <= 380; S2value++) {
    srituhobby.setPWM(servo2, 0, S2value);
    delay(10);
  }

  for (int S3value = 300; S3value <= 380; S3value++) {
    srituhobby.setPWM(servo3, 0, S3value);
    delay(10);
  }

  for (int S4value = 410; S4value <= 510; S4value++) {
    srituhobby.setPWM(servo4, 0, S4value);
    delay(10);
  }
  ////////////////////////
  delay(2000);
  for (int S4value = 510; S4value > 410; S4value--) {
    srituhobby.setPWM(servo4, 0, S4value);
    delay(10);
  }

  for (int S3value = 380; S3value > 300; S3value--) {
    srituhobby.setPWM(servo3, 0, S3value);
    delay(10);
  }

  for (int S2value = 380; S2value > 150; S2value--) {
    srituhobby.setPWM(servo2, 0, S2value);
    delay(10);
  }

  for (int S1value = 250; S1value < 450; S1value++) {
    srituhobby.setPWM(servo1, 0, S1value);
    delay(10);
  }
  //////////////////////
  for (int S2value = 150; S2value <= 380; S2value++) {
    srituhobby.setPWM(servo2, 0, S2value);
    delay(10);
  }

  for (int S3value = 300; S3value <= 380; S3value++) {
    srituhobby.setPWM(servo3, 0, S3value);
    delay(10);
  }

  for (int S4value = 410; S4value <= 510; S4value++) {
    srituhobby.setPWM(servo4, 0, S4value);
    delay(10);
  }

  for (int S4value = 510; S4value > 410; S4value--) {
    srituhobby.setPWM(servo4, 0, S4value);
    delay(10);
  }
  ///////////////////
  for (int S3value = 380; S3value > 300; S3value--) {
    srituhobby.setPWM(servo3, 0, S3value);
    delay(10);
  }

  for (int S2value = 380; S2value > 150; S2value--) {
    srituhobby.setPWM(servo2, 0, S2value);
    delay(10);
  }

  for (int S1value = 450; S1value > 330; S1value--) {
    srituhobby.setPWM(servo1, 0, S1value);
    delay(10);
  }
}

Step 21

Now, select board and port. After, upload this code to the Robot arm.

OK, enjoy this project. The full video guide is given below. So, we will meet in the next tutorial.

How to assemble and control a robot arm with an Arduino

Similar Posts

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *