4. Lesson 4

../_images/4_111.png

4.1. Introduction

Welcome to Micro:bit Smart Car tutorial! In this course, we will explore Micro:bit and learn how to develop Micro:bit Smart Car by programming.

4.2. Learning Target

Let students clearly understand Micro:bit Smart Car’s extension tools and its functions, moreover, understanding its install and block coding method.

After successfully getting the load up and unload in Lesson 3, you can start experimenting with the loader!

You can try it out from other living shapes, sizes and weights.

You can also see how the machine encounter problem when servo angle value is too big or too small, and think what solutions can couple with.

Servo angle value Problem
Too big
Too small

4.3. Exercise 1

Program the car to complete the task.

1) Put the car at the beginning of the black line (starting point)

2) The car follows the line with unload state

3) After reaching the end point (outside the black line), the car stops and load up the target object

../_images/4_211.png

Tip: The object needs to be placed at the correct distance, and the moving speed of the car (motor) needs to be adjusted properly, so that the object can be more easily load up

4.4. To install the ultrasonic sensor

../_images/4_310.png

1)Assemble the other servo with three M2.5*5mm screws, and install the pan-tilt-zoom mount plate.

../_images/4_42.png

2)Put the ultrasonic sensor into the universal expansion mounting plate, and use two M3*5mm screws to attach the universal expansion mounting plate to the pan-tilt-zoom mounting plate.

../_images/4_51.png

3)Use two screws, two screw pads and two copper pillars to mount the loader together with the ultrasonic sensor to the car/expansion board. (Pay attention to the direction of the pan-tilt-zoom mounting plate)

../_images/4_62.png

Finished diagram:

../_images/4_72.png

4.5. Exercise 2

Automatic Sensor (Ultrasonic)

Use ultrasound to detect whether there is something that can be carried in front of the car, and then use a loader load up the goods.

After loaded up, the car stopped.

(If it is not detected, the car will continue to move forward until it encounters an obstacle).

Tip: Ultrasonic distance required for a loader to successfully pick up an item is shorter than mechanical beetle

../_images/4_81.png

4.6. Exercise 3

Combining the ultrasonic and line tracking sensors and the remote control, design program that can change the action mode of the car instantly through the remote control, realize the two ultrasonic detection functions of obstacle avoidance and control the shovel at one time, and complete the tasks:

1) The car follows the black line. When the ultrasonic wave detects an obstacle, the car avoids it (just move horizontally)

2) Use the remote control (B1) button to change the action mode of the car (the ultrasonic obstacle avoidance function is changed to control the action of the loader)

3) When the ultrasonic wave detects the object, the car stops and load up the object

Tip:

The variable "mode" records the car's action mode (the text blocks "avoid" and "load" represent obstacle avoidance and loader modes)

The behavior of the car is different, and the ultrasonic detection of the object will react differently.

../_images/4_92.png

4.7. Answer

4.7.1. Exercise 1

Line tracking can be referred to lesson 2

../_images/4_102.png

4.7.2. Exercise 2

When the ultrasonic reading distance is greater than 4, unload and move the car forward.

When the ultrasonic reading distance is less than or equal to 4, load up and stop the car.

../_images/4_112.png

4.7.3. Exercise 3

The remote only needs to send the "B1" text.

../_images/4_121.png ../_images/4_132.png

4.7.3.1. The program of the car

The default car variable mode is "avoid", and when the text "B1" is received, the mode is set to "load".

When the ultrasonic wave cannot detect the object, the car will follow the line and move forward, and turn right to return to the line when it goes out of bounds.

When the ultrasonic detects an object and the mode is "avoid", the car moves horizontally to avoid obstacles.

(The time to move left is longer than that to the right, to avoid the car turning right before returning to the line, causing the direction to be reversed)Otherwise, the ultrasonic detects the object and the mode is "load", the car stops and unload the object.

../_images/4_142.png