Ultrasonic Sensor

The ultrasonic sensor uses sound waves beyond the human hearing range to sense solid objects.

Its functinality is similar to biological echolocation in bats and certain marine mammals.

How the Sensor Works

An ultrasonic sensor has a transmitter and a receiver. Sometimes it looks like eyes, which can be confusing.

Testing the Sensor

Let's test our Ultrasonic sensor - find and plug the sensor into the hub:

Once connected, look at the Sensor reading displayed at the top of your coding area:

Mount the sensor on your 2-Wheel robot and test the measurement as the robot nears a wall/obstacle.

Programming Tips

We will be programming some robot behaviors that depend on the Ultrasonic sensor. You can use the condition boolean for Ultrasonic sensor:

When you program algorithms you need to account for unpredictable outcomes - the environment of operation could change, an object might move into your path, etc.

So we usually do not use MOVEMENT blocks with pre-defined distances.

For instance, in our last challenge we may have used:

But now we will also need to use unspecific blocks like:

THis block tells the robot to start moving straight until further notice...

We will also need to account for variability in the programs, so we will need to use blocks that wait for some trigger:

(you might wish to use conditionals like If/Else but with the following challenges, those are not really necessary)

When a program requires you to repeat the same behavior over and over, you can use the Forever block: