How to make a Smart Level Indicator with Raspberry Pi Pico and MPU6050

Hello and welcome back. In this project, we will learn how to make a DIY leveling tool using a Raspberry Pi Pico. For that, I mainly used the MPU6050 sensor. This sensor can measure acceleration and gyroscope values from three axes ( X, Y, and Z). In this project, I used only the Y-axis values to determine the level. If you don’t know what the MPU6050 sensor is or how to use it step by step, please check out this link. It will help you understand the basics before starting this project.
To indicate the level, I used 16 LEDs and a buzzer. When the device is tilted, the LEDs light up in a specific pattern, and the buzzer sounds an alert. I also designed and manufactured a custom PCB for this project with JLCPCB using free coupons. If you are a beginner with the Raspberry Pi Pico, I recommend checking out our basic tutorials first. You can also modify the Python script and use the X or Z-axis instead of the Y-axis.
OK let’s do this project step by step. The required components are given below.
- Raspberry Pi Pico board x 1 — Our store / Amazon
- MPU6050 sensor x 1 — Our Store / Amazon
- LED bulb x 16 — Our Store / Amazon
- 100-ohm Resistor x 16 — Our store / Amazon
- 5v Active buzzer x 1 — Our store / Amazon
- Female header x 2 — Our store / Amazon
- Two-pin terminal x 1 — Our store / Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.







Step 2
Second, let’s order the PCBs for this project by following the instructions below.


- Click the “Instant Quote” button and upload the Gerber file, which you can download from the link below.
- Gerber file – Download
- For this project, I ordered five red PCBs. Next, select the build time, and shipping method. Finally, click the “Save to Cart” button and complete the payment.





Step 3
Thirdly, unbox your PCB package.







Step 4
Next, solder the LEDs, resistors, female headers, buzzer, and pin terminal onto the PCB.





Step 5
Now, connect the MPU6050 sensor and the Raspberry Pi Pico board to the PCB. Then, connect the Raspberry Pi Pico board to the computer.



Step 6
Afterward, copy and paste the following Python script into the Thonny IDE.
- Python script — Download
from machine import Pin, I2C
import time
# Set up I2C on pins 0 (SDA) and 1 (SCL)
i2c = I2C(0, scl=Pin(1), sda=Pin(0))
# Lights (LEDs on pins 2 to 17)
leds = [Pin(a, Pin.OUT) for a in range(2, 18)]
# Buzzer on pin 18
buzzer = Pin(18, Pin.OUT)
# MPU6050 address and registers
MPU6050_ADDR = 0x68
PWR_MGMT_1 = 0x6B
ACCEL_YOUT_H = 0x3D
# Function to read a word (2 bytes) from a register and convert to signed integer
def read_word_signed(register):
try:
data = i2c.readfrom_mem(MPU6050_ADDR, register, 2)
value = (data[0] << 8) + data[1]
return value - 65536 if value > 32767 else value
except OSError:
return 0 # Return 0 if reading fails
# Function to initialize MPU6050
def init_mpu6050():
i2c.writeto_mem(MPU6050_ADDR, PWR_MGMT_1, b'\x00')
time.sleep(0.1)
# Function to determine which LED should be on
def get_led_index(accel_value):
if abs(accel_value) < 500:
return -1
index = min(abs(accel_value) // 2000, 7) # Scale to 0-7 range
return 7 - index if accel_value >= 0 else 8 + index # Map to LED positions
# Scan I2C devices
devices = i2c.scan()
if MPU6050_ADDR not in devices:
print("MPU6050 not found!")
exit()
init_mpu6050()
previous_led_index = -1 # Track the last LED index
while True:
accel_y = read_word_signed(ACCEL_YOUT_H)
led_index = get_led_index(accel_y)
if led_index != previous_led_index and led_index != -1:
buzzer.on()
time.sleep(0.05)
buzzer.off()
previous_led_index = led_index
for i in range(16):
leds[i].on() if i == led_index else leds[i].off()
time.sleep(0.02)
- Now, save it on the Raspberry Pi Pico as “main.py”, then click the Run button.




Step 7
Finally, disconnect the USB cable and provide a 5V DC power supply to the system. However, you can also test it using USB power. Ok, enjoy this project. The full video guide is below. So we hope to see you in the next project. Have a great day!





Troubleshooting tips
- Check the soldering points.
- Check the component status.
- Check the Python code.
- Check the power supply.
How to make a Smart Level Indicator with Raspberry Pi Pico and MPU6050