Hello guys, In this tutorial, we will learn how to control a 4 axis robot mechanical arm kit with an Arduino and 4 servo motors.
Please support us on YouTube also. Like Share and Subscribe to our channel : https://youtube.com/c/RatnasRoboLab
Total Materials
- Arduino Uno : https://amzn.to/3Axir6R
- Varo Board : https://amzn.to/41N04a3
- Breadboard : https://amzn.to/3HimZBI
- Jumper Wires : https://amzn.to/3V6UlJP
- Jumper Wires : https://amzn.to/3puH8Py
- Servo Motor : https://amzn.to/3JDeO4l
- Wooden Robotic Arm : https://amzn.to/3NT9goU
Assembling
This is very simple and easy to build kit and it is the perfect Arduino Project for Beginners and is a great learning platform to get into Robotics and Engineering.

Circuit Diagram

Controlling 1st Servo
Horizontal movement of the Robo Arm can be controlled by this servo. Here we are moving the arm from 120 degrees to 30 degrees and again 30 degrees to 120 degrees.


/* Sweep
by Ratnadeep <www.ratnasrobolab.com>
For more you may visit
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
Servo myservo1; // create servo object to control 1st servo
Servo myservo2; // create servo object to control 2nd servo
Servo myservo3; // create servo object to control 3rd servo
Servo myservo4; // create servo object to control 4th servo
int pos1 = 0; // variable to store the servo position
int pos2 = 0; // variable to store the servo position
int pos3 = 0; // variable to store the servo position
int pos4 = 0; // variable to store the servo position
void setup()
{
myservo1.attach(5); // attaches the servo on pin 5 to the servo object
myservo2.attach(6); // attaches the servo on pin 6 to the servo object
myservo3.attach(9); // attaches the servo on pin 9 to the servo object
myservo4.attach(10); // attaches the servo on pin 10 to the servo object
}
void loop()
{
for(pos1 = 120; pos1 >= 30; pos1 -= 1) { // goes from 120 degrees to 30 degrees
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(20); // waits 20ms for the servo to reach the position
}
for (pos1 = 30; pos1 <= 120; pos1 += 1) { // goes from 30 degrees to 120 degrees
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(20); // waits 20ms for the servo to reach the position
}
}
Controlling 2nd Servo
Vertical movement of the Robo Arm can be controlled by 2nd and 3rd servos. Here we are moving the arm from 30 degrees to 60 degrees and again 60 degrees to 30 degrees.


for (pos2 = 30; pos2 <= 60; pos2 += 1) { // goes from 30 degrees to 60 degrees
myservo2.write(pos2); // tell servo to go to position in variable 'pos'
delay(20); // waits 20ms for the servo to reach the position
}
for (pos2 = 60; pos2 >= 30; pos2 -= 1) { // goes from 60 degrees to 30 degrees
myservo2.write(pos2); // tell servo to go to position in variable 'pos'
delay(20); // waits 20ms for the servo to reach the position
}
Controlling 3rd Servo
Vertical movement of the Robo Arm can be controlled by 2nd and 3rd servos. Here we are moving the arm from 0 degrees to 60 degrees and again 60 degrees to 0 degrees.


for (pos3 = 0; pos3 <= 60; pos3 += 1) { // goes from 0 degrees to 60 degrees
myservo3.write(pos3);
delay(20); // waits 20ms for the servo to reach the position
}
for (pos3 = 60; pos3 >= 0; pos3 -= 1) { // goes from 60 degrees to 0 degrees
myservo3.write(pos3);
delay(20); // waits 20ms for the servo to reach the position
}
Controlling 4th Servo
At last by this servo we can control the hand movement for pickup and drop of an object.


for (pos4 = 0; pos4 <= 180; pos4 += 1) { // goes from 0 degrees to 180 degrees
myservo4.write(pos4); // tell servo to go to position in variable 'pos'
delay(20); // waits 20ms for the servo to reach the position
}
for (pos4 = 180; pos4 >= 0; pos4 -= 1) { // goes from 0 degrees to 180 degrees
myservo4.write(pos4); // tell servo to go to position in variable 'pos'
delay(20); // waits 20ms for the servo to reach the position
}
Result
By this program we can control the hand movement for pickup and drop of an object and this servo will rotate from 0 degrees to 180 degrees.
Further Readings
If you liked this article, then please subscribe to our YouTube Channel. You can also find us on Instagram, Facebook and Twitter.
READ – CONNECT – BOOST – CREATE