# How to use the Ultrasonic Sensor with the Catapult built from EV3/NXT (Part 5) ProPreview

This video lesson shows a very interesting specific example on how to use the LEGO Mindstorms EV3 Ultrasonic Sensor. The sensor detects if the catapult is loaded or if we have just fired an element. At the end of the lesson I also offer an interesting challenge that you could use in your classroom or at home.

• #69
• 01 Feb 2015
• 7:52

### Ultrasonic Sensor

The sensor detects distance in centimeters or in inches. When the catapult is loaded the distance between the sensor and the base of the robot is about 7-9 centimeters (~3 inches).

It is more interesting however that after adding the sensor we should balance the nest holding the brick. Many novice robot builders make the mistake of adding parts, sensors and motors only on one side of the robot without thinking about how to balance it.

### The challenge

The challenge from this video is.

How to calculate the speed at which the nest falls? (Using those calculations in some of the next video lessons we would calculate the speed of the parts fired from the catapult). Use the knowledge from:

### Catapult build from LEGO Mindstorms EV3/NXT (Part 1)

Building instructions for EV3 Mindstorms Catapult Robot with Ultrasonic Sensor are given below

### Catapult Frame - LEGO Mindstorms construction for a frame of a catapult

This frame holds the motor and ev3 brick used in the catapult. The frame is placed on top of the rotating base and thus could be easily rotated. The brick could be both NXT and EV3

### Catapult Rotating Base - LEGO Mindstorms construction for a base for a catapult

This is the initial construction of a catapult. The base on which we will place the rest of the robot. The goal of this construction is to give the catapult the ability to rotate.

### Catapult Full - Full catapult from LEGO Mindstorms with a Motor and a Touch Sensor

These are building instruction for a working automatic catapult with a motor and a touch sensor.

### Catapult Full - Full catapult from LEGO Mindstorms with a Motor and ultrasonic sensor

The catapult robot could use the ultrasonic sensor to stop loading at a certain height

Use the ultrasonic sensor to measure the speed of falling objects. Use the task in your classroom, for your team or at home to engage students in learning.

There is 1 task from a middle complexity giving 2 points.

#### Tasks description, submission and evaluation are available to subscribed users.

Subscribe now to acces the full capacity and get feedback.

### English

In the previous episode of the series on how you can construct your own catapult we finished with a robot that can load and fire small Lego parts completely automatically. A very interesting gear system with a clutch transfers the power for loading the catapult from the EV3 motor to the axle. The main challenge was to find out when the motor should stop. In the previous episode we used a touch sensor to detect this. In this episode I would like to introduce you to the ultrasonic sensor and to how we can stop loading the robot using this sensor.

The ultrasonic sensor detects distance. We can use this sensor to detect whether we have just loaded the catapult and we have just fired or we should load it. For example, if we attach the sensor on this side of the nest of the catapult, and if we detect a distance of 4 - 5 cm or about 1 - 1.5 inch, we can say that we have just fired an element. Now, I will load the catapult. And during loading, we can see that if we detect a distance of, let's say,10 cm (we would check this with the software), we can say that the catapult is loaded and we are ready to fire. Now, what you should pay attention to is that without the sensor the nest is balanced. But when we attach the sensor to one side of the nest,

the center of mass changes and the nest is not balanced anymore. So, we should find a way to balance the nest. A solution would be to move the brick a little to the right. Now, I will remove the brick from the nest and move it one step to the right. Now the construction is much more balanced. Let's check the numbers with the software. Now, let's check the exact numbers using the EV3 software. As you can see, the ultrasonic sensor is attached to the nest and currently, it returns a value of about 4 cm. Here. If I now load the catapult, the value will increase. The catapult is loaded and we can see that the value of the ultrasonic sensor is about 7.8 cm. We can use these values to program our robot, so we'll start the motor and we'll turn the motor until we reach a value of more than 7 cm. This will be our threshold for knowing that we have just loaded the catapult. Now, the program for the robot goes like this. First, we need to start the medium motor. And we start with with a power of 50 but for an unlimited amount of time. It's connected to port D. The second step is to wait until the catapult is loaded. So, we are going to wait. And we are waiting for the ultrasonic sensor to detect a distance. We need distance in cm and we need distance that's more than 7 cm.

Let me just check. Yes, it's connected to port 4.

Then we stop loading the catapult. The medium motor just stops. And the catapult is loaded. Now, the question is how we know when we have just fired an element and we should load it again. We know that we have fired an element, when the sensor detects a distance of less than 5 cm. This means that we've just fired, the nest is down and we can now load again. Let me just zoom this.

And again we wait -

wait for the ultrasonic sensor to detect a distance of less than, let's say, 4 cm. Or even 5 cm.