• sales

    +86-0755-88291180

Chapter 10 of KitiBot-Microbit: Ultrasonic Obstacle User Guide

Chapter 10 Ultrasonic Obstacle

In this chapter we talk about how to use ultrasonic sensor and use ultrasonic for obstacle.

Generally, our ears cannot hear sounds above 20 kHz (sound was generated by vibration, 10 kHz, which is equivalent to 20 thousand vibrations per second, which is 20,000 times). Sonic waves produced above 20 kHz are called "ultrasounds". Due to their amblyopia, bats flying at night emit such ultrasound. Bats rely mainly on ultrasound to locate any avoidable obstacle on their way. Sound waves are emitted by the bat's throat and received by their ears, according to the received sound waves. They can determine the position of the front object. Ultrasound sensor invention is based on the same method


Ultrasonic sensor is mounted on the cat face, looks like two eyes of the cat, one eye is receiver and another is sender. With this ultrasonic sensor, Robot can detect the distance of obstacle in the front.

Read value of ultrasonic sensor

: Using Ultrasonic block, we can read distance value (integer) from ultrasonic sensor.

We make a project to read ultrasonic value and display to LED matrix


Show distance value with bar graph

Light more leds if obstacle is farer, less leds if closer


Obstacle detecting

We use ultrasonic sensor to detect obstacle and make robot stop when obstacle detected.


Ultrasonic sensor keeps detecting distance of obstacles in front, if distance is farer than 15cm, robot move forward, and stop if distance detected is less than 15cm. Note that you need to set servo degree to 90 on start, make sure ultrasonic sensor faces forward.

Turning when obstacle detected

We modify the code, let robot turn right when obstacle detected.


Turning according to distance

Here we add servo control code. Robot will rotate to both side to detect distance (obstacle) and turn to the farer side when obstacle is detected in front.

https://cdn.static.spotpear.com/uploads/picture/learn/micro-bit/micro-bit-kit/chapter-10-of-kitibot-microbit/chapter-10-of-kitibot-microbit-11.gif

Variables rdis and ldis are used to save distances of right side and left side. By comparing rdis and ldis, robot can judge which side is farer. Pause are added because servo need times to rotate.

TAG: XIAO RA4M1 Tiny SuperMini Board For Arduino Uno IDE For SeeedStudio R7FA4M1 Raspberry Pi PICO 7.5 inch Passive NFC e-Paper V2 BW Display 7.5inch E-ink Screen No Need Battery Wireless Powered Data Transfer For Mobile APP ADXL354BEZ JSON Command Meaning Pi5 Case Raspberry Pi CM5 Mini Base IO Board NANO B Development For Compute Module 5 DeepSeek AI Voice Chat ESP32 C6 Development Board 1.69 inch LCD Display 240x280 1.69inch TouchScreen Programmable Watch Screen Black ESP32-S3 QMI8658A Sipeed Lichee Tang Nano1K FPGA MINI Development Board GW1NZ-1 ESP32-S3 Smart 86 Box Development Board with 4 inch 480x480 Display Touch Screen For AI and DeepSeek Raspberry Pi Pico 2 RP2350 1.69 inch LCD TouchScreen Development Board 240x280 1.69inch Display QMI8658 6-Axis STM32 0.96inch RGB OLED Day and IR Night Vision ESP32 Serial UART Bus Servo ST3215-HS 20KG.CM High Speed Magnetic Encoder 360° Large Torque Industrial Modbus RTU Dual Ethernet RJ45 To 8ch POE ETH Relay (C) PoE Power over Ethernet Raspberry Pi 5 PCIe FFC Connector to Standard PCIe x1 Slot (C) Expansion Board