Introduction: MPU6050 Controlled Servo Arm

Picture of MPU6050 Controlled Servo Arm

So, in this instructable i present the process to make a 2-axis pan and tilt servo arm controlled using the MPU6050

First of all we need to Upload the files from and into the Arduino IDE library.
This can be done by extracting the files within the .zip folders and copying into the library folder of the arduino IDE.

The parts needed for this project are:
1) Arduino UNO
2) Breadboard
3) MPU6050
4) 2 x Servo motors ( i used microservo motors in this case)
5) Male-Male Jumper cables
6) Computer with Arduino IDE

The connections should be made as shown in the Fritzing diagram.

For MPU6050:
SCL -> A5
SDA -> A4
INT -> 2

Servo1 -> 9
Servo2 ->10

After all the connections are made, upload the code onto your Arduino:

#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Servo.h"

MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
Servo servo1;
Servo servo2;

int val1;
int val2;
int prevVal1;
int prevVal2;

void setup()
Serial.println("Initialize MPU");
Serial.println(mpu.testConnection() ? "Connected" : "Connection failed");

void loop()
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
val1 = map(ax, -17000, 17000, 0, 179);
if (val1 != prevVal1)
prevVal1 = val1;
val2 = map(ay, -17000, 17000, 0, 179);
if (val2 != prevVal2)
prevVal2 = val2;

Important note: There might be issues connecting the MPU6050, as the wires keeping running lose, so when you initially upload it, check in the serial moniter if the accelerometer was successfully connected. Else reconnect and try again.

Tips: You can add more servos by introducing new variables and mapping accordingly. Adding more powerful servos and a better structure can open new possibilities like a fpv camera mount etc


Always ready for feedback.
Thank you.


alexpou (author)2017-06-30

Hello, where did you find the values -17000, 17000, 0, 179 ? Are they your offsets?

Idrispo (author)2016-09-16

It is not so smooth. How can we make it smoother?

Michael Chan (author)2016-06-04

Thanks for sharing!

From the line "map(ax, -17000, 17000, 0, 179);", how come the acceleration values are assumed to be within -17000 and 17000? Aren't they 16-bit values? If so, shouldn't the range be wider than -17000, 17000?

DswW (author)2016-05-30

Hello, Can i see how is your servo motor connected with each other in detail?

And can i know the exact model of the servo motor that you are using pls?

tq for sharing

Soul_seeker (author)DswW2016-05-31

Unfortunately i disassembled the setup, but its a Towerpro 90g motor found here:

As for servo connection its basically arm of one servo is glued ontho the body of other servo, in order to use two axis.

AlexAndAmigos (author)2016-05-24


gada888 (author)2016-05-24

Thanks for sharing.

Soul_seeker (author)gada8882016-05-24

Anyday brother ! :D

About This Instructable




More by Soul_seeker:MPU6050 controlled servo armSweeping obstacle detector
Add instructable to: