Users Manual

CLASS 4
122
Now, try to use the ultrasonic sensor to recognize the situation. The closer the distance of the ultrasonic sensor,
the smaller the analog value. It can detect obstacles by using the ultrasonic sensor connected to the servo motor.
I will measure the value three times after letting the steering wheel turn to the left and the ultrasonic sensor
connected to the servomotor can recognize the situation at the left 45degree angle. With these three measured
values, it can averagely measure obstacles more precisely how far from the ultrasonic sensor the obstacle is. After
that, you do the same thing by turning the steering wheel to the right.
Here, the measurement of the sensor is called sampling. It is called a filter to find the most accurate value by
averaging the sampled values. Above, the ultrasonic sensor samples the value and determines the filter value with
the sampled value.
Now let's add a script that recognizes the situation using the ultrasonic sensor in the 'Monitor_process' script. If
the value of the ultrasonic sensor is smaller than the predetermined value of the ultrasonic sensor, '1' is stored in
the 'is_Detect_obstacle' variable. After the ultrasonic sensor has sampled 3 times after setting the servo motor to
the left, the servo motor is set to the right, we need to let the sensor determine the filter value after sampling 3
times.
It can then compare the filter value on the left with the filter value on the right to determine which obstacle is
on either side. If neither the infrared sensor nor the ultrasonic sensor is recognized, it should keep going straight,
right? Make the scripts described so far in your way!
Use ultrasonic sensor to judge after recognizing the situation
Activities