# get ultrasonic () distance (cm)

## Description

The block returns the distance reading from the specified ultrasonic sensor.

## Example

### Ultrasonic Sensor with Quarky

The example demonstrates how to use an ultrasonic sensor with Quarky.

#### Connections

Now we will connect the Ultrasonic Sensor to the Robot. The sensor and the robot have the following pins:

1. Ultrasonic Sensor Pins:
1.  VCC
2. GND
3. Trig
4. Echo
2. Quarky Pins:
1. GND
2. V
3. D1
4. D2

We will start with connecting the ultrasonic sensor with Quarky using the 4 set wire provided in the kit. But, first, make the connection in the following way:

• First, connect the VCC of the ultrasonic sensor with the V pin on the Quarky.
• Connect the GND of the ultrasonic sensor with the Ground pin on the Quarky.
• Connect Trig of the ultrasonic sensor with D1 pin on the Quarky.
• Finally, connect the Echo of the ultrasonic sensor with the D2 pin on the Quarky.

### Learn How to Make a Quadruped Robot Detect and React to a Hand

This example teaches you how to use an ultrasonic sensor to make a quadruped robot detect and move toward a hand. We provide two examples of code to help you get started.

The project demonstrates how to make the Quadruped detect the hand in front of it and move according.

#### Type 1 - Forward Backward

The logic is simple. If the distance measured from the ultrasonic sensor is less the robot will move toward the hand. Else the robot will lean backward.

#### Type 2 - Upside Down

If the distance measured from the ultrasonic sensor is less the robot will face upwards towards the hand. Else the robot will look downward.

### Quadruped Obstacle Avoidance Project with Ultrasonic Sensor

Use the Quadruped that can detect and avoid obstacles using an ultrasonic sensor. The robot will draw an LED display to show its movement, and it will make a U-turn if it can’t move forward.

This project of obstacle avoidance is for a robot that will move around and look for obstacles. It uses an ultrasonic sensor to measure the distance. If the distance is less than 20 cm, it will stop and look in both directions to see if it can move forward. If it can, it will turn left or right. If not, it will make a U-turn. The robot will also light up an LED display to show where it is going.

#### Logic

This code is making a robot move around and explore its surroundings. It has an ultrasonic sensor that can measure the distance between objects.

1. First, it checks if the distance measured by the sensor is less than 20 cm.
2. If it is, it draws a stop sign pattern on the LED display and makes the robot stop and look straight. Then it looks left and checks if the distance is greater than 40 cm. If it is, it draws a left arrow pattern on the LED display and makes the robot turn left.
3. If not, it looks right and checks if the distance is greater than 40 cm. If it is, it draws a right arrow pattern on the LED display and makes the robot turn right.
4. If not, it draws a U arrow pattern on the LED display and makes the robot make a U-turn.
5. If the distance measured by the ultrasonic sensor is not less than 20 cm, the code will make the robot move forward.

#### Code

Upload the code to Quarky and test it.