Users Manual
SCRATCH CODING KIT
In the 'check_Ultrasonic' script that we created on the previous page, let's create a 'Detect_Ultrasonic' script that
was broadcast to determine the ultrasound sensor value at the end. This script is very simple. This is because the
filter value of the ultrasonic sensor is compared with the filter value of the ultrasonic sensor in the left direction and
the filter value of the ultrasonic sensor is measured in the right direction. Please create the script below.
If it receives a broadcast called 'Detect_Ultrasonic', broadcast 'Move_BB' and wait for 2 seconds. Then compare
the values of 'Ultrasonic_R_value' and 'Ultrasonic_L_value'. If the value of 'Ultrasonic_R_value' is larger, the filter
value of the ultrasonic sensor on the right side is larger than that of the ultrasonic sensor on the left side, so it can
be judged that the obstacle is closer to the left side. So, the car should go to the right, so we have to broadcast
the 'Move_FR' script.
Conversely, if the value of 'Ultrasonic_L_value' is larger, the filter value of the ultrasonic sensor on the left side is
larger than the filter value of the ultrasonic sensor on the right side, so it can be judged that the obstacle is closer
to the right side. So, it has to go to the left side of the car, so it can broadcast the 'Move_FL' script.
After the judgment is finished, it should broadcast 'Detect_Clear' script and make 'is_Detect_obstacle'
variable '0' so that it can recognize the obstacle again.
Activities
Operation after judgment using ultrasonic sensor