0% found this document useful (0 votes)
97 views185 pages

KS0426 Microbit Mini Smart Robot Car V2

..

Uploaded by

TAENGKASEM K.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views185 pages

KS0426 Microbit Mini Smart Robot Car V2

..

Uploaded by

TAENGKASEM K.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 185

Micro:bit Mini Smart Robot Car V2

Content

1. Description.............................................................................................................. 1
2. Specifications.......................................................................................................... 2
3. Packing List............................................................................................................. 2
4. Robot Installation................................................................................................... 1
5. micro:bit Driver Installation................................................................................. 1
6. micro:bit Example Use.......................................................................................... 8
Step 1: Connect It.................................................................................................. 8
Step 2: Program It..................................................................................................9
Step 3: Download It............................................................................................. 11
Step 4: Play It....................................................................................................... 12
7. micro:bit Pins........................................................................................................ 14
8. Get Knowledge of Micro:bit Shield Elements
Playing Music......................................................................................................... 21
Micro:bit LED Matrix Display...............................................................................24
RGB Light Cycle.................................................................................................... 27
RGB Light Test...................................................................................................... 36
Light Sensing......................................................................................................... 46
Motor Driving........................................................................................................ 49
9.Line Tracking Robot
Testing the tracking sensor.................................................................................55
How to Build a Line Tracking Robot?................................................................ 59
10.Ultrasonic Following Robot
Ultrasonic Ranging............................................................................................... 64
How to Build an Ultrasonic Following Robot?.................................................. 71
11. Obstacle Avoiding and Following Robot
Infrared Avoiding Obstacles............................................................................... 76
How to Build an Obstacle Avoiding Robot?......................................................82
How to Build an Object Following Robot?........................................................ 86
Infrared Remote Control..................................................................................... 91
How to Build an Infrared Remote Control Robot?........................................106
11. Bluetooth Controlling Robot
Android Bluetooth Controlling Robot.............................................................. 111
IOS Bluetooth Wireless Programming and Control...................................... 126
How to Build IOS Bluetooth Control Robot....................................................143
12. Related Resources Link.................................................................................. 159
1. Description

Here comes a mini STEM education DIY robot platform based on Micro:bit programming.
Micro: bit is an ARM structure microcontroller designed by BBC. It is only half size of a credit card, onboard comes
with Bluetooth, accelerometer, compass, three buttons, 5x5 LED matrix, mainly used for teens programming
education.
The Micro:bit Mini Smart Robot Car V2 integrates ultrasonic and infrared obstacle avoidance, line following as well
as infrared and Bluetooth control functions.
It comes with a passive buzzer for playing music; a KEYES-2812-18R module for controlling 18 RGB LED colors; a
photocell for detecting the light intensity; two RGB lights used as direction light.
Moreover, the micro:bit car supports charging by 18650 batteries when run out of power. It is available to adjust the
motor speed.
This micro:bit robot is a perfect toy for kids to start learning robotics. The plug-and-play allow children to quickly
learn graphic programming in entertaining, nurturing children's interest in science and logical thinking.

1
2. Specifications

1) Voltage: DC 5V
2) Current: USB power supply or power supply with a capacity greater than or equal to 1A
3) Maximum power: maximum output power is 10W
4) Operating temperature range: 0-50 degrees Celsius
5) Dimensions: 120*90.7mm
6) Environmental attributes: ROHS

3. Packing List

Note: the Micro:bit main board is Not Included!

2
No. Item Quantity Image

Micro:bit robot bottom shield


1 V2 1
(Black and Eco-friendly)

Acrylic pack of 3 pieces


2 1
T=3MM

3
3 HC-SR04 ultrasonic sensor 1

KEYES-2812-18R Module
4 (welded with yellow curved 1
pin)

N20 motor wheel


diameter:43mm ; width:
5 19mm ; 2
hole diameter: 3mm type D
ABS plastic + rubber yellow

steel universal wheel


6 1
W22*H15MM

4
7 M1.6*10MM round head screw 8

8 M3*6MM round head screw 8

9 M1.6 304 stainless steel nut 8

Double pass M3*35MM hex


10 4
copper pillar

11 M3*10MM flat-head screw 1

12 M3 Nickel plated nut 1

5
13 M2*12MM round head screw 8

14 M2 Nickel plated nut 6

yellow-black handle 3*40MM


1
15 phillips screwdriver

USB Cable
16 A/MICRO OD: 4.0 black 1
L=1.2m eco-friendly

Male to female jumper wire


17 3
10CM random color

Male to female jumper wire


18 4
15CM random color

6
4. Robot Installation

Firstly prepare all the assembly components before install the micro:bit robot.

a. Next let’s begin to install the wheel on Micro:bit bottom shield.


Prepare well universal wheel, two yellow wheels, 4pcs M3*6MM round-head screws and 4pcs dual-pass
M3*35MM hex copper pillars.

1
b. To begin with, should use two screws of universal wheel to mount the wheel on the bottom shield.

2
The front and back view are shown as below picture:

3
After that, install two yellow wheels into the shield’s motor.

c. Mount the 4pcs M3*6MM round-head screws and 4pcs dual-pass M3*35MM hex copper pillars onto the bottom
shield.

4
5
d. Well, ready to install the electronic elements:
 Two Acrylic plates

 Ultrasonic module

 KEYES-2812-18R module

 Micro:bit main board

 6pcs M1.6*10MM round-head screws

 6pcs M1.6 304 stainless steel nuts

 4pcs M3*6MM round-head screws

 1pcs M3*10MM flat-head screw

 1pcs M3 nickel plating nut

 F-M Jumper wires

6
At first fix the KEYES-2812-18R module on the Acrylic plate with 2pcs M1.6*10MM round-head screws and 2pcs M1.6

304 stainless steel nuts.

7
8
Then mount the HC-SR04 ultrasonic module on the Acrylic plate with 4pcs M1.6*10MM round-head screws and 4pcs

M1.6 304 stainless steel nuts.

9
Installed well, fix the two Acrylic plates together with 1pcs M3*10MM flat-head screw and 1pcs M3 nickel plating nut

10
11
e. Finally you should get the parts below:

12
13
Hookup Guide:

Connect the KEYES-2812-18Rmodule and HC-SR04 ultrasonic module to the bottom shield with F-M jumper wires.

KEYES-2812-18R module Micro:bit shield

G G

V V

DI D5

HC-SR04 ultrasonic module Micro:bit shield

GND G

Echo D15

Trig D14

VCC 5V

14
15
The final step is to mount the Acrylic plates on the 4pcs dual-pass M3*35MM hex copper pillars of micro:bit bottom

shield with 4pcs M3*6MM round-head screws.

16
Insert the micro:bit main board into bottom shield. Congrats! The fantastic micro:bit robot is installed well.

17
5. micro:bit Driver Installation
Next, let’s install the driver for micro:bit main board.
1) First of all, connect the micro:bit to your computer using a USB cable.

2) Then, double click the driver software to install it. Here you can click the driver icon to download.

1
2
3) After that, click Next to continue the installation.

3
4) Wait the driver installing finished.

4
5) Completing the driver installation.

5
6) Driver installation completed, then you can right click the “Computer” —> “Properties”—> “Device Manager”.

6
You can check the detailed Ports information shown as below.

7
6. micro:bit Example Use

Step 1: Connect It

Connect the micro:bit to your computer via a micro USB cable.


Your micro:bit will show up on your computer as a drive called 'micro:bit'.

8
Step 2: Program It

Use micro:bit MakeCode Block editor https://makecode.micro:bit.org/ to write your first micro:bit code.
You can drag and drop some example blocks and try your program on the Blocks Editor. Shown below.

9
Click the JavaScript, you can see the corresponding program code. Shown as below figure.

10
Step 3: Download It

Click the Download button in the editor. This will download a 'hex' file, which is a compact format of your program
that your micro:bit can read.
Here you can name the project as LED1, then click “Save”. Shown below.

11
Once the hex file has downloaded, copy it to your micro:bit just like copying a file to a USB drive.
On Windows you can right click the downloaded file and choose "Send To→micro:bit."

Step 4: Play It

The micro:bit will pause and the yellow 5*5 LED on the back of the micro:bit will display the images while your code is
programmed.

12
You can power it using USB cable or battery. The battery holder should connect two 1.5V AA batteries.

13
7. micro:bit Pins

Before getting started with the following projects, first need to figure out each pin of micro:bit main board.

The BBC micro:bit has 25 external connections on the edge connector of the board, which we refer to as ‘pins’.
The edge connector is the gray area on the right side of the figure below.
There are five large pins, that are also connected to holes in the board labeled: 0, 1, 2, 3V, and GND.
And along the same edge, there are 20 small pins that you can use when plugging the BBC micro:bit into an
edge connector.

Please refer to the reference diagram shown below.

14
15
More reference you can click the link below:

BBC micro bit Pins: http://micro:bit.org/guide/hardware/pins/

BBC micro:bit website: http://micro:bit.org/

Micro bit MakeCode Block Editor: https://makecode.micro:bit.org/

Meet micro:bit starter programming: http://micro:bit.org/guide/

BBC micro:bit Features Guide: http://micro:bit.org/guide/features/

BBC micro:bit Safety Warnings: http://micro:bit.org/guide/features/

BBC micro:bit Quick Start Guide: http://micro:bit.org/guide/quick/

16
17
18
Get Started
with
Micro:bit
Robot
Projects
19
Get
Knowledge
of Micro:bit
Shield
Elements

20
Playing Music

Description
Buzzers can be categorized as active and passive ones.
The difference between the two is that an active buzzer has a built-in oscillating source, so it will generate a
sound when electrified.
A passive buzzer does not have such a source, so DC signal cannot drive it beep.
Instead, you need to use square waves whose frequency is between 2K and 5K to drive it.
Different frequencies produce different sounds.
You can use micro:bit to code the melody of a song, quite fun and simple.

The keyestudio Micro:bit robot shield comes with a passive buzzer element. The signal terminal of buzzer is
connected to the P0 interface of micro:bit main board.
In the experiment, we make use of the software built-in library to drive the passive buzzer play a song of Happy

21
Birthday.

22
Source Code

What will you see


Send well the test code to micro:bit main board, then insert the
micro:bit main board into the micro:bit robot shield.
Connect a 18650 battery to the shield, and turn the POWER and
BUZZER switch ON.
You should hear the micro:bit robot shield playing a song of
《Happy Birthday》

23
Micro:bit LED Matrix Display

Description
LED stands for Light Emitting Diode. The micro:bit has 25
individually-programmable LEDs, allowing you to display text,
numbers, and images.
The micro:bit MakeCode Block editor has built-in library. So
you can use it to control the 25 LED lights on and off, showing
the different images.
In the experiment, we drive the 25 LED lights show a big
heart and a small heart images.

24
Source Code

25
What will you see
Send well the test code to micro:bit main board, powered on, the
micro:bit 25 LED lights show a big heart for one second, then
show a small heart image for one second, repeatedly.

26
RGB Light Cycle

Description
The KEYES-2812-18R module comes with 18 WS2812 LED
lights and a yellow pin header, fully compatible with
micro:bit main board.
In this circuit, we are going to control 18 WS2812 LEDs
displaying different status by using control pin P5 on
micro:bit main board.

27
Source Code
Note: before setting the test code, you need to add the libraries. Follow the instructions below:
Open the micro:bit Software MakeCode editor https://makecode.micro:bit.org/ Click to add New Project, then
you will see the interface below:

28
Then click Advanced, find the Extensions to add file.

29
Search “neopixel”, then add the library file.

30
31
Library added well, you should see the Neopixel on the Blocks interface.

32
Test code 1:

You can drag the code file to the MicrosoftMakeCode window.

33
What will you see
Send well the test code to micro:bit main
board, then insert the micro:bit main board
into the micro:bit robot shield. Connect a
18650 battery to the shield, and turn the
POWER switch ON.
You should see the 18 RGB LEDs on the
KEYES-2812-18R module are all turned on,
changing with seven colors separately and
circularly.

Note: here we have only introduced the use


method of test code 1. But we provide the
source code of 1-4 in the folder. The use

34
method is almost the same. You are able to open the program on the micro:bit makecode environment or directly
send to micro:bit main board.
If upload the test code 2, 18 RGB LEDs flash with colorful light, turning a round and then off.
If upload the test code 3, 18 RGB LEDs turn circle, one circle of one color, always cycle;
If upload the test code 4, one LED turns circle, and each light is in a random color.

35
RGB Light Test

Description
There are two RGB lights on the robot shield. You will learn how to make

the two RGB lights as indicator for the micro:bit robot. To save the IO port

resources, we will use a PCA9685PW chip to drive the two RGB lights.

In the circuit, Pin LED 4 of PCA9685PW chip is used to control the blue

light of RGB; pin LED 5 controls the green light, while pin LED 6 controls

the red light.

In this lesson, you will learn how to drive the two RGB LEDs circularly light

up the red, green and blue light colors. Another one is to show different

color of light.

36
Source Code
Note: before setting the test code, you need to add the libraries. Follow the instructions below:
Open the micro:bit Software MakeCode editor https://makecode.micro:bit.org/ Click to add “New Project”, then
you will see the interface below:

37
Then click Advanced, find the Extensions to add file.

38
Enter https://github.com/jdarling/pxt-pca9685 and search.

39
Then you will get the pca9685 below:

40
Click the pca9685 to download the extension:

41
Finally you should see the PCA9685 project is added successfully.

42
Test code 1:

43
Test code 2:

44
What will you see
Send well the test code 1 to micro:bit main
board, then insert the micro:bit main board
into the micro:bit robot shield. Connect a
18650 battery to the shield, and turn the
POWER switch ON.
The two RGB LEDs on the robot shield flash in
three colors, red, green and blue.

With the same method, upload the test code 2,


the 2 RGB LEDs on the robot shield will
gradually change with different colors.

45
Light Sensing

Description
The micro:bit robot shield comes with a photocell sensor element controlled by P1 interface.

Photo resistor (Photovaristor) is a resistor whose resistance varies with

different incident light strength.

In the project, we will use the photocell sensor to detect the ambient

light intensity, controlling the color brightness of 18 WS2812 LEDs on

the KEYES-2812-18R module.

The darker the ambient light, the brighter the 18 LEDs.

46
Source Code
Note: here involves KEYES-2812-18R RGB module. Before setting the test code, you need to add the libraries.
Follow the instructions mentioned above (RGB Light Cycle)

47
What will you see
Send well the test code to micro:bit main board,
then insert the micro:bit main board into the
micro:bit robot shield. Connect a 18650 battery
to the shield, and turn the POWER switch ON.
The 18 WS2812 LEDs are turned on.
The darker the light intensity, the brighter the
white light.

48
Motor Driving

Description
The micro:bit robot shield has built-in PCA9685PW and TB6612FNG
chips. To save the IO port resources, we can control the TB6612FNG
chip through PCA9685PW chip; then control the moving direction and
speed of two DC motors by TB6612FNG chip.

Pin LED1 and LED2 of PCA9685PW chip are separately used to


control the direction and speed of the left motor;
Pin LED3 and LED4 separately control the direction and speed of the
right motor.

In the code, LED1 and LED3 are setting the moving direction.

49
When the front number are set to 0, motor turns forward; set to 100, motor turns reverse.

In the code, LED2 and LED4 are setting the motor’s speed, in the range of 0-100.
The greater the value, the faster the speed.

Below table is the running status settings of Micro:bit robot:

50
control control control control
Car direction of speed of Left direction of speed of Right
state left motor left motor motor right motor right motor motor
(LED1) (LED2) (LED3) (LED4)

Turn Turn
Forward 0 100 forward 0 100 forward

Turn Turn
Backward 100 50 backward 100 50 backward

Stop 0 0 Stop 0 0 Stop

Turn Turn
Left 0 50 forward 0 100 forward

Turn Turn
Right 0 100 forward 0 50 forward
51
Source Code
Note: here need to drive PCA9685PW chip. Before setting the test
code, you need to add the libraries.
Follow the instructions mentioned above (RGB Light Test)

52
What will you see
Send well the test code to micro:bit main board, then insert the micro:bit main board into the robot shield, and
connect a 18650 battery. Turn the POWER switch ON.
The micro:bit robot will go forward for 2 seconds, backward for 2 seconds, stop for 1 seconds, turn left for 1

second and turn right for 1 second, circularly and repeatedly.

53
Line
Tracking
Robot

54
Testing the tracking sensor

Description
The micro:bit robot shield comes with two line tracking sensor elements. Also comes with two potentiometers
used for adjusting the sensitivity of sensor.
The tracking sensor is actually an infrared sensor. The component used here is the TCRT5000 infrared tube.
Its working principle is to use the different reflectivity of infrared light to the color, then convert the strength of
the reflected signal into a current signal.
During the process of detection, black is active at HIGH level, but white is active at LOW level.

The two line tracking sensors are controlled by P12 and P13 of micro:bit main board.
The left tracking sensor is controlled by P12; the right one is controlled by P13.
Place a white paper in the robot bottom; adjust the potentiometer (RP1; RP2);
Once the D2 and D6 led indicator turn on, the sensitivity is adjusted well.

55
56
Source Code

57
What will you see
Send the test code to micro:bit main board, then insert the
micro:bit main board into the robot shield; connect a 18650
battery; then turn the POWER switch ON.

When the left tracking sensor detects an obstacle, the


micro:bit LED matrix will showⅠat the left side;
When the right tracking sensor detects an obstacle, the
micro:bit LED matrix will showⅠat the right side;
When both tracking sensors detect an obstacle, the
micro:bit LED matrix will show a big heart image;
When both tracking sensors do not detect an obstacle, the
micro:bit LED matrix will show a small heart;

58
How to Build a Line Tracking Robot?

Overview
In the previous projects, we have introduced the principle and application of line tracking sensor and motor
driving. We’re now ready to give the Micro:bit robot an upgraded capability - Line tracking!

What is line tracking?


Line tracking is exactly what it sounds like - following the track. The robot can always stay on its black track.

How does it work?


It uses the tracking sensor to detect the black track on the pavement, and detection signal will feed back to the
micro:bit main board. Then micro:bit main board will analyze and judge the collected signals to control and drive
the motor in time, thus can adjust the robot turning direction.

59
That is why the micro:bit car can automatically follow the black track, achieving the automatic line tracking
function.

Programming Thinking
1 Set the KEYES-2812-18R module to turn on 18 RGB LEDs in various colors.
2 Judge white and black line by both side line tracking sensors.
3 If right side tracking sensor detects black line, robot turns right; if left side tracking sensor detects black
line, turn left; if both side sensors don’t detect black line, stop; if both side sensors detect black line, go forward.

Source Code

60
61
What will you see
Send the test code to micro:bit main board, then insert the micro:bit main
board into the car shield; connect a 18650 battery, and turn the POWER
switch ON.
The micro:bit robot will move forward along the black track.

Note:
1) The width of black track should be greater than the distance between
the two tracking sensors.
2) Do not test the robot in the sun. If appear problems during the test
process, try testing the robot in a rather dark environment.

62
Ultrasonic
Following
Robot

63
Ultrasonic Ranging

Description
There is an animal called bat in nature. The bats can fly at night, not depend on its eyes, but on its ears and

vocal organs. When the bat flies, it will emit a scream, an ultrasonic signal that humans cannot hear because of

its high audio frequency. If these ultrasonic signals hit other objects on the flight path, they will be reflected back

immediately. After receive the returned information, the bats complete the whole process of listening, seeing,

calculating and bypassing obstacles during the flutter.

The principle of the ultrasonic module is as the same as the above


principle.
The ultrasonic module will emit the ultrasonic waves after trigger
signal. When the ultrasonic waves encounter the object and are

64
reflected back, the ultrasonic module outputs an echo signal, so it can determine the distance of object from the
time difference between trigger signal and echo signal.
Ultrasonic sensor has a wide range of sensitivity, no blind area, and no interference with obstacles.
As the following picture shown, it is our keyestudio ultrasonic module. It has two something like eyes.
One is transmitting end, the other is receiving end.

TECH SPECS:
 Operating Voltage: 5V(DC)
 Operating Current: 15mA
 Operating Frequency: 40khz
 Maximum Detection Distance: 3-5m
 Minimum Detection Distance: 3-4cm
 Sensing Angle: less than 15 degrees

65
66
When using it:
(1) Use IO trigger ranging, at least 10us HIGH level
signal; that is, first pull the Trip Low, then give a
HIGH level signal of 10us.

(2) The module automatically sends eight square


waves of 40khz to automatically detect whether
there is a signal return back;

(3) There is a signal return, through the IO output a


High level, and the duration period of High level is
the time of Ultrasonic wave from emission to return.

Test distance = (High level time * speed of sound (340M/S))/2;


Then you can get the formula: detection distance = (High level time/58) (cm);

67
Source Code:

68
What will you see
Send the test code to micro:bit main board, then insert the micro:bit main board into the robot shield and
connect a 18650 battery; turn the POWER switch ON.
When the measured distance between an obstacle and ultrasonic module is less than 10cm, the passive buzzer
on micro:bit shield will beep up.

Note:
Open the Arduino IDE, select the proper board and COM port; then open serial monitor and set the baud rate to
115200, the measured distance value will print out on the monitor window.
Here you can click the link below to get more use details of Arduino IDE.
https://wiki.keyestudio.com/Ks0001_keyestudio_UNO_R3_BOARD

69
70
How to Build an Ultrasonic Following Robot?

Overview
In the previous project, we have introduced how to build an obstacle following robot.
This project we use an ultrasonic module combined with micro:bit robot shield to build an ultrasonic obstacle
following robot.

How does it work?


The principle is very simple. We will use an ultrasonic module to measure the distance between the micro:bit
robot and an obstacle ahead. Then control the running state of micro:bit robot car according to the measured
distance.

Programming Thinking

71
1 Set the KEYES-2812-18R module to turn on 18 RGB LEDs in various colors. When micro:bit robot moves
forward, 18 RGB LEDs turn on blue light; robot moves backward, 18 RGB LEDs turn on purple light; robot stops,
18 RGB LEDs turn on red light.
2 Measure the distance between the robot and obstacles using an ultrasonic sensor.
3 When the measured distance is greater than or equal to 10cm, the micro:bit robot moves forward; if
less than or equal to 6cm, robot will move backward; if greater than 6cm but less than 10cm, or greater than
30cm, robot will stop.

Source Code

72
73
What will you see
Send the test code to micro:bit main board,
then insert the micro:bit main board into the
robot shield and connect a 18650 battery;
Turn the POWER switch ON.
The 18 RGB LEDs on the KEYES-2812-18R
module will emit different colors.
The micro:bit robot will follow along the front
object.
Note that the object can only move in front of
the robot, can’t turn around.

74
Obstacle
Avoiding
And
Following
Robot

75
Infrared Avoiding Obstacles

Overview
The micro:bit robot shield comes with two infrared obstacle avoidance sensors. It is actually designed for
infrared obstacle avoidance robot.
The infrared obstacle detector sensor has a pair of infrared transmitting and receiving tubes.
The transmitter emits an infrared rays of a certain frequency. When the detection direction encounters an
obstacle (reflecting surface), the infrared rays are reflected back, and receiving tube will receive it.
At this time, the indicator (SIG1/SIG2 LED) lights up. After processed by the circuit, the signal output terminal
will output Digital signal.
You can rotate the potentiometer on the shield to adjust the detection distance. It is better to adjust the
potentiometer to make the SIG1/SIG2 LED in a state between on and off. The detection distance is the best,
almost 10cm.

76
77
Programming Thinking

1 Set the control pin of left infrared obstacle avoiding sensor to P2; the right one set to P11.
2 Measure the HIGH/LOW level of both sensors’ control end. Obstacle detected, signal end LOW; no
obstacle, signal end HIGH.
3 Judge whether there is obstacles according to the level feedback of sensor’s signal end; make the
micro:bit LED matrix show the patterns.

Source Code

78
79
What will you see
Send the source code to micro:bit main board, then insert the micro:bit main board into the robot shield and
connect a 18650 battery; turn the POWER switch ON.
The two infrared obstacle detector sensors on the micro:bit robot shield can detect an obstacle ahead.
 If both infrared sensors do not detect obstacles, the LED matrix will show an upward arrow.
 If both infrared sensors detect obstacles, the LED matrix will show a smile face.
 If the left infrared sensor detects an obstacle but right one doesn’t, the LED matrix will show a leftward
arrow.
 If the right infrared sensor detects an obstacle but left one doesn’t, the LED matrix will show a rightward
arrow.

80
81
How to Build an Obstacle Avoiding Robot?

Overview
This project you will learn how to combine an ultrasonic module, infrared obstacle sensor and micro:bit robot
shield to build an ultrasonic obstacle avoiding robot.

How does it work?


The principle is very simple. We will use an ultrasonic module to measure the distance between the micro:bit
robot and an obstacle ahead. Then detect the left and right side obstacles using infrared obstacle sensors;
control the running state of micro:bit robot according to the measured result.

Programming Thinking

1 Set the KEYES-2812-18R module to turn on 18 RGB LEDs in various colors. When micro:bit robot moves

82
forward, 18 RGB LEDs turn on blue light; robot moves backward, 18 RGB LEDs turn on red light; turn left, 18 RGB
LEDs turn on purple light; turn right, 18 RGB LEDs turn on yellow light.
2 Measure the distance between the robot and obstacles using an ultrasonic sensor.
3 When the measured distance is greater than 10cm, make use of infrared sensors to detect obstacle at both
sides:
If no detecting obstacles at both sides, robot moves forward; if obstacles are at right side but not left side, robots
turn left; if obstacles are at left side but not right side, robots turn right; if both sides have obstacles, robot will go
back for 0.1 second then turn left.
4 When the measured distance is less than or equal to 10cm, make use of infrared sensors to detect obstacle
at both sides:
If no detecting obstacles at both sides, robot turns left; if obstacles are at right side but not left side, robot turns
left; if obstacles are at left side but not right side, robot turns right; if both sides have obstacles, robot will go back
for 0.1 second then turn left.

83
Source Code

84
What will you see
Send the test code to micro:bit main
board, then insert the micro:bit main
board into the robot shield and
connect a 18650 battery;
Turn the POWER switch ON.
The micro:bit robot is ready to avoid
an obstacle ahead to move freely.

85
How to Build an Object Following Robot?

Overview
In the previous project, we have built an ultrasonic following robot combined with ultrasonic module and robot
bottom shield. But the robot can’t turn around, only follow in a straight line.
We’re now ready to give the Micro:bit robot another upgraded capability - Object Following!
Combine ultrasonic module, infrared detector sensor and robot shield to build an obstacle following robot that
can turn around.

How does it work?


The principle is very simple. We will use an ultrasonic module to measure the distance between the micro:bit
robot and an obstacle ahead. Then detect the left and right side obstacles using infrared obstacle sensors;
control the running state of micro:bit robot according to the measured result.

86
Programming Thinking
1 Set the KEYES-2812-18R module to turn on 18 RGB LEDs in various colors.
When micro:bit robot moves forward, 18 RGB LEDs turn on blue light;
robot moves backward, 18 RGB LEDs turn on purple light; turn left, 18 RGB LEDs turn on green light;
turn right, 18 RGB LEDs turn on yellow light; robot stops, 18 RGB LEDs turn on red light.
2 Measure the distance between the robot and obstacles ahead by an ultrasonic sensor. Use 2 infrared
detector sensors to detect the obstacles on both sides of micro:bit robot.
3 When the measured distance is greater than 3cm but less than or equal to 6cm, no obstacles at both sides,
micro:bit robot stops. If less than or equal to 3cm, obstacles detected at both sides, robot moves backward;
If greater than 6cm, no obstacles detected at both sides, robot moves forward;
If greater than 3cm, obstacles are at right side but not left side, robot turns right;
If greater than 3cm, obstacles are at left side but not right side, robot turns left;
If greater than 6cm, obstacles detected at both sides, robot moves backward;
for other status, robot stops.

87
Source Code

88
What will you see

Send the test code to micro:bit


main board, then insert the
micro:bit main board into the
robot shield and connect a 18650
battery;
Turn the POWER switch ON.
The micro:bit robot will follow
the front object straight or turn
around.

89
Infrared
Control
Robot

90
Infrared Remote Control

Overview

IR Remote Control Decoding:

There is no doubt that infrared remote control is commonly seen in our daily life. It's hard to
imagine our world without it.
An infrared remote control can be used to control a wide range of home appliances such as
television, audio, video recorders and satellite signal receivers.

Well, in the following let’s get a better understanding of the infrared remote control.
Infrared remote control is composed of infrared transmitting and infrared receiving systems.

91
That is, consist of an infrared remote control, an infrared receiver module and a microcontroller that can decode.
You can refer to the figure below.

The 38K infrared carrier signal transmitted by an infrared remote controller is encoded by an encoding chip
inside the remote controller. It is composed of a pilot code, user code, data code, and data inversion code.
The time interval between pulses is used to distinguish whether it is a signal 0 or 1. (when the ratio of high level
to low level is about 1:1, considered as signal 0.) And the encoding is just well composed of signal 0 and 1.

The user code of the same button on remote controller is unchanged. Using difference data distinguish the key

92
pressed on the remote control.
When press down a button on the remote control, it will send out an infrared carrier signal. And when infrared
receiver receives that signal, its program will decode the carrier signal, and through different data codes, thus
can judge which key is pressed.
The microcontroller is decoded by an received signal 0 or 1 to determine which key is pressed by the remote
control.

Infrared Receiving:
The robot shield comes with infrared receiver module. It is mainly composed of an infrared receiving head. This
device integrates with reception, amplification and demodulation.
Its internal IC has been demodulated, outputting Digital signal. Suitable for IR remote control and infrared data
transmission.

Specification Parameters:

93
1) Operating Voltage: 3.3-5V(DC)
2) Output Signal: Digital signal
3) Receiving Angle: 90 degrees
4) Frequency: 38khz
5) Receiving Distance: 18m

94
Source Code
Note: before setting the test code, you need to add the libraries. Follow the instructions below:
Open the micro:bit Software MakeCode editor https://makecode.micro:bit.org/ Click to add “New Project”, then
you will see the interface below:

95
Then click Advanced, find the Extensions to add file.

96
Enter https://github.com/jhlucky/maqueen and search.

97
Then you will get the maqueen file below:

98
Click the maqueen file to download the extension:

99
Finally you should see the maqueen project is added successfully.

100
Code:

101
Test Result:

Send the test code to micro:bit main board, then insert the micro:bit main board into the robot shield and
connect a 18650 battery; turn the POWER switch ON.
Aimed at the infrared receiver head, press the button on the infrared remote controller, the serial monitor will
show the corresponding key value.

Note:
Open the Arduino IDE, select the proper board and COM port; then open serial monitor and set the baud rate to
115200, the measured distance value will print out on the monitor window.
Here you can click the link below to get more use details of Arduino IDE.
https://wiki.keyestudio.com/Ks0001_keyestudio_UNO_R3_BOARD

102
103
104
We have listed out the key value of infrared remote control. See the figure below:

105
How to Build an Infrared Remote Control Robot?

Overview
How to built an infrared remote control robot? Think about it.

We can build a line tracking robot combined with tracking sensor and robot shield in the above project.

So in this circuit, you can combine an infrared remote control and robot shield to build an infrared remote control

robot.

The principle is indeed simple. Send the button signal by infrared remote control; robot shield’s infrared receiver

module receives the button signal to control the moving status of robot.

106
Source Code

107
Test Result:

Send the test code to micro:bit main board, then


insert the micro:bit main board into the robot
shield and connect a 18650 battery;
Turn the POWER switch ON.
Aimed at the infrared receiver head, press the
button on the infrared remote controller, it can
control the micro:bit robot go front, back, turn
right or turn left and stop.

Note: during the test, the infrared remote


control shall be directly facing the infrared
receiver head on the robot shield.
The distance shall not exceed 18 meters.

108
Key on IR remote control Robot status

Move forward

Move backward

Turn left

Turn right

stop

109
Bluetooth
Control
Robot

110
Android Bluetooth Controlling Robot

Overview:
The micro:bit main board comes with Bluetooth module. Communicate built-in Bluetooth module with your
mobile phone; then use Bluetooth APP to control the external devices connected to micro:bit main board.
The built-in Bluetooth module can support both Android and IOS system. But the use method is different.
In this project, you will learn how to connect the Bluetooth module in Android system so as to drive the robot
move.

111
Adding Code libraries:
Note: before setting the test code, you need to add the libraries. Follow the instructions below:
Connect the micro:bit main board to your computer using a USB cable.

Open the micro:bit Software MakeCode editor https://makecode.micro:bit.org/


Click to add “New Project”, then you will see the interface below:

112
113
Then click Advanced, find the Extensions to add file.

114
Then click the Bluetooth.

115
Select Remove extensions and add Bluetooth.

116
Finally, you should see the Bluetooth is added well.

117
Then click the Extensions again, enter the library link below and search:

https://github.com/LaboratoryForPlayfulComputation/pxt-BlockyTalkyBLE-UART

118
Finally, you should see the library blocky Talky BLE is added successfully.

119
Source Code:

Right click the source code to send to micro:bit main board.

120
Using Bluetooth APP:

Send the above source code to the micro:bit main board; then power on the micro:bit main board
Click the link to download the Bluetooth APP:

https://drive.google.com/open?id=1u_wXlpuRjcChpCcVPcIha4yWYWhefhW2

Installed well the Bluetooth APP, click the icon to open the APP.

Once your phone detects Bluetooth module on micro:bit main board, the APP will

prompt to open the Bluetooth. Choose to open the Bluetooth.

Pop up the interface below:

121
No connecting the Bluetooth APP, Micro:bit main board will show a smile face on the LED matrix.

Then click the Bluetooth icon , it will pop up the micro:bit Bluetooth interface.

122
Then click to connect the micro:bit Bluetooth.
Bluetooth connected, you will see the LED matrix on the Micro:bit main board showing a heart image.

123
Icon Function

Bluetooth

Disconnect Bluetooth

Connect Bluetooth

Button control

Long press to operate; release to stop;


Arrow for controlling the robot’s moving direction.

Voice control
Speak “go、back、left、right、stop” towards your Android phone
to control the robot status.

Gravity sensing control system


Check out the angle value of your phone on the APP

124
Test Result:
Send well the test code to micro:bit main
board; insert the micro:bit main board into
robot shield; turn power switch on.
Follow the method mentioned above,
connect the Bluetooth on the micro:bit main
board using Bluetooth APP.
Bluetooth connected, click the icons on the
APP to randomly control the micro:bit robot
running.

125
IOS Bluetooth Wireless Programming and Control

This section will introduce how to use wireless programming and control in IOS devices (ipad/iPhone).

Use Method is follows:

Step 1: Open the App store on your ipad/iPhone.

Step 2: Search the micro:bit to download and install.

126
127
Pay close attention to:
Connect your micro:bit main board to PC; Open the micro:bit Software MakeCode editor
https://makecode.micro:bit.org/, click the icon , select the Project Settings and no pairing required.

128
129
Step 3: open the micro:bit interface, click Choose micro:bit.

130
Then click Pair a micro:bit, and click Next.

131
Step 4: power on the micro:bit main board, HOLD the A and B buttons, then press and release RESET button.
The micro:bit main board will enter the Bluetooth pairing mode.
You should see an image showing on the LED matrix.

132
Step 5: copy the pattern from your micro:bit device and tap Next.

133
Continue to tap Next to pair.

134
OK, pairing successful!

135
Step 6: now go to control robot; press the reset button on the micro:bit main board; then tap Create Code on
the micro:bit APP.

136
Step 7: open the Microsoft MakeCode for micro:bit, click the icon , select to open the Project Settings.

137
Then you will see the interface below. Close the option2 (JustWorks pairing...) and open option1(No Pairing

Required...)

138
Step 8: write the code

139
Wrote well, click the triangle icon at the bottom left to change the name; then click to save the code.

140
Step 9: go to the Flash interface, click the blue bar to flash code to micro:bit. Wait the process complete.

141
OK. Flashing successful!

142
How to Build IOS Bluetooth Control Robot

In the previous section, you have learned the knowledge of IOS Bluetooth wireless programming and control.
Now let’s move on to build an IOS Bluetooth control robot. The method is almost the same.
We have packaged all the source code. So you can drag the code file to micro:bit makecode window to check out.
Or Right click the code file to send to micro:bit main board.

143
Source Code:

144
Use Method is follows:

Step 1: Right click the source code to send to micro:bit


main board.
Step 2: Open the App store on your ipad/iPhone.
Search the micro:bit to download and install.

145
Pay close attention to:
Connect your micro:bit main board to PC; Open the micro:bit Software MakeCode editor
https://makecode.micro:bit.org/, click the icon , select the Project Settings and no pairing required.

146
147
Step 3: open the micro:bit interface, click Choose micro:bit.

148
Then click Pair a micro:bit, and click Next.

149
Step 4: power on the micro:bit main board, HOLD the A and B buttons, then press and release RESET button.
The micro:bit main board will enter the Bluetooth pairing mode.
You should see an image showing on the LED matrix.

150
Step 5: copy the pattern from your micro:bit device and tap Next.

151
Continue to tap Next to pair.

152
OK, pairing successful!

153
Step 6: now go to control the robot; press the reset button on the micro:bit main board; then tap Monitor and
Control on the micro:bit APP.

154
Step 7: Tap the Add and then select the Gamepad.

155
And you should see the control interface shown below. Click Start to connect.

156
Connection successful! Click Stop to disconnect.

157
Test Result

Press key A, robot goes front; Press the

key B, go back; Press key C, turn left;

Press key D, turn right;

Press Stop to disconnect the Bluetooth,

robot will stop.

Press key 1, robot stops; Press key 2,

robot stops to turn left 180° and then

stop to go forward;

Press key 3, robot will turn left circle;

press key 4, turn right circle.

158
Related Resources Link

You can download all the information needed from the link below:
https://drive.google.com/open?id=1vxESHAOWctadONe-8mImSPYi-JEEGE9g
Download the micro:bit driver:
https://drive.google.com/open?id=18g1tebO73kpHDqohhP2WWjmrWO7MvvrZ
Download the Bluetooth APP:
https://drive.google.com/open?id=1u_wXlpuRjcChpCcVPcIha4yWYWhefhW2
Download the User Guide:
https://drive.google.com/open?id=1NESb2BdathiVVst6NxrqaOW4PrFYmQNk
Download all the source code:
https://drive.google.com/open?id=1qR3848mxxGU6VxxUKncL0UGYEdawzlP6

159

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy