Table of Contents

get ultrasonic () distance (cm)

Description

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

Example

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.

Script

Output

Read More
Explore the surroundings with our obstacle avoidance Mars Rover that uses an ultrasonic sensor to detect and avoid obstacles. Learn how the robot moves, detects obstacles, and navigates its way through them.

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.

Logic

  1. This code is making a robot move around and explore its surroundings. It has an ultrasonic sensor that can measure the distance between objects.
  2. We will first initialize the servos of the Mars Rover with the block “Set head pins()”.
  3. Then we will make all the servos rotate to 90 degrees if they are not initialized.
  4. Thereafter we will initialize the ultrasonic sensors and define the minimum and maximum distance variables.
  5. The main logic of the code is that it first checks whether the distance is less than the minimum distance. If it is, the head servo will move to 45 degrees and check again if the distance is greater than the maximum distance, hence moving in the right direction.
  6. The robot with the help of the head servo, will check the distance for the conditions 90 degrees, 45 degrees, 135 degrees, 0 degrees and 180 degrees in the same order as stated.
  7. Whenever the distance measured will be less than minimum distance the head servo will change the direction to the next set of degree to check distance.
  8. In the last case scenario where all the angles contain obstacles as such, in that case the robot will change its direction to reverse by rotating to 180 degrees. By this way the robot will be able to navigate its own way through each and every obstacles.

Code:

Main Functions:

 

Final Main Logic:

Output

 

Read More
Discover how the Quadruped robot can detect and respond to the presence of a hand in its environment.

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.

Code


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.

Code


Read More
Explore the functionality of our obstacle avoidance robot equipped with an ultrasonic sensor. Discover how it intelligently detects obstacles.

Intorduction

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.

Output

Read More
All articles loaded
No more articles to load