3D Artificial Horizon/ Gyroscope Using Arduino and Processing3+
Works with mouse if desired.
Also works with ADXL345 and MPU6050/GY-521 Accelerometer/Gyroscope variations.
Note: This project is not completed. Dare I ever to lose this code on my HDD.
Azimuth doesn't work, but fully serves purpose without it.
A little shaky. Altitude also doesn't work... yet
Based on Kerbal Space Program (KSP)
Face the module like this when operating.

Aerospace Navigational Geometry: 3D Artificial Horizon
When an airplane flies through the clouds, the pilot has no visual reference to the ground; if the wing dips, they might accidentally fly perfectly upside down and crash. The 3D Artificial Horizon is an incredible engineering feat that extracts pure Cartesian Acceleration and Gyroscopic vectors from a tiny silicon MPU6050 (GY-521) IMU, porting the math via serial to Processing IDE to literally draw a massive, fluidly shifting artificial 3D box on the computer screen!
The I2C MPU6050 Quaternion Output Framework
Raw accelerometer data (X=15000, Y=3000, Z=-1500) is chaotic. If the Uno shakes slightly on a desk, the numbers vibrate violently, which would make the 3D airplane on the screen visually rip itself apart!
- The MPU6050 contains a catastrophic feature called the DMP (Digital Motion Processor).
- The Arduino must aggressively utilize the massive
I2Cdev.handMPU6050_6Axis_MotionApps20.hlibraries to tap into the silicon! - The internal DMP chip fuses the Accelerometer gravity vectors with the Gyroscope spin momentum, mathematically calculating Quaternions and Euler Angles!
- It outputs an incredibly smooth decimal:
Pitch: 14.5 degrees, Roll: 32.1 degrees, Yaw: 180.0 degrees.
The Serial Bridge to Processing IDE (Java Rendering)
The Uno cannot draw a stunning 3D airplane.
- The Uno acts strictly as a data-pipe. It blasts the flawless decimal numbers out
Serial.println(String(ypr[0]) + "," + String(ypr[1]) + "," + String(ypr[2]));at maximum 115200 baud! - The PC Java Architecture: The programmer opens a massively complex Processing IDE Java sketch.
- Over the USB Cable, Processing intercepts the string!
// Java code applying physical rotation directly to a 3D geometry shape!
rotateZ(radians(roll));
rotateX(radians(pitch));
rotateY(radians(yaw));
box(200, 10, 200); // Draws the physical 3D wings of the plane dynamically updating 60 frames per second!
Inertial Component Matrix
- Arduino Uno/Nano (Standard functionality).
- MPU6050 (GY-521) 6-Axis Accelerometer/Gyroscope Module (Absolutely ensure the I2C wires
SDAandSCLare connected securely. A loose wire will completely crash the DMP initialization array!). - Processing IDE Software (Installed on a PC/Mac to handle the heavy WebGL 3D rendering pipeline!).
- A 12-inch massive USB cable tying the entire architecture seamlessly to the host display!
Connect the ADXL345 or MPU6050/ GY-521 into the Arduino.
We will use A4 and A5 here.
SCL - A5
SDA - A4
