Post Top Ad

Monday, May 8, 2023

6 DOF Robotic Arm using Arduino | How to make a Robotic Arm with Arduino Code | Pakluck


 Pakluck Training Center strives to keep its curriculum at par with the needs of today’s markets and industrial practices, best short courses in Pakistan . Recent studies and analysis of the alumni and student preferences have show the following fields of study the most popular and relevant to the needs of the contemporary markets. We Offer Best Online Courses in Pakistan.

Arduino controlled 6-axis robot arm

It has always fascinated me to see the movements of robotic arms when they do all kinds of work. Their movements are precise and continuous, as if I was in a dance class. These industrial robots have powerful motors and special electronic circuits to control movements according to programmed coordinates. Would it be possible to build a small robot arm with simple electronic modules and components?


The main problem is the weight of the structure of the robot arm and the actuators to move it. Ideally, the structure should be of metal and the actuators would have to be stepper motors, but this set is heavy and expensive. The question is: could it be done with servo motors?


We have to look for a material that is not very heavy and inexpensive. Balsa wood is used for inlays (marquetry), which is not heavy and yet resistant. So it is possible for servo motors to move the set, with the electronics for control already integrated there. We will develop a robot arm that picks up parts with a gripper and places them elsewhere.

The first step is to design the structure of our robot arm from 3 mm thick balsa wood. In order for the different parts of our robot to be able to support the weight of the next part, we have to increase the thickness of these parts by gluing several equal pieces (the weight does not increase very much, as you will notice). To support the movements of the servo motors, we need to balance the weights of the arms a little, taking into account the weight of the arm at the other end.


For the operation of our robot arm it is very important to know the pulse width data of the servo motors in order to position the minimum and maximum angle with the adjustment sketches and to bring the robot arm into the desired position. According to the data sheet, the MG995 servo motor rotates 120 degrees, while the MG90S and SG90 servo motors rotate 180 degrees. To determine the required pulse width data, we use the Servo_check_120_degrees_slow_motion.ino and Servo_check_180_degrees.ino sketches and a protractor as shown in the drawing.


The two sketches are very similar, so we will explain the most important lines of one of the two sketches. The following lines belong to the MG995 servo motor sketch. The first two lines we analyse are the minimum and maximum values of the pulse width for each servo motor, corresponding to the positions 0 degrees and 180 degrees.

In the following lines we create two loops in which we have to change the data marked in red to position the servo motor between 30 degrees and 150 degrees. In this case we get the 120 degrees that the MG995 works with. The movement is slow with 10 "steps" every 50 milliseconds from 30 degrees to 150 degrees. We need to do these procedures with all the servo motors we will be using and write down the corresponding values for each one, as these are the values it works between to position itself.


1. we start mounting on the gripper with it closed and the servo motor turned 90 degrees.

2. the next servo motor is number 1, with the position at 0 degrees and the gripper in the position shown in the photo, as the rotation is 180 degrees clockwise.

3. the third servo motor is number 2, which, like the previous one, is in the 0 degree position and moves the grab vertically upwards as it also rotates clockwise to move in the direction of 180 degrees.

4. now it is the turn of servo motor number 3, we leave the position of the servo motor at 90 degrees in this case and we mount the arm in alignment with the next one, as this gives us 60 degrees of movement in each direction

5. for servo motor number 4 we leave the position at 90 degrees and mount the arm horizontally (parallel to the ground), which gives us a large radius of action with 60 degrees in each direction, as with the previous servo motor.


6. we leave the last servo motor, number 5, at 90 degrees like the previous one and mount the rotating platform so that the rest of the arm is in the middle of the side edge of the base.

Circuit and description of operation

As you can see in the circuit diagram, the circuit is very simple. We have the microcontroller, the PCA9685 module and the 6 servo motors.


The electrical connections of the servo motors to the PCA9685 assembly are connected according to the numbering of the servo motor with the number of the corresponding PWM output port on the assembly, i.e. servo motor number 0 with output port 0.


The 5V DC power supply is connected to the green screw connector on the ver board, paying attention to the polarity as the servo motors are supplied via this connector.

The connections between the Atmega328P microcontroller and the PCA9685 module are the I2C communication via its port and the 5V for the power supply of the module electronics.


The six servo motors are controlled by the Atmega328P microcontroller via the PCA9685 module, which has two important functions. The first is to supply the servo motors with 5V from an external power supply with enough power to move the 6 servo motors simultaneously. The second is to send the PWM signal to the respective servo motor, which was transmitted via the I2C signal from the microcontroller. As can be seen in the diagram above, we only need 2 pins for communication between the microcontroller and the PCA9685 module, leaving the other pins for other uses.


The really tedious part of this project is setting the values for each position of the arm and the speeds of the movements. The latter must slow down if the arm is to pick up an object.


For the adjustment and movement of the robot arm in each stage, one sketch per stage was created. This allows the settings to be made individually. When we have made all the settings correctly, we will combine them all into one sketch. We will use methods/functions so that the code is cleaner and easier to follow. Analyse the code for one stage and you will see that it is very simple. For the other stages, the adaptation method is similar.


The code we will analyse is the settings for the robot arm to pick up the first part. The sketch is called pick_up_first_object.ino.


The first two lines of code are the libraries we need for the sketch to run correctly. Wire.h is for I2C communication and Adafruit_PWMServoDriver is for using the PCA9685 module.

The next 4 lines are in order the implementation of an Adafruit_PWMServoDriver object to control the servo motor positions, SERVOMIN and SERVOMAX are the rising edge and falling edge values for the 0 degree and 180 degree position of the servo motors respectively. The speed variable is used for the waiting time until the next servo motor is moved.


The next 4 lines are in order the implementation of an Adafruit_PWMServoDriver object to control the servo motor positions, SERVOMIN and SERVOMAX are the rising edge and falling edge values for the 0 degree and 180 degree position of the servo motors respectively. The speed variable is used for the waiting time until the next servo motor moves. In the setup() method we initialise the serial monitor and output a message. In the next two lines we initialise the PCA9685 module using its previously implemented object and specify the frequency at which the servo motors operate, 50 Hz.


In the setup()-method we initialise the serial monitor and output a message. In the next two lines we initialise the PCA9685 module using its previously implemented object and specify the frequency at which the servo motors operate, 50 Hz.



 Pakluck Training Center strives to keep its curriculum at par with the needs of today’s markets and industrial practices, best short courses in Pakistan . Recent studies and analysis of the alumni and student preferences have show the following fields of study the most popular and relevant to the needs of the contemporary markets. We Offer Best Online Courses in Pakistan.

Arduino controlled 6-axis robot arm

It has always fascinated me to see the movements of robotic arms when they do all kinds of work. Their movements are precise and continuous, as if I was in a dance class. These industrial robots have powerful motors and special electronic circuits to control movements according to programmed coordinates. Would it be possible to build a small robot arm with simple electronic modules and components?


The main problem is the weight of the structure of the robot arm and the actuators to move it. Ideally, the structure should be of metal and the actuators would have to be stepper motors, but this set is heavy and expensive. The question is: could it be done with servo motors?


We have to look for a material that is not very heavy and inexpensive. Balsa wood is used for inlays (marquetry), which is not heavy and yet resistant. So it is possible for servo motors to move the set, with the electronics for control already integrated there. We will develop a robot arm that picks up parts with a gripper and places them elsewhere.

The first step is to design the structure of our robot arm from 3 mm thick balsa wood. In order for the different parts of our robot to be able to support the weight of the next part, we have to increase the thickness of these parts by gluing several equal pieces (the weight does not increase very much, as you will notice). To support the movements of the servo motors, we need to balance the weights of the arms a little, taking into account the weight of the arm at the other end.


For the operation of our robot arm it is very important to know the pulse width data of the servo motors in order to position the minimum and maximum angle with the adjustment sketches and to bring the robot arm into the desired position. According to the data sheet, the MG995 servo motor rotates 120 degrees, while the MG90S and SG90 servo motors rotate 180 degrees. To determine the required pulse width data, we use the Servo_check_120_degrees_slow_motion.ino and Servo_check_180_degrees.ino sketches and a protractor as shown in the drawing.


The two sketches are very similar, so we will explain the most important lines of one of the two sketches. The following lines belong to the MG995 servo motor sketch. The first two lines we analyse are the minimum and maximum values of the pulse width for each servo motor, corresponding to the positions 0 degrees and 180 degrees.

In the following lines we create two loops in which we have to change the data marked in red to position the servo motor between 30 degrees and 150 degrees. In this case we get the 120 degrees that the MG995 works with. The movement is slow with 10 "steps" every 50 milliseconds from 30 degrees to 150 degrees. We need to do these procedures with all the servo motors we will be using and write down the corresponding values for each one, as these are the values it works between to position itself.


1. we start mounting on the gripper with it closed and the servo motor turned 90 degrees.

2. the next servo motor is number 1, with the position at 0 degrees and the gripper in the position shown in the photo, as the rotation is 180 degrees clockwise.

3. the third servo motor is number 2, which, like the previous one, is in the 0 degree position and moves the grab vertically upwards as it also rotates clockwise to move in the direction of 180 degrees.

4. now it is the turn of servo motor number 3, we leave the position of the servo motor at 90 degrees in this case and we mount the arm in alignment with the next one, as this gives us 60 degrees of movement in each direction

5. for servo motor number 4 we leave the position at 90 degrees and mount the arm horizontally (parallel to the ground), which gives us a large radius of action with 60 degrees in each direction, as with the previous servo motor.


6. we leave the last servo motor, number 5, at 90 degrees like the previous one and mount the rotating platform so that the rest of the arm is in the middle of the side edge of the base.

Circuit and description of operation

As you can see in the circuit diagram, the circuit is very simple. We have the microcontroller, the PCA9685 module and the 6 servo motors.


The electrical connections of the servo motors to the PCA9685 assembly are connected according to the numbering of the servo motor with the number of the corresponding PWM output port on the assembly, i.e. servo motor number 0 with output port 0.


The 5V DC power supply is connected to the green screw connector on the ver board, paying attention to the polarity as the servo motors are supplied via this connector.

The connections between the Atmega328P microcontroller and the PCA9685 module are the I2C communication via its port and the 5V for the power supply of the module electronics.


The six servo motors are controlled by the Atmega328P microcontroller via the PCA9685 module, which has two important functions. The first is to supply the servo motors with 5V from an external power supply with enough power to move the 6 servo motors simultaneously. The second is to send the PWM signal to the respective servo motor, which was transmitted via the I2C signal from the microcontroller. As can be seen in the diagram above, we only need 2 pins for communication between the microcontroller and the PCA9685 module, leaving the other pins for other uses.


The really tedious part of this project is setting the values for each position of the arm and the speeds of the movements. The latter must slow down if the arm is to pick up an object.


For the adjustment and movement of the robot arm in each stage, one sketch per stage was created. This allows the settings to be made individually. When we have made all the settings correctly, we will combine them all into one sketch. We will use methods/functions so that the code is cleaner and easier to follow. Analyse the code for one stage and you will see that it is very simple. For the other stages, the adaptation method is similar.


The code we will analyse is the settings for the robot arm to pick up the first part. The sketch is called pick_up_first_object.ino.


The first two lines of code are the libraries we need for the sketch to run correctly. Wire.h is for I2C communication and Adafruit_PWMServoDriver is for using the PCA9685 module.

The next 4 lines are in order the implementation of an Adafruit_PWMServoDriver object to control the servo motor positions, SERVOMIN and SERVOMAX are the rising edge and falling edge values for the 0 degree and 180 degree position of the servo motors respectively. The speed variable is used for the waiting time until the next servo motor is moved.


The next 4 lines are in order the implementation of an Adafruit_PWMServoDriver object to control the servo motor positions, SERVOMIN and SERVOMAX are the rising edge and falling edge values for the 0 degree and 180 degree position of the servo motors respectively. The speed variable is used for the waiting time until the next servo motor moves. In the setup() method we initialise the serial monitor and output a message. In the next two lines we initialise the PCA9685 module using its previously implemented object and specify the frequency at which the servo motors operate, 50 Hz.


In the setup()-method we initialise the serial monitor and output a message. In the next two lines we initialise the PCA9685 module using its previously implemented object and specify the frequency at which the servo motors operate, 50 Hz.


No comments:

Post a Comment

Post Top Ad

Pages