SuperKitz.com Project Manual
Simple 2-axis Servo Robotic Arm controlled by MPU-6050
A Robot is a virtually intelligent agent capable of carrying out tasks with help of some supervision. In this project, we design a robotic arm which is very much similar to a human hand using an MPU-6050 (gyroscope) module to calibrate the position and motion of the hand and emulate it on the 2-axis servo robot. The servos are motors that rotate to a certain degree and we can program it to do certain movements to give the bunny robot a life-like feel.
So here in this project, we are designing a simple and interesting 2axis robotic arm using an MPU6050 module and sg90 hobbyist servo. We’ll also be learning how to communicate with each module with the Arduino and programming.
Requirements :
- Computer with an internet connection
- Download and install Arduino IDE
Components
1. MPU6050 Gyro sensor
2. Arduino UNO
3. Breadboard
4. Micro Serov SG90
5. Jumper wires
6. Pan and Tilt
HARDWARE
ARDUINO UNO
Although there are many types of boards from arduino . Here we are going to be using the Arduino UNO as it is the most commonly used one. The arudino UNO has :
- The operating voltage is 5V
- The recommended input voltage will range from 7v to 12V
- Digital input/output pins are 14
- Analog i/p pins are 6
- DC Current for each input/output pin is 40 mA
- Flash Memory is 32 KB
- SRAM is 2 KB
- EEPROM is 1 KB
- CLK Speed is 16MHz
Another wonderful feature of the Arduino is the option of using add-on boards to the Arduino which comes as a module and they are known as “Shields”
Pin out diagram
Arduino UNO
MPU6050 Gyro Sensor
The MPU-6050 is a sensor based on Micro Electrical Mechanical System (MEMS) technology. In this sensor module, the 3-axis accelerometer and the 3-axis gyroscope embedded in a single chip using I2C protocol to communicate, which helps to measure the acceleration, voltage, orientation, displacement, and many parameters of a system. An onboard Digital Motion Processor in this module is used to process the 6 axis fusion algorithm to provide a complete 9 axis motion fusion output by accessing the external magnetometer. MPU-6050 is a low cost and highly accurate sensor with an I2C bus.
This sensor has 8pins, the pins are follows :
VCC,GND,SCL,SDA,XDA,SCL,AD0,INT
This is an easy and interesting project in which you use an MPU6050 (Accelerometer + Gyro) sensor module to control a simple 2-axis Servo Robotic Arm
- Examples where MPU-6050 may be used
- Automotive industry – To deploy airbags,Vehicle roll handling
- Game controllers – Wii remote/ Wiimote
- Gimbal/ Camera stabilisation system
- Hard drives
- Personal Digital Assistants – Smartphones, tablets
- Robotics
- Unmanned Aerial Vehicles (UAV) – Drone, helicopters
- Vehicle Navigation.
Micro Servo Motor
Micro servo motors provide precise control of linear and angular position, velocity, and acceleration. They are useful in many robotics projects, such as for turning the front wheels on an RC model for steering or pivoting a sensor to look around on a robotic vehicle.
Servo is a general term for a closed-loop control system which consists of a suitable motor, couple to a sensor for position feedback signal, in order to adjust the speed and direction of the motor and to achieve the desired result
RC servo motor works on the same principle. It contains a small DC motor connected to the output shaft through the gears.
A servo motor works with a small DC motor connected to the output shaft through the gears. The output shaft drives a servo arm which is connected to the potentiometer (pot). The potentiometer provides position feedback to the servo control unit where the current position of the motor compared to the target position.
The control unit corrects the actual position of the motor according to the error so that it matches the target position.
How Servo Motors Work?
A servo motor can be controlled by sending a series of signal pulses to the signal. A conventional analog servo motor can receive a pulse roughly every 20 milliseconds (i.e. signal should be 50Hz). The position of the servo motor determines the length of the pulse.
- If the pulse is high for 1ms, then the servo angle will be zero.
- If the pulse is high for 1.5ms, then the servo will be in its center position.
- If the pulse is high for 2ms, then the servo will be at 180 degrees.
In this servo motor, the pulses ranging between 1ms and 2ms will rotate the servo shaft to full 180 degrees of its travel.
CIRCUIT DIAGRAM
CONNECTING MPU6060 Sensor To ARDUINO
STEP1:
Wire up the data lines and power lines of the Ultrasonic sensor.
- MPU6050 Sensor VCC -> Arduino 5V
- MPU6050 Sensor GND -> Arduino GND
- MPU6050 Sensor SCL -> Arduino Analog Pin A5
- MPU6050 Sensor SDA -> Arduino Analog Pin A4
STEP2:
Wire up the Servo Module (Pitch)
- Relay VCC -> Arduino Vcc
- Reay GND -> Arduino GND
- servo Signal -> Arduino Digital Pin 10
Wire up the Pitch Module (Pitch)
- Relay VCC -> Arduino Vcc
- Reay GND -> Arduino GND
- Servo Signal -> Arduino Digital Pin 9
PROGRAMMING
Getting started with Arduino
Arduino Integrated Development Environment (IDE) is a common and prominent software running on the system which allows writing programs in Arduino language for different Arduino boards (sketch). Processing is known as the hardware programming language for Arduino, is somewhat similar to c language. The sketch written in the Arduino IDE, it should be uploaded on the Arduino board for execution.
Before starting any project, we need to interface Arduino with computers. So we have to write and compile code for the Arduino to execute, as well as providing Arduino to function with a computer.
Connect your Arduino Uno board with an A B USB cable; sometimes this cable is called a USB printer cable
If you used the Installer, as soon as you connect your board the Windows – from XP up to 10 – will install drivers automatically
If the board is not properly recognized when the zip package is downloaded and expanded, please follow the procedure below.
- START menu> CONTROL PANEL MENU
- From the control panel, check for System and Security
- Select system
- Select Device Manager from the System window
- Select open port named “Arduino UNO (COMxx)”, under Ports (COM & LPT). If there is no COM & LPT section, check “Other Devices” for “Unknown Device”.
- Choose the “Update Driver Software” option by right-clicking on the “Arduino UNO (COmxx)” port
- Navigate to the “Browse my computer for Driver software” option.
- Choose the driver file named “arduino. inf”, located in the “Drivers” folder of the Arduino Software download (not the “FTDI USB Drivers” sub-directory). If you are using an old version of the IDE (1.0.3 or older), Choose the Uno driver file named “Arduino UNO.inf”, If an old version of the IDE (1.0.3 or older) is used
- Thus the windows driver installation is completed
Select your board type : Arduino UNO and port
Choose Tools | Serial Port menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port.
Press CNTRL + A & press DELETE to clear the Arduino IDE page
Upload the program
Copy the Sketch Code given below And try to understand
After that click on the “Upload” button. Then we can see the RX and TX LEDs on the board flashing. The message “Done uploading.” will appear if the uploading is a success
Install I2Cdev and Arduino-MPU6050-master as ZIP file in Arduino IDE
Download Arduino-MPU6050-master Library by clicking the button: Download Arduino-MPU6050-master
Do not unzip the downloaded library, leave it as is.
- In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library. At the top of the drop down list, select the option to “Add .ZIP Library‘‘.
- Then select the library zip file you have downloaded.
- Return to the Sketch > Include Library menu. menu. You should now see the library at the bottom of the drop-down menu. It is ready to be used in your sketch. The zip file will have been expanded in the libraries folder in your Arduino sketches directory.
Arduino Code
Before we start, restart the Arduino IDE after installing the library.
#include <MPU6050.h>
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
MPU6050 mpu;
int flagpitch = 0;
int flagroll = 0;
int steprate = 1;
unsigned long timer = 0; // Timers
float timeStep = 0.01;
float pitch = 0; // Pitch, Roll and Yaw values
float roll = 0;
void setup()
{
myservo1.attach(9, 600, 2300); // (pin, min, max) servo
myservo2.attach(10, 600, 2300); // (pin, min, max) servo
Serial.begin(115200);
while (!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G)) // Initialize MPU6050
{
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
delay(500);
}
// mpu.setThreshold(3); // Default 3. If you don't want use threshold, comment this line or set 0.
}
void loop()
{
timer = millis();
Vector norm = mpu.readNormalizeGyro(); // Read normalized values
pitch = pitch + norm.YAxis * timeStep; // Calculate Pitch and Roll
roll = roll + norm.XAxis * timeStep;
controlfunc2(pitch, roll);
//print the pitch and roll
Serial.print(" Pitch = ");
Serial.print(pitch);
Serial.print(" Roll = ");
Serial.println(roll);
delay((timeStep * 1000) - (millis() - timer)); // Wait to full timeStep period
}
void controlfunc2(float,float) {
myservo1.write(pitch+90);
myservo2.write(roll+90);
Serial.print(" Servo1 = ");
Serial.print(pitch+90);
Serial.print(" Servo2 = ");
Serial.println(roll+90);
}
Then, click the Upload button in the Arduino IDE and wait a few seconds until you see the message “Done uploading.” in the bottom left corner.
Output
After connecting, it should look like this. The Robot comes to (0- pitch,0 – roll) position. Adjust it accordingly.
before turning it on , keep the gyroscope in a suitable position from where its going to take the calibration of the coordinates as 0,0,0 (x,y,z axis) , then move your hand to get the output on the relay
You should see the Pitch and Roll coordinates