Users Manual
CLASS 3
102
Now you're going to try coding for an ultrasonic sensor. The line tracer must stop when it encounters obstacles
along the black line, which is very simple. When the distance of the object approaches the ultrasonic sensor, you
can create a script that stops the two DC motors. It will be very simple.
If you create a script like the one above, the line tracer will work, and if it recognizes the obstacle through the
ultrasonic sensor, it stops working. Very simple, isn’t it?
So what if the line tracer is completely out of the black line? Unless both infrared sensors are on the black line.
When coding, you have to consider a lot of situations. Because unexpected things can happen. If the infrared
sensors are not all on the black line, the line tracer will have to stop. It should not continue to work.
If so, what criteria should you code for when you are not on this line? Here, we'll try to learn about timers. Click
the Observation tab in the Scratch palette
If you check 'Timer' on the Observation tab, you can see that time continues to flow on the stage screen. 'Timer'
is literally a stopwatch inside the scratch. How do you code using this 'timer'?
Commentary
Coding the Line Tracer Ultrasonic sensor