Build a Pocket Spirit Level That Measures Angles, Slopes and Tilt Using Gravity
Summary: This article provides a comprehensive guide to building a compact, portable digital spirit level. Utilizing an ESP32-C3 Super Mini and an MPU6050 sensor, the device accurately measures angles, slopes, and tilt, displaying real-time data on an OLED screen. Encased in a custom 3D-printed frame and powered by a rechargeable battery, it offers multiple measurement modes and on-the-go utility.
Key Takeaways
- DIY Digital Level: Construct a sophisticated pocket spirit level using an ESP32-C3 microcontroller and an MPU6050 accelerometer/gyroscope for precise angle, slope, and tilt measurements.
- Multi-Mode Functionality: The device features an OLED display and a rotary encoder, allowing users to switch between Level, Angle, and Tilt Guide modes, as well as toggle between degrees and percentage measurements.
- Compact & Portable Design: The project leverages 3D printing for a custom, ergonomic enclosure, making the tool highly portable and suitable for various applications, powered by a long-lasting rechargeable battery.
- Simplified Circuitry: Learn how to transition from a breadboard prototype to a compact, soldered circuit, optimizing space and reducing wire clutter for a professional finish.
Detailed Overview
This Instructable outlines the process of creating a compact Pocket Spirit Level, an innovative tool that goes beyond traditional bubble levels by providing digital measurements of angles, slopes, and tilt. Powered by an ESP32-C3 Super Mini and an MPU6050 sensor, this DIY project offers real-time data on an OLED display, complete with a rotary encoder for mode selection and calibration. The entire device is housed within a custom 3D-printed frame, making it a handy, portable tool for various measurement tasks.
Essential Supplies
To embark on this project, gather the following components:
- MPU 6050 Sensor
- ESP32-C3 Super Mini
- Rotary Encoder
- Jumper Cables
- Spirit Level (for the analog reference)
- OLED Module
- Breadboard (for prototyping)
- TP4056 Charging Board
- 3.7 V Rechargeable Battery
- 3D Printer
- PLA Filament
- Slicing Software (e.g., Ultimaker Cura)
- Arduino IDE
- Hot Glue, Double-sided Tape, Super Glue

Circuit and Arduino Program
The initial circuit is assembled on a breadboard for testing. The MPU6050 and OLED module share I2C pins (SDA to ESP32 pin 1, SCL to ESP32 pin 0). All modules' GND and VCC pins connect to the ESP32-C3's ground and 3 V pins, respectively. The rotary encoder's SW pin connects to D6, DT to pin 5, and CLK to pin 4 on the ESP32 board.
After wiring, upload the provided Arduino program to the ESP32-C3. Ensure the correct COM port and board type are selected in the Arduino IDE. Once uploaded, test the circuit by rotating the encoder to switch modes and tilting the sensor to observe display changes.

Deep Dive & Technical Insights
The core of this project lies in the ESP32-C3's ability to process data from the MPU6050. The MPU6050 is a 6-axis motion tracking device that combines a 3-axis gyroscope and a 3-axis accelerometer. By reading the accelerometer data, the ESP32 can calculate the device's orientation relative to gravity, thus determining angles, slopes, and tilt. The rotary encoder provides user input for mode selection and calibration, while the OLED display presents the measurements in a clear, digital format.
The Arduino program (level.ino) handles the sensor readings, calculations, display updates, and user interface logic. It's designed for automatic calibration upon startup, ensuring accurate measurements when placed on a flat surface.
- Arduino Program: level.ino
3D Designing and Printing
The enclosure for this pocket spirit level is designed using Tinkercad. The primary goal was to create a compact, rectangular frame that securely houses all the electronic components, including the ESP32, MPU6050, OLED, rotary encoder, and a rechargeable battery. A smaller 1200 mAh battery was chosen over an 18650 to optimize space and maintain a compact form factor without sacrificing performance.
The design includes specific slots and mounts for each component, ensuring a snug fit and easy assembly. The main frame, lid, and a holder for the analog spirit level are printed using PLA filament. Standard slicing software like Ultimaker Cura can be used with typical PLA settings.

- STL Files:
Simplifying the Circuit
After verifying the breadboard circuit, the next step is to simplify the wiring for a compact fit within the 3D-printed enclosure. This involves reducing redundant wires by branching ground and positive connections. For instance, instead of connecting three separate ground wires to the ESP32, they are consolidated into a single connection.
The rechargeable battery, initially with pre-soldered wires and a connector, is modified by directly soldering its wires to the TP4056 charging board. The charging board's output pins (ground and positive) are then connected to the ESP32, with a switch integrated into the positive line for power control. This streamlined approach eliminates the need for a breadboard and minimizes cable clutter.

Casing the Electronics
With the circuit simplified and 3D parts printed, it's time for assembly. Start by gluing the TP4056 charging board to the base of the 3D-printed frame. Next, secure the rechargeable battery to a corner of the frame using double-sided adhesive or hot glue. The ESP32 is then glued into an appropriate spot on the base.
For optimal performance, the MPU6050 sensor is affixed to the side of the 3D-printed frame using double-sided adhesive. Finally, the OLED display and rotary encoder are mounted onto the lid, along with the analog spirit level tube, which fits into a dedicated slot. Once all components are in place and wired, the lid is secured to the base using super glue, completing the device.

How to Use With Working Video
Using the pocket spirit level is straightforward. Simply turn on the power button. The device will automatically calibrate itself; ensure it's placed on a flat surface during startup for accurate calibration.
Once calibrated, the OLED display will show the spirit level meter. You can use this to check the flatness of any surface. Rotate the rotary encoder to switch between different modes:
- Level Mode: Displays the levelness of a surface.
- Angle Measurement Mode: Shows the precise angle of the surface.
- Tilt Guide Mode: Provides tilt information, also showing angles.
The device is designed for portability, allowing you to carry it in your pocket and take measurements anywhere on the go.

Conclusion & Resources
This DIY pocket spirit level offers a practical and educational project for makers interested in electronics, 3D printing, and microcontrollers. Its ability to provide precise digital measurements of angles, slopes, and tilt makes it a versatile tool for various applications, from home improvement to engineering tasks. The compact, rechargeable design ensures it's always ready for use.
- Author's Website: letsmakeprojects.com
- Original Project Source: Instructables - Build a Pocket Spirit Level That Measures Angles, Slopes and Tilt Using Gravity