Introduction: Make an Ultrasonic Distance Tester With Micro:bit

About: ElecFreaks is an open design house founded in March 2011. Our goal is to create rapid prototypes and give small-batch manufacture solution for makers and startups. With over 50% staff as engineers and expanded…

Today, we are going to make an ultrasonic distance tester with micro:bit and ultrasonic sensor module.

Step 1: Materials Needed

Step 2: Background Knowledge

HC-SR04 Basic Principle

HC-SR04 is a kind of ultrasonic distance measuring modules. With this module, we can detect the space time between ultrasonic send and return, then convert it into distance. Here's the basic principle:

  • Use the IO port TRIG to trigger distance measure with 10us high electric level at least.
  • Automatically send 8 40kHz square wave and check if a signal returns.
  • If a signal has returned, then output a high electric level through the IO port TRIG. The duration of high electric level is the time from ultrasonic send and return.

Distance=(high electric level time x sound space (340m/s))/2

Note: Find in the MakeCode for the already sealed ultrasonic library. You don't have to write any complicated drive code but just simplly invoke the library.

Step 3: Hardware Assembly

1.You can refer to the column for the connection between ultrasonic module and octopus.

2.Since the driving voltage of SR04 ultrasonic module is 5V, so we must slide the voltage switch on octopus:bit to the end of 5V.

3.Plug OLED module into IIC cpnnector on octopus:bit.

4.Once connected, you can see the following picture showed:

Step 4: Programming

1. Click to open and enter the programming interface.

2.Search sonar in ADD Package, then add the ultrasonic library.

3.Search OLED in ADD Package, then add the library for OLED module.

4.Initialize OLED screen.

5.Set the pin trig to be P14 and the pin echo to be P15 with cm as unit. And display the data returned on the OLED screen.

6.When you finished your program, you can get the whole code from this link:

Or you can download the code into micro:bit directly through the web page below.

Step 5: Result

Now you have already successfully created a set of ultrasonic measuring device. Point the ultrasonic head to the object you would like to test, then you will see the distance between on the OLED screen.

Step 6: Source

This article is from:

If you have any questions, you can contact: