Gyroscopic Arduino Head Tracking Unit

About: Electrical Engineering Undergrad at Virginia Tech

This is a subsystem I developed for a custom Arduino RC plane I am currently designing and building. This head tracking system is used to control the angle of an on board FPV (First Person Video) camera based on the pilot's head movement using a gyroscope.

Disclaimer: The image above belongs to Oculus Rift

Materials needed:

Arduino Mega 2560

MPU 6050 3 axis accelerometer and gyroscope

Different colored wire (20 gauge should work)

Wire strippers

Soldering iron and solder

3 90g Tower Pro servos

1 breadboard (or protoboard/PCB)

Step 1: Connecting the MPU 6050 Gyroscope

Since the MPU 6050 uses I2C, we can disregard all pins not pertaining to I2C or supply. The INT (interrupt) pin can be quite useful, but this project does not need or utilize the pin.

Solder a red wire to VCC and connect the other end to one of the 5V supply pins on the Mega (you can also connect it to the 3V pin and it should work just fine)

Solder a black wire to GND and connect the other end to one of the GND pins on the Mega

Solder a grey wire to SCL and connect the other end to the SCL pin on the Mega

Solder a brown wire to SDA and connect the other end to the SDA pin on the Mega

NOTE: The wire lengths are completely dependent on the design of your own project. Also, make sure the wires you are using are "bendy" enough to move the gyroscope about easily (regular 20 gauge wire might not cut it).

Step 2: Connecting the Servos and Button

Use the Fritzing schematic and other pictures above to connect the peripherals correctly.

Also, the push button is used to reset the servos if the servos are in the incorrect position (basically resets the position of each servo to 90 degrees).

NOTE: In order to conserve power without losing functionality, use as large of a resistor as possible in the push button circuit (Power = Voltage^2 / Resistance).

Step 3: Code

Use the following code in the Arduino IDE (works on 1.6.7, not sure about any other version). Also, I apologize for the lack of comments. I'll probably do an update and add more comments later.


Step 4: Expansion: XBee for Wireless Control

This code will ONLY work with Arduino Megas.

Using two Arduinos and two XBee transceivers, you can make a remote controlled head tracking unit.

Take a look at the video I took of the unit I made.

Also below are the programs to upload to the Arduinos for wireless control.

Pinouts should be consistent with the previous version of the project, except that you need to be careful which component to plug into which Arduino. For more info on the pin connections, please take a look at the source code.


XBee - Arduino

GND - GND (obvious, I know)

3.3V - 3.3V (obvious, again)

Dout - RX2 (Pin 17)

Din - TX (Pin 16)



    • Epilog X Contest

      Epilog X Contest
    • Faux-Real Contest

      Faux-Real Contest
    • Toys Contest

      Toys Contest

    14 Discussions


    9 months ago

    Men your job is just INCREDIBLE. Finally i discover your fabulous sketch !!!!! THANK YOU SOOOOOOOOOO MUCH !!!!


    1 year ago

    hey, iam a engineering student and am working on a project quite similar to this, can you pleeeese help me, m quite stuck and you instructable was quite a huge help, but i want to talk to you about few things.

    my mail id is


    2 years ago

    Salut Va_Tech_EE,

    Ton code m’intéresse vraiment car il est relativement simple par rapport à tout se que j'ai pu tester. Mais il ne fonctionne pas sur UNO pourquoi ? je parle que de la partie FPV, j'ai supprimé toutes la partie concernant le Xbee

    et pour le projet final j'aimerais le mettre sur un nano ou mini.

    Merci de ta réponse.

    Hi Va_Tech_EE,

    Your code really interests me because it is relatively simple compared to everything I could test. But it does not work on UNO why? I'm talking about the FPV part, I deleted all parts regarding the Xbee

    And for the final project I would like to put it on a nano or mini.

    Thank you for your answer.

    2 replies

    Reply 2 years ago

    I have no idea what you're talking about. What do you mean it doesn't work on an UNO?

    If you're trying to do headtracking on a single Arduino, use the HeadTracking_Gyro_TEST.ino code.


    Reply 2 years ago

    Translate by Google:
    Thank you for your answer, I have only one servo on horizontal (pin7) because there is only the one that interests me. I
    take the file HeadTracking_Gyro_TEST.ino, I leave the initialization to
    be done, then when I turn 45 ° to the left the servo turns 45 ° to the
    left, then I turn 45 ° right to return to the starting position, the
    servo Turns about 10 °, on this test the mpu was fueled in 3.3v.
    I just tried in 5v as it can also, its works better. Left direction no worries by cons when I go to the right it's random, it works from time to time, it's weird. Hoping to have been clear.


    2 years ago

    I want to make one with a nano for size and weight reasons. Any suggestions for modifying your code so it will work? Perhaps this comment will inspire you to do a tutorial? I am probably not the only one who would like to make one of these but with a Nano or a Mini :)

    2 replies

    Reply 2 years ago

    That's very simple. Just use the softSerial library instead of Serial2 to transmit data (this will dictate which two data pins you hook up the XBee to the Nano with). Everything else a can stay the same. You will have to look up which pins are SDA and SCL on the Nano, though (this dictates how you hook the gyroscope to the Nano).


    2 years ago

    So far this write up looks great, thank you!! I'm going to hopefully get started on it this coming weekend; if I run into any snags I'll surely ask for some help, but until then, thanks again!!!

    2 replies

    Reply 2 years ago

    Cool! Just post and I'll get back to you as soon as I can.


    2 years ago

    Hello thankyou for sharing this project. Now I need your help. Can you help me to make this wireless using a rf module and with two arduino. One for connecting all servo and for rf reciever and other for rf transmitter to transmit the gyroscop values.

    1 reply

    Reply 2 years ago

    Thank you for the interest in the project! I do have a version that uses XBee transceivers. I'll upload the master/slave codes very soon.


    2 years ago

    Any suggestions, additions, or bug fixes would be greatly appreciated!