Skip to content

Projects

#10 Depth Meter With micro:bit

by PicoBricks Team 07 May 2025

Sometimes, we use depth-measuring machines to measure the quantity of a beverage or mixtures of liquid materials poured into a glass. The fundamental variable that needs to be known for these machines to measure depth is the depth amount measured when the container is empty. After defining this information to the measurement devices, the device performs the measurement process by using various sensors such as ultrasonic distance sensor, IR sensor, etc.

In this project, we will control the water pump connected to the motor driver based on the value measured by the ultrasonic distance sensor we connect to PicoBricks. We will transfer the desired amount of liquid from the container filled with liquid to the empty one. To determine the depth of the glass, we will use the potentiometer & button module.

Connection Diagram:

You can prepare this project without making any cable connections.

Project Images:

 

MakeCode Code of The Project


Python Code of The Project:

#Depth Meter Projects
from microbit import *
from picobricks import *

# Pin Initialization
Pot_Pin = pin1
Button_Pin = pin2

# Function Initialization
oled = SSD1306()
oled.init()
oled.clear()
motor = motordriver()
button = Button_Pin.read_digital()

while button_a.is_pressed()==0:
    oled.clear()
    glassDeepValue=10
    oled.add_text(2,0,"Press the")
    oled.add_text(3,1,"A Button")
    oled.add_text(5,2,str(glassDeepValue))
    sleep(100)

while True:
    oled.clear()
    distance = measure_distance()
    print(distance)
    waterDeepValue=glassDeepValue-round(distance)
    oled.add_text(0,2,"Depth:")
    oled.add_text(8,2,str(waterDeepValue))
    if waterDeepValue<(glassDeepValue-4):
        motor.dc(1,150,1)
    else:
        motor.dc(1,0,1)
    sleep(100)

MicroBlocks Code of The Project

 

Prev Post
Next Post

Thanks for subscribing!

This email has been registered!

Shop the look
Choose Options

Edit Option

Back In Stock Notification

Compare

Product SKURatingDescription Collection Availability Product Type Other Details
this is just a warning
Login
Shopping Cart
0 items
Same Day Shipping No Extra Costs
Easy Returns Guarantee Return with Ease
Secure Checkout Secure Payment