Gyro Stabilizer W/ Arduino and Servo





Introduction: Gyro Stabilizer W/ Arduino and Servo


This is how I managed to use a MPU6050, an Arduino Nano, and two Servos to perform basic planar stabilization, as would be found on camera gimbals and so on. This is a work in progress but the guide provide hardware connections and basic code to implement my initial prototype.

My List of Parts:

1 x 6 DOF MPU-6050 module ( from

1 x Arduino Nano

2 x 9g Servos ( from

2 x 10k Resistors

1 x Breadboard

Jumper wires

USB Battery pack (for independent power) or use USB power from a PC

IMPORTANT: I pay only w/ PayPal. I read that you shouldn't use credit cards there.

Step 1: Step 1: Push Things in and Roll Tape.

1. It took me a long time to convince me that I need 10k Pull-Up Resistors on SCL and SDA pins off MPU-6050 module. But they are vital for the MPU to function properly. Before I added those resistors, my MPU would cause lock-up w/in a minute of power-up. Also pay attention to the #2 and #3 below for complete solution.

(Updated on 1/17/16)

2. Jeff Rowberg @ points out ADO pin must be connected to GND ( post).

3. ArsenioDev also points out that baud rate for MPU should be kept at maximum 115200.

4. Thank you for the tips! The tips above completely solved my lock-ups!

5. I'm now running on a DIY Uno w/ ATmega32P-PU w/ clock and two caps and it's running equally great! ATmega by itself only takes about 3ma right now, aside from the MPU and Servo powers.

For wire connections, use the diagram or pictures as a reference. (Also explained in the code)

MPU -> Arduino

VCC -> 5V (this powers the rail and hence the whole system including the servos)


SCL -> A5

SDA -> A4

INT -> D2 (I have it but not used in current software. I'm polling, not interrupting in this set up)

IMPORTANT: In addition to the wires above, two 10k resistors:

SCL -> 10K resistor (BROWN-BLK-ORANGE-Whatever) -> 5V Rail

SDA -> 10K resistor -> 5V Rail

ADO -> GND (Per Jeff Rowberg @ - See Above)

SERVO 1 -> Arduino

This is the first servo taped (I know it's totally a hack job) on the breadboard, and this is oriented so that it would rotate around the long (or longitudinal or roll) axis. My servos had Brown-Orange-Yellow wires.


ORANGE -> 5V Rail


SERVO 2 -> Arduino

This is the second servo that is mounted to the servo 1 which controls the pitch axis. Again, it's wrapped even worse than the first one so it's barely visible in the picture.


ORANGE -> 5V Rail


Step 2: Step 2: Check the Servo Orientation

For the code to work correctly w/o any adjustment, it would help to make sure the servos are oriented the same way as mine. I know the tapes make it terrible to discern. Sorry... If you tape up, or screw everything together and find out that something's turned around, it's no big deal. We'll fix it in the next step.

Step 3: Step 3: Send 1's and 0's to the Arduino Nano

Of course any Arduino should work, but I've been using these Nanos a lot for their affordable price.

Upload the code using the USB cable from your PC. If you have a long cable, you may just leave it alone and let it power the unit. I taped (I know. This is the last one.) a USB power bank underneath the breadboard so I can hold it and feel cool about my sticky mess.

BTW, I have been using the USB brick underneath a breadboard and use USB output to power an Arduino or even connect to a USB-Serial interface (Like an FTDI interface) to power the breadboard and it's been very handy.

It should fire up, and should start it's wake-up dance. It's designed to sweep on both axis to clear the area. If it hits the chassis or things like that, it's possible the mount is too restrictive or servo is mounted backwards.

If a servo seems mounted backwards, you can adjust the code to reverse it's command:

<p>Servo1.write(-mpuPitch + 90);<br>Servo2.write(mpuRoll + 90);</p>

If the command seems to be adding to a change and not correcting it, you may try to reverse the sign of the mpuPitch or mpuRoll. Also, +90 is there because I oriented my servos so that 'normal' horizontal position would be in the middle of the servo range. You may play w/ that value as well depending on your installation.

Step 4: Step 4: Help Me Out Please

I learned a tremendous amount already from everyone w/ their awesome comments on Reddit. (

So please help me make it better and learn lots of other things. I put Kalman Filter and PID on the list of things to read up to improve the command logic. Thank you for reading my first instructable.

P.S. If it does lock up on you, a reset on arduino should get it going again. Sorry.

6 People Made This Project!


  • Epilog Challenge 9

    Epilog Challenge 9
  • Pocket-Sized Contest

    Pocket-Sized Contest
  • Science of Cooking

    Science of Cooking

We have a be nice policy.
Please be positive and constructive.



Great project, but i have problem with it i use arduino uno, and when i start program it writes mpu failed to connect and arduino external interupt 0 and fifo overflow can you help me



i'm using the mpu6050 with a mega ADK, and somehow when i ran the code and using the serial monitor, it always ends up in
"Enabling interrupt detection (Arduino external interrupt 0)"

did the code doesnt work with an ADK or what? thank you

Works great! just downloaded the coad , did not re flash the mpu or anything! only with current arduino uno i had to use pin DIGITAL 2 and 3 for outputs for servo's :) Thanks! also used the 3.3V from the arduino for the mpu and 5V for servo's straight from the powersupply not the arduino :)

puedo poner una resistencia en cada extremo

My servos didn't moved (my servos are fine, indeed i see the dance)

in serial monitor it only said "Initializing I2C devices..." the "Testing device connections..." won't appear and so the next message :(

did i do something wrong ?(i followed exactly your instructable, except for the power source)

oo yeah i almost forget to mention, i used uno w/ usb power source. At this point i started to think i dont have enough power, is that true?

many thanks btw, i can use ur code as refence :)


so i got rid of the pull-up resistor and foila.

my question is, BUT WHY :/

Worked for me as well. Thanx.

why is it showing me compilation error in arduino.ide

Download libraries from this link and try again

Great project! I used a Nano and the system adjusts for MPU-6050 pitch and roll orientation changes very accurately! Many thanks to Woojay! Next, I would like to control 3 servos - for pitch, roll and yaw. Does anybody have connection and sketch suggestions for three axes?

Gimbal 2 Servo project.jpg