58. Case 57: An Unmanned Bus#

58.1. Introduction#

Now, with the maturity of artificial intelligence and driverless technology, driverless buses are beginning to appear, and the fares are lower. Therefore, in this class, we will make an unmanned bus work to experience the riding mode of unmanned bus and the convenience of future transportation.

../../_images/57_1.jpg

Materials Required#

Nezha expansion board × 1

micro:bit V2 × 1

Crash sensor× 1

Ultrasonic sensor × 1

RJ11 cable × 1

Bricks × n

Note: If you want all of the above components, you may purchase the Nezha 48 IN 1 Inventor’s Kit.

Assembly Steps#

Component Details

../../_images/57_2.jpg

Build it as the assembly steps suggest:

../../_images/57_3.jpg

../../_images/57_4.jpg

../../_images/57_5.jpg

../../_images/57_6.jpg

../../_images/57_7.jpg

../../_images/57_8.jpg

../../_images/57_9.jpg

../../_images/57_10.jpg

../../_images/57_11.jpg

../../_images/57_12.jpg

../../_images/57_13.jpg

../../_images/57_14.jpg

../../_images/57_15.jpg

../../_images/57_16.jpg

../../_images/57_17.jpg

../../_images/57_18.jpg

../../_images/57_19.jpg

../../_images/57_20.jpg

../../_images/57_21.jpg

../../_images/57_22.jpg

../../_images/57_23.jpg

../../_images/57_24.jpg

../../_images/57_25.jpg

../../_images/57_26.jpg

../../_images/57_27.jpg

../../_images/57_28.jpg

58.2. Connection Diagram#

Connect the four motors to the M1, M4, the crash sensor to J1 port, the Ultrasonic sensor to J2 port.

../../_images/57_29.jpg

58.3. MakeCode Programming#

Step 1#

Click “Advanced” in the MakeCode drawer to see more choices.

../../_images/49_10.png

For programming the servo, we need to add a package. Click “Extensions” at the bottom of the drawer and search with “nezha” to download it.

../../_images/49_11.png

For programming the PIR sensor, we need to add a package. Search with “PlanetX” in the dialogue box and click to download it.

../../_images/49_12.png

Notice: If you met a tip indicating that some codebases would be deleted due to incompatibility, you may continue as the tips say or create a new project in the menu.

Reference#

The program is shown in the figure below:

../../_images/57_30.jpg

Link: https://makecode.microbit.org/_Cz7hETb9V9pL

You may also download it directly:

Result#

We can see that when the bus encounters a bus stop it will stop and wait for passengers to get on, and after passengers get on the bus and press the crash sensor the bus will leave again.