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 this tutorial we will look at the line sensor module for the motor:bit STEM Education robot, connect it up with the robot and test out it’s functionality.
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.
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 –
- Exploring robotics with the motor:bit STEM Education Robot for the BBC micro:bit – Introduction
- Exploring robotics with the motor:bit STEM Education Robot for the BBC micro:bit – Diving into the capabilities of the motor:bit main board
- Exploring robotics with the motor:bit STEM Education Robot for the BBC micro:bit – Learning to use Line Sensors (This article)
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 Line Tracking Module – Before we dive in and setup the line tracking module with the motor:bit STEM Education Robot for the BBC micro:bit let’s dive in and learn a bit more about line tracking sensors and how they work.
A line tracking module is a type of an infrared sensor module, which consists of two infrared sensor components i.e. an infrared receiver and an infrared transmitter. The line following sensor has the same working principle as any other infrared obstacle avoidance sensor module, but the only difference is that it has low transmitting power. This line tacking module is built to be able to detect a black line on a white background and a white line on a black background. The line tracking sensors is designed to provide a more stable and accurate output. These type of sensors are easy to use and easily obtained from most electronic stores. Line tracking sensors are widely used to design robots that need to navigate lines (White or Black).
Checkout the video below to understand how line sensors work. The video covers use of a line sensor with an Arduino board which is not in the scope of this article, however the concepts covered at the start of the video are very relevant. The author wonderfully covers off the functionality of the line sensor including other important concepts.
Very simply speaking the line sensor consists of two different infrared modules like the ones below. One is meant to function as an infrared transmitter and the other as an infrared receiver. These signals bounce off the track i.e. white line on a black background or a black line on a white background.
Connecting up the line tracking module – Infrared line sensors are the most basic line detection sensors and will only work when you have a contrasting setup in place i.e. black line on a white background or a white line on a black background. Let’s now connect up the line sensor module to the motor:bit mainboard. In this section we’ll work on connecting the line 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 navigate around a track by sensing a line underneath it.
Connect up the left sensor (S1) on line tracking module to the P4 or Pin 4 on the motor:bit. Connect up the right sensor (S2) on the line tracking module to the Pin 3 on the motor:bit.See the diagram below.
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 line sensor for the motor:bit STEM Education Robot for the BBC micro:bit and test out the line sensor to make sure it’s working. In subsequent tutorials we’ll build a full fledged line following robot but in this tutorial we’ll stick to testing out the line 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 –
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.
- Let’s add a
move forward with speedblock below
on start. Set the speed parameter to 80, which means the car will move forward at the speed of 80 after it has been powered on.
- Let’s also now create two variables:
right. These variables will be used to measure the values of the left or right sensor. We will set their initial value to 1.
- Within the forever block, let’s read values from digital pin P3 and P4, which correspond to the left or right sensor on line tracking module.
- Value read from the left sensor is assigned to
leftvariable and value read from the right sensor to the
- We the evaluate if the
rightvariable is 0, which means one of the two sensors has detected black line.
rightis 0, set the motor speed to 0 and stop the car.
Testing things out – To test things out you will need a small area with a white (any light color should work) background with a black line (using black tape) on top. The black line on a white background is more easy to setup since black electrical tape is very easily available at the hardware stores. If you do not have one at home you should be able to get hold of one from the hardware store for 1-2$.
Once you have the tape, create a line on a flat surface (e.g. floor, etc.) that is 10 cm long, place the robot on the line and power it on. You should find that as long as the line sensors detect the line the motors will remain powered on and the robot will power ahead. As soon as the robot veers off the line and the line sensors do not detect the line the motors will turn off bringing the robot to a halt. For this to work your tape has to be really dark in color (preferably black) and the surface you are sticking the line on preferably white.
Conclusion – So with this experiment you’ve now introduced yourself to the very basics of robotics. You’ve learned about line sensors, you’ve learned how to write code and get the robot to move around and also how to stop the robot if it were to swerve off the line.
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.
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>.