Back AeroTech PROJECT #Stabilizer

ESP32
Self-Leveling
Stabilizer

Robotics ESP32 MPU6050 Servo Motor I2C
ESP32 Self-Leveling Stabilizer
// Overview

Abstract

This project demonstrates a self-leveling stabilization system using an ESP32 microcontroller and MPU6050 sensor. The system detects tilt angles and automatically adjusts a servo motor to maintain a horizontal position in real time.

// Goals

Objective

// Hardware

Components

ESP32
📐
MPU6050 Sensor
⚙️
Servo Motor
🔌
Breadboard
// How It Works

Working Principle

The MPU6050 sensor measures tilt using its accelerometer data on X and Y axes. The ESP32 processes this data and calculates the exact angle of inclination. Based on the calculated angle, the servo motor moves in the opposite direction to counteract the tilt and stabilize the platform in real time.

// Source Code

Code

C++ / ESP32
#include <Wire.h>
#include <MPU6050.h>
#include <ESP32Servo.h>

MPU6050 mpu;
Servo servo;

float angle;

void setup() {
  Wire.begin(21, 22);
  mpu.initialize();
  servo.attach(18);
}

void loop() {
  int16_t ax, ay, az;
  mpu.getAcceleration(&ax, &ay, &az);

  angle = atan2(ay, az) * 180 / PI;

  int servoPos = map(angle, -90, 90, 0, 180);
  servoPos = constrain(servoPos, 0, 180);

  servo.write(180 - servoPos);

  delay(20);
}

✓ Results

  • Stable response to tilt
  • Smooth servo correction
  • Real-time balancing

↑ Future Improvements

  • PID control system
  • Kalman filter for accuracy
  • Dual-axis stabilization