Introduction: LEDs and Gravity ?

This project has no practical use at all, but was initiated as an exercise in implementing physics formulas related to gravity in C-code on an Arduino. To make things visible, a neopixel LED-strip with 74 LEDs was used. The effect of the gravitational acceleration on an object is demonstrated by using a MPU-6050 accelerometer and gyroscope chip. This chip is physically attached to the LED-strip, so when the LED-strip is held at a certain angle, the chip measures the angle of the LED strip and the Arduino uses this information to update the position of a virtual object as if it was a ball that is balanced on a beam and rolls from one side to the other if the beam is held at an angle. The position of the virtual object is indicated on the LED strip as a single LED that is illuminated.

To update the position of a virtual object that is falling to the earth under the influence of gravity, we use the formula :

y = y0 + (V0 * t) + (0.5 * a * t^2)

With :

y = travelled distance in meters
y0 = start distance in meters
v0 = start velocity in meters/second
a = acceleration (gravity) in meters/second^2
t = time in seconds

Step 1: Circuit

The Arduino Pro Mini is powered by feeding a +5V supply directly into the +5V pin, which is the output of the onboard 5V regulator. This might seem a bit orthodox, but when Vin is left open, it does not create a problem as long as you don't reverse the polarity, because that would certainly toast your Arduino.

The MPU6050 accelerometer and gyroscope chip is powered via a low power 5V to 3V3 converter module and talks to the Arduino via an I2C interface (SDA, SCL). With the Arduino Pro Mini, SDA is connected to A4 and SCL is connected to A5, which are both located on the Arduino Pro Mini PCB. With the Pro Mini version that i use, A4 and A5 were located within the PCB (2 holes) and were not accessible via the pin headers at the sides of the PCB. The MPU6050 also has an interrupt output (INT) that is used to tell the Arduino when there is new data available. The WS2812B neopixel LED strip with 74 LEDs is powered directly by the 5V supply and has 1 data line (DIN) that is connected to an output of the Arduino.

Step 2: Software

I put all the drivers that are used by the sketch (.ino) in the same folder as the sketch instead of using libraries. The reason for this is that i don't want the drivers to be updated, to prevent bugs from sneaking in and to prevent that changes that i did to the drivers will be overwritten by updates.

Here is a list of the project files :

  • Balancing_LED_using_MPU6050gyro.ino : sketch file
  • MPU6050.cpp / MPU6050.h : MPU6050 accelerometer and gyroscope driver
  • MPU6050_6Axis_MotionApps20.h : MPU6050 DMP (digital motion processor) definitions and functions
  • helper_3dmath.h : Class definitions for quaternions and integer or float vectors.
  • I2Cdev.cpp / I2Cdev.h : I2C driver using the Arduino wire library
  • LEDMotion.cpp / LEDMotion.h : Implementation of the gravity LED balance using the LED strip and angle measured by the MPU6050

Step 3: Pictures

Step 4: