4. Lesson 4¶
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|
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
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¶
1）Assemble the other servo with three M2.5*5mm screws, and install the pan-tilt-zoom mount plate.
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.
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)
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
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
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.
4.7.1. Exercise 1¶
Line tracking can be referred to lesson 2
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.
4.7.3. Exercise 3¶
The remote only needs to send the "B1" text.
220.127.116.11. 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.