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
Arduino Mega 2560
MPU 6050 3 axis accelerometer and gyroscope
Different colored wire (20 gauge should work)
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.
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)