Exploring Robotics with the motor:bit and BBC micro:bit  – Keeping Your Distance

Exploring Robotics with the motor:bit and BBC micro:bit – Keeping Your Distance

In our initial article we looked briefly at the motor:bit STEM Education Robot for the BBC micro:bit. We explored the capabilities of the motor:bit STEM Education Robot, the different challenges we could take on and the learning one could gain from the robot. In the second tutorial we explored the capability of the motor:bit mainboard and obtained a better understanding of the different capabilities we could build into our robot using the motor:bit mainboard. In the third tutorial we looked at the line sensor module for the motor:bit STEM Education robot, connected it up with the robot and tested out it’s functionality.

In this tutorial we will look at the Ultrasonic Sensor for the motor:bit STEM Education robot, understand the principle behind the Ultrasonic Sensor, connect up the Ultrasonic sensor to our motor:bit STEM Education robot and test out the final product.

About the motor:bit STEM Education Robot – The Motor:bit STEM education robot is a DIY (Do It Yourself) robot based on the highly popular BBC micro:bit. The Motor:bit STEM education robot is designed to get kids (12 and older) introduced to the world of coding, electronics and robotics. The Motor:bit STEM education robot is designed from ground up to be an easy to easy to work with, easy to assemble robot and simply built with the aim of giving educators, parents and kids a great opportunity to get a taste of robotics, electronics and coding.

motor:bit STEM Education Robot for the BBC micro:bit

The Motor:bit is really easy to assemble and can be put together in less than an hour. We would recommend the Motor:bit STEM education robot to kids and adults who are willing to put in some effort to put together their robot and take on a small maker challenge assembling the robot from its different components. So if you are keen to introduce your child to the world of STEM and are keen to get them coding, introduced to the world of robotics using the micro:bit the Motor:bit is for you. Overall the Motor:bit STEM education robot is a great way to get started with the basics of coding and robotics using a flexible, affordable and easy to work with robotic platform.

If you haven’t read the initial article in this series please head over and check out –

  1. Exploring robotics with the motor:bit STEM Education Robot for the BBC micro:bit – Introduction
  2. Exploring robotics with the motor:bit STEM Education Robot for the BBC micro:bit – Diving into the capabilities of the motor:bit main board
  3. Exploring robotics with the motor:bit STEM Education Robot for the BBC micro:bit – Learning to use Line Sensors
  4. Exploring robotics with the motor:bit STEM Education Robot for the BBC micro:bit – Learning to keep distance (Learning to use ultrasonic sensors with the motor:bit) : This tutorial.

If you are interested in purchasing the motor:bit STEM Education Robot for the BBC micro:bit then head over to OzToyLib and grab one now.

Lets learn about the Ultrasonic Module – Before we dive in and setup the line ultrasonic sensor module with the motor:bit STEM Education Robot for the BBC micro:bit let’s dive in and learn a bit more about ultrasonic sensors and how they work.

Ultrasonic sensors measure distance by using ultrasonic waves. The sensor is designed to send out an ultrasonic wave and receive the wave that is reflected back from the obstacle. Ultrasonic Sensors use the bounced back wave to measure the distance to the target (From the point of measurement) by computing the amount of time between the emission and reception. An optical sensor has a transmitter and receiver, whereas an ultrasonic sensor uses a single ultrasonic element for both emission and reception. In a reflective model ultrasonic sensor, a single oscillator emits and receives ultrasonic waves alternately. This enables miniaturization of the sensor head. The distance between the sensor and the obstacle can be calculated with the following formula:

Distance = 1/2 × T (Time) × C (Speed of sound)

where L is the distance, T is the time between the emission and reception, and C is the sonic speed. (The value is multiplied by 1/2 because T is the time for go-and-return distance.). So in summary ultrasonic sensors like many others, use a single transducer to send a pulse and to receive the echo.  The sensor determines the distance to a target by measuring time lapses between the sending and receiving of the ultrasonic pulse.

Working of an ultrasonic sensor

Checkout the video below to understand how the ultrasonic sensors work. The video covers use of a ultrasonic sensor with an Arduino environment which is not in the scope of this article, however the concepts covered in the video are very relevant. The author wonderfully covers off the functionality of the ultrasonic sensor including other important concepts.

Connecting up the line tracking module – In this section we’ll work on connecting the ultrasonic sensor module to the motor:bit mainboard. Once we’ve made the connections we will have given our motor:bit STEM Education Robot for micro:bit the capability to detect obstacles in front it and make decisions to stop or to proceed.

Ultrasonic Sensor on the motor:bit STEM Education Robot

Wire up the Ultrasonic Sensors such that the GVS (Ground / Black – Voltage / Red – Signal / Yellow) is connected up to Pin 10 on the motor:bit main board.See the diagram below.

Ultrasonic sensor connected to Pin 10 on the motor:bit mainboard

Let’s Write Some Code – With the connections now complete it’s time to head over to BBC MakeCode and start writing some code. The aim of this tutorial is to setup the ultrasonic sensor for the motor:bit STEM Education Robot for the BBC micro:bit and test out the ultrasonic sensor to make sure it’s working. In subsequent tutorials we’ll build a full fledged line following robot with obstacle sensing capability but in this tutorial we’ll stick to testing out the ultrasonic sensors and making sure our connections work.

So let’s open up a browser and head over to BBC MakeCode for micro:bit https://makecode.microbit.org and load up the programming interface. Once you have MakeCode open head over to the “Advanced” section. We’ll now add the “motor:bit” module from the Advanced options on the BBC Makecode interface. See image below for details –

adding the motorbit library within makecode

Let’s now add the following package “motor:bit” as shown below. You will have to search for the package “motor:bit” within the Advanced option which then imports the relevant libraries into your program.

Now that we’ve added the “motor:bit” module we are good to go. You can now start putting together the remaining code that will let us test out the line sensor capability on the motor:bit STEM Education Robot for the BBC micro:bit.

  1. Insert a move forward with speed block within the On Start block, and set its parameter to 80, which means the car moves forward at the speed of 80 once powered on.
  2. The unit of ultrasonic wave is centimeter(cm). We will read the value of P10 and assign its return value to a variable.
  3. If the return value is above 5 but under 10, set the speed of motors to 0 and stop the car. This will make sure that we don’t collide with obstacles in front of us.
  4. If the return value is under 5, set the motor speed to 80 with movement in reverse. This will prevent an immediate collision.
  5. If none of these values meet, set the motor speed to 80 and let the robot move forward.This ensures we keep moving forward when there are no obstacles in our path.

Testing things out – To test things out you can place the motor:bit STEM Education robot in any open space with obstacles in front of it. Switch on the motor:bit main board and the robot should start moving forward. When an obstacle is detected the motor:bit STEM Education robot will come to a stop and if the object is too close then it will move in the reverse direction. In subsequent tutorials we’ll build a line tracking robot which plays music and also navigates around obstacles.

Conclusion – If you’ve followed through each of the tutorials in this series you would have by now introduced yourself to the basics of robotics. You would have learned about the motor:bit main board used to build the motor:bit STEM Education robot, learned about line sensors, learned about ultrasonic sensors and most importantly managed to build the robot and code it to move around.

For more tutorials please do check out the development track at KidzCanCode.com for detailed tutorials on the motor:bit STEM Education Robot for the BBC micro:bit. If you are looking to purchase the motor:bit STEM Education Robot head over to the store at <OzToyLib> and check it out.

About BBC micro:bit – The Micro Bit (also referred to as BBC Micro Bit, is an ARM-based embedded system designed by the BBC for use in computer education in the UK. The board is 4 cm × 5 cm and has an ARM Cortex-M0 processor, accelerometer and magnetometer sensors, Bluetooth and USB connectivity, a display consisting of 25 LEDs, two programmable buttons, and can be powered by either USB or an external battery pack.

BBC micro:bit

The device inputs and outputs are through five ring connectors that are part of the 23-pin edge connector at the bottom of the board. The micro:bit can be programmed using the Microsoft Block code program editor which is similar to the block based language Scratch ideal for 7-12 year olds. The micro:bit can also be programmed using the Makecode editor in Javascript and Python which allows for older kids to learn the Javascript and Python programming language using the micro:bit.

Explore our FREE coding, electronics and robotics resources for the BBC micro:bit at www.KidzCanCode.com – <Link>. Hopefully you have enjoyed the post. If you have any questions, comments or suggestions for future tutorials drop us a note at – learning at hack2 dot live.

FREE STEM learning at KidzCanCode – At KidzCanCode.com we offer FREE access to various STEM (Science, Engineering, Technology, Math) development courses at KidzCanCode.com. At KidzCanCode.com you will find courses on Scratch, BBC Micro:Bit, Raspberry Pi, Arduino, 3D modelling, Robotics and Electronics.

If you are looking for a BBC micro:bit, Arduino, Raspberry Pi, starter kits, electronics kits, robotics kits including other STEM learning kits we would recommend you drop by our online store here – <OzToyLib>.

Leave a Reply

avatar
  Subscribe  
Notify of
!!! We Can Help You With Your Coding - Electronics - Robotics learning journey. Call us now (0423607688) !!!Shop Now
×

Cart