Microbit Robotics Sensors & Circuits Artificial Intelligence
Intermediate
60 mins
Teacher/Student led
235 points
What you need:
Chromebook/Laptop/PC
Microbit
Move Motor Car

Car Distance Sensors

Discover the world of ultrasonic sensors with your Move Motor car. Learn how these sensors measure distance, and apply this knowledge to create a project that enables your car to follow an object, reverse, and roam freely while avoiding obstacles. Enhance your car's capabilities by adding lights and improving its sensor range.
Learning Goals Learning Outcomes Teacher Notes Lesson Files

Live Class Feed

This is a live feed of the latest activity by your students on this lesson. It will update in real-time as they work on the lesson.
Load previous activity

    1 - Introduction

    The Move Motor car has and ultrasonic sensor at the front of it.

    What is an ultrasonic sensor?

    An ultrasonic sensor is an instrument that measures the distance to an object using ultrasonic sound waves. An ultrasonic sensor uses a transducer to send and receive ultrasonic pulses that relay back information about an object’s proximity. High-frequency sound waves reflect from boundaries to produce distinct echo patterns.

    How Ultrasonic Sensors Work

    Ultrasonic sensors work by sending out a sound wave at a frequency above the range of human hearing. The transducer of the sensor acts as a microphone to receive and send the ultrasonic sound. The sensor determines the distance to a target by measuring time lapses between the sending and receiving of the ultrasonic pulse.

    Source: MaxBotix




    2 - Create a new project

    Go to the https://makecode.microbit.org website, create a new project and add the kitronik-move-motor extension to your project.


    3 - Measure distance

    Let's program the sensor to measure the distance to an object.

    Create a new variable called distance and add the following code to your project. This code will store the distance (in cms) that the sensor is reading into the 'distance' variable and then it will shot the number on the Microbit that's attached to the Move Motor car.

    Download your code onto the Microbit, turn on your Move Motor car and test that the code works by putting an object at different distances from the sensor and seeing the result on the Microbit.


    4 - Follow an object

    Now that we know how far away the object is, let's add some code to move the car so that it is always 10cm away.

    Change your code to the following, download it onto your Microbit and then test that the car moves when you move the object away and then stops when it is 10cm away.


    5 - Reverse

    So far the car will stay any distance under 10cm away from the object. Let's add some code to reverse the car until it is exactly 10cm away.

    Update your code to the following, download it onto your Microbit and test that it works by moving the object back and forth. Your car should move to stay exactly 10cm away from the object.



    Unlock the Full Learning Experience

    Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our Digital Skills Curriculum.

    Copyright Notice
    This lesson is copyright of DigitalSkills.org. Unauthorised use, copying or distribution is not allowed.
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more