3.29 Car Backing Radar

3.29.1 Overview

When a car is in reverse, it will alarm the distance of the obstacles behind the parking space. In this project, we build a mini car backing radar with an ultrasonic sensor for distance detection, a speaker to alarm, and a traffic light module as an indicator.

3.29.2 Test Code

3.29.2.1 Code Flow

6-29-2-1

3.29.2.2 Build Code

There are two ways to upload the code: directly open the code file we provide; or manually build blocks.

Directly open the code file we provide:

  1. Click and choose Load from your computer

  1. We have already downloaded the codes on computer desktop, so open the file and choose 3-29-parkingSensor.sb3

Manually build blocks:

  1. Build the two basic blocks:

6-1-4-1-1

  1. Declare a variable named distance

  2. Assign the detected value of the ultrasonic sensor to distance

    QQ_1721810318114

  3. Add a j25 to determine the distance. If distance > 40, code blocks in it will be executed: the speaker stays quiet, the red LED is off while the green one is ON.

    QQ_1721868975906

  4. Add another j25. If distance < 40, code blocks in it will be executed: the speaker alarms, the red LED is ON while the green one is off.

    QQ_1721870782466

Complete Test Code

6-29-2-2-3

3.29.2.3 Test Result

After uploading code, when the the detected distance value is greater than 40cm, the green LED is on and the amplifier does not emit sound. If the value is less than 40cm, the red LED will light up and the amplifier will alarm.