How to use a water level sensor with the Microbit board

How to use a water level sensor with the Microbit board

Hello and welcome back! In this tutorial, we will learn how to use a water level sensor with the Microbit board. For this project, I’ve used an LCD screen to display the water level readings and the built-in buzzer to indicate when the water level is too high. You can customize these components as needed. For example, you could replace the LCD with an LED indicator or choose a different type of component. Also, I used the Microsoft MakeCode platform for this project, which is great for beginners as it allows us to create code easily with code block-based programming. The platform also gives you the option to switch to Python or JavaScript. When you are using Python or JavaScript codes, you can see the automatically generated code blocks. Also, you can use this knowledge for small water level monitoring and leakage detection projects. If you’d like to learn more about how the water level sensor works, please use this link.

OK let’s do it step by step. The required components are given below.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect the MicroBit board to the sensor shield.

Step 3

Thirdly, connect the I2C module and water level sensor to the sensor shield using the circuit diagram below.

How to use a water level sensor with the Microbit board

Step 4

Next, connect the MicroBit board to the computer, then open the MakeCode website and create a new project.

Step 5

Afterward, install the LCD extension. Then, click the Python tab and copy and paste the following script into the window. You should now see the auto-generated code blocks.

  • Python script and Circuit diagram — Download
value = 0
I2C_LCD1602.lcd_init(0)
I2C_LCD1602.show_string("Water Level", 0, 0)
I2C_LCD1602.show_string("Monitoring", 3, 1)
basic.pause(3000)
I2C_LCD1602.clear()

def on_forever():
    global value
    basic.clear_screen()
    value = pins.analog_read_pin(AnalogReadWritePin.P10)
    I2C_LCD1602.show_string("Water Level:", 0, 0)
    I2C_LCD1602.show_string("" + str(value) + " ", 12, 0)
    basic.pause(100)
    if value > 700:
        I2C_LCD1602.show_string("High", 0, 1)
        music.ring_tone(262)
    elif value < 700:
        I2C_LCD1602.show_string("Low ", 0, 1)
        music.stop_all_sounds()
basic.forever(on_forever)

Step 6

Now, connect the device to the computer. Finally, click the download button.

Step 7

Next, disconnect the USB cable and power the sensor shield with another power supply. I used two Li-ion batteries, but you can use a 9V battery or any other suitable power source.

Step 8

Finally, test the project with a cup of water. Enjoy the project! The full video guide is below. We hope to see you in the next project or tutorial. Have a great day!

How to use a water level sensor with the Microbit board

https://youtu.be/r9t7k2rik00

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *