Make An Ultrasonic Distance Tester with Micro:bit

Materials Needed

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))/2Note：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.

Hardware Assembly

Step 1

You can refer to the column below for the connection between ultrasonic module and octopus:bit

ultrasonic module

octopus:bit

VCC

VCC

GND

GND

TRIG

P14

ECHO

P15

Step 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.

Step 6

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.

ELECFREAKS is a globally competitive micro:bit peripheral product manufacturer, working closely with the micro:bit Foundation and its partners. We focus on the development, production and sales of micro:bit extension modules and accessories. In addition to that, the tutorials, blogs, and videos we create are our contribution to building a comprehensive knowledge base for the micro:bit community. Our belief is that programming is more interesting when it is tangible, and we aim to make coding more popular. We promise to provide excellent products and services to our customers.more