Visual Tilt Tracker using Arduino UNO and MPU6050 with LED Directional Display

If you’ve ever wanted to turn motion into something visual, this simple yet fascinating Arduino project might be the perfect place to start. By combining an MPU6050 accelerometer with an Arduino UNO and seven LEDs, I created a tilt direction indicator that shows movement to the left or right using a smooth LED sweep.

Whether you’re new to motion sensors or want to add interactive lighting to your robotics or wearables, this project will walk you through a practical and visually appealing implementation.

PCBWay offers high-quality PCB prototyping and assembly at an affordable price, starting at just $5 for 5 PCBs. With fast turnaround, great customer support, and easy online ordering, it’s a top choice for hobbyists and professionals alike.

Hardware Components

You’ll need the following hardware components to get started:

ComponentsValue / ModelQty
Arduino UNOR3 Board1
AccelerometerMPU60501
LEDs5mm or 3mm (any color)7
Resistors220Ω7
BreadboardFull-size or half-size1
Jumper WiresMale-to-male1 set
USB CableFor Arduino UNO (Type B)1
Power Supply5V via USB or external source1

How It Works ?

The MPU6050 sensor detects the angle of tilt along the Y-axis. Based on the tilt angle, one of the 7 LEDs is turned on to show how far the device has tilted left or right. The middle LED lights up when the device is level. As you tilt the setup left, LEDs light up progressively to the left. The same happens to the right when tilted in that direction.

Schematic

Make connections according to the circuit diagram given below.

Wiring / Connections

Arduino UNOMPU6050LED’s
3.3V or 5VVCC
GNDGND
A4SDA
A5SCL
Digital Pins 2–8Positive of all LED’s
GNDResistors (to GND)

Arduino Code

#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>

Adafruit_MPU6050 mpu;

const int ledPins[7] = {2, 3, 4, 5, 6, 7, 8}; // LEDs from left to right

int lastLit = -1;

void setup() {
  Serial.begin(115200);
  while (!Serial) delay(10);

  for (int i = 0; i < 7; i++) {
    pinMode(ledPins[i], OUTPUT);
    digitalWrite(ledPins[i], LOW);
  }

  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) delay(10);
  }

  Serial.println("MPU6050 Found!");
  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);

  delay(100);
}

void loop() {
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);

  float ay = -a.acceleration.y;  // Invert if needed
  float az = a.acceleration.z;

  float angleY = atan2(ay, az) * 180.0 / PI;

  int ledIndex = 3; // Default center

  if (angleY < -35) ledIndex = 0;
  else if (angleY < -25) ledIndex = 1;
  else if (angleY < -15) ledIndex = 2;
  else if (angleY > 35) ledIndex = 6;
  else if (angleY > 25) ledIndex = 5;
  else if (angleY > 15) ledIndex = 4;

  if (lastLit != ledIndex) {
    if (lastLit >= 0 && lastLit < 7) {
      digitalWrite(ledPins[lastLit], LOW);
    }
    digitalWrite(ledPins[ledIndex], HIGH);
    lastLit = ledIndex;
  }

  delay(100);
}

Conclusion

This project is a great way to learn about motion sensing and visual feedback. It introduces real-time data processing with sensors and demonstrates how physical movement can control outputs like LEDs. Whether you’re working on a tilt-based game controller, a gesture interface, or simply learning electronics, this is a solid and fun foundation.