The HC-SR04 ultrasonic sensor can be used to measure the distance between an obstacle and the sensor using the Micro:bit. The sensor uses ultrasound to measure the distance, by sending out a sound wave and measuring the time it takes for the sound wave to bounce back.
To use the HC-SR04 sensor with the Micro:bit, you will need to connect the sensor to the Micro:bit‘s pins. The sensor has four pins: VCC, GND, Trig and Echo. VCC should be connected to 3V on the Micro:bit, GND to GND, Trig to one of the digital output pins (such as pin 0 or pin 1) and Echo to one of the digital input pins (such as pin 2 or pin 3).
In this tutorial we will learn how to use a reference ultrasonic distance sensor HC-SR04 with Micro:bit.
Micro:bit is a small, low-cost microcontroller board that was developed by the Micro:bit Educational Foundation for use in computer education. It is designed to be easy to use and accessible to a wide range of users, including children and beginners. The Micro:bit board measures about 4cm by 5cm and features a 25-pin edge connector, a 5×5 LED matrix, two programmable buttons, an accelerometer, a compass, a Bluetooth Low Energy (BLE) module, and a USB connector.
The Micro:bit is widely used in education, providing a hands-on learning experience for students of all ages to learn computer programming, logic, and problem-solving. It’s also used by hobbyist and makers to create fun and interactive projects.
Microbit GPIO board
A Micro:bit GPIO (General Purpose Input/Output) Expansion Board is an accessory that can be used to extend the capabilities of a Micro:bit by providing additional input/output (I/O) pins. These pins can be used to connect sensors and actuators, such as LEDs, buttons, motors, and other electronic components.
The expansion board typically connects to the Micro:bit using a standard edge connector and provides a set of male headers that can be used to connect external components.
The HC-SR04 is an ultrasonic distance sensor that uses sound waves to determine the distance to an object. It is a low-cost, easy-to-use sensor that can be used in a wide range of applications. The sensor has four pins: VCC, GND, Trig and Echo.
The sensor works by sending out a short ultrasonic pulse from the Trig pin and measuring the time it takes for the echo of the pulse to return to the Echo pin. The distance to an object can then be calculated using the speed of sound and the duration of the echo pulse.
The HC-SR04 sensor can measure distances from 2cm to 400cm with a precision of 3mm. However, the accuracy of the sensor can be affected by the environment, such as temperature and humidity, as well as the properties of the object being measured, such as its size, shape, and reflectivity.
Connecting wires are used to connect various components in an electronic circuit. They allow for the transfer of electricity, data, or signals between different devices and components.
When connecting wires to an Arduino or other microcontroller, it is important to pay attention to the correct pinout. The pinout refers to the arrangement of pins on the microcontroller and the corresponding function of each pin. The Arduino pinout can be found in the documentation provided by the manufacturer, or in various resources available online.
A test plate, also known as a test jig, is a device used to test electronic circuits and components. It is a board or plate that has been designed to hold and connect various components and devices in a specific configuration, allowing for the easy testing and measurement of their performance.
A test plate can be used to test various types of electronic circuits and components, such as microcontrollers, sensors, and actuators. It typically includes connectors and sockets for connecting wires, power supply and measurement devices such as multimeters, oscilloscopes, and power supplies.
The assembly is disconcertingly simple:
There are several mounting methods.
Here is the makecode program which displays the distance in cm on the micro: bit card which separates the ultrasonic sensor from an obstacle. Note: You must go to Extensions to import the Sonar extension.