Introduction: Gyroscopic Arduino Head Tracking Unit
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.
Code:
Attachments
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.
HOW TO CONNECT XBEES:
XBee - Arduino
GND - GND (obvious, I know)
3.3V - 3.3V (obvious, again)
Dout - RX2 (Pin 17)
Din - TX (Pin 16)

Participated in the
Make it Move Contest 2016

Participated in the
Robotics Contest 2016
18 Comments
7 months ago
Very informative, detaild and functioning really well, I will try to use the NRF24 instead of the XBEEs is it gonna be simple to mod? Thank you Va_Tech_EE!!
Question 9 months ago
Has anybody actually made this work?
9 months ago
hello are u still around? thx
2 years ago
i am trying to get this working but to no luck can you help
5 years ago
Men your job is just INCREDIBLE. Finally i discover your fabulous sketch !!!!! THANK YOU SOOOOOOOOOO MUCH !!!!
6 years 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 abhijeetoxide@gmail.com
6 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.
Reply 6 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 6 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.
7 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 :)
Reply 7 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).
Reply 7 years ago
Awesome, thank you!!!
7 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!!!
Reply 7 years ago
How's the project coming?
Reply 7 years ago
Cool! Just post and I'll get back to you as soon as I can.
7 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.
Reply 7 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.
7 years ago
Any suggestions, additions, or bug fixes would be greatly appreciated!