19. Case 10 Smart Crashproof Car

19.1. Purpose

  • Make a smart crashproof car with a Sonar:bit.

19.2. Materials

  • 1 x Ring:bit Car kit

  • 1 x micro:bit

  • 1 x Sonar:bit

19.3. Hardware Connection

  • Connect the left servo to P1, right servo to P2 and Sonar:bit to P0 of the Ring:bit.


19.5. Software

Step 1

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


  • We need to add a package for programming the kit. Click “Extensions” in the drawer and search “ringbit” in the dialogue box to download it.


  • We also need to add a package for programming the Sonar:bit. Click “Extensions” in the drawer and search “https://github.com/elecfreaks/pxt-sonarbit” in the dialogue box to download it.

Note: if you are informed that it will be deleted due to incompatibility of the codebase, you can go on with the tips or create a new project in the menu.

Step 2

  • Drag the pins selection bricks for servos in the On start brick, the pins numbers are set according to the actual connection port.

  • Move forward at full speed.


Step 3

  • Set variate sonar in the forever brick and read the detected value from the Sonar:bit to it.

  • Drag the if brick and judge if the value given by sonar is below 10 and not equal to 0.

  • If yes, set the speed of right wheel to 100 and the left to 0 to turn left with 500ms for obstacle avoidance.

  • If not, move forward at full speed.



Links: https://makecode.microbit.org/_RTwFcMeA1MMY

You can also download it below:

--- ## Result --- - The Ring:bit car turns left automatically when detecting any obstacle 10cm in front of it.

19.6. Exploration

  • Question: Why we need to judge if the value is not 0 ?

  • Answer: The detection value is also 0 if beyond the detection scope of Sonar:bit.

19.7. FAQ