Files
micromelon-website/content/resources/ultrasonic-sensor.mdx
Tim Hadwen 1f8c46597b Site audit: fix broken images, add activity metadata, clean up content
- Remove broken image references from 25 MDX files (deleted spacer/content images)
- Add codingSkills and roverConcepts frontmatter to 24 activity pages
- Fix "Activity Demonstration" headings in 15 activity files (plain text -> h3)
- Remove unused "All" category from 89 MDX files
- Decode HTML entities (> <  ) in 9 content files
- Escape bare < > characters in MDX to fix build errors
- Standardize contact email to contact@micromelon.com.au
- Add missing description to rover-repair-request metadata
- Include previous session work: about-us updates, difficulty filtering,
  LearningPathway component, expanded schools list, new product/resource images

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 21:49:15 +10:00

109 lines
5.5 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "The Ultrasonic Sensor"
date: "2021-07-21"
categories: ["Sensor Guides"]
tags: []
excerpt: "Learn all about the ultrasonic sensor!"
featuredImage: "/images/resources/ultrasonic-sensor.png"
---
![](/images/content/d9e944-the-ultrasonic-sensor.png)
The ultrasonic sensor is one of the fives types of sensors on the Micromelon rover.
**What Is It Used For?**
The ultrasonic sensor is used to detect the distance to the closest object in front of the sensor. The sensor is placed on the front of the rover, so we can detect if any obstacles (like walls) are in front of the rover, and how far away they are.
### **How The Ultrasonic Sensor Works**
To detect objects, the ultrasonic sensor uses sound. Ultrasonic sound is defined as sound waves at a frequencies higher than 20kHz. How does it detect objects by using sound? Simply by following the steps below.
**Ultrasonic Distance Sensing**
- The sensor makes the high pitched sound.
- The sound waves travel outwards from the sensor towards objects or surfaces in front.
- The sound waves hit and reflect off the object or surface back towards the sensor.
- The sound waves travel back towards the sensor.
- The sensor detects the returning sound waves.
**Based on how long it took the sound to bounce back, the sensor calculates how far away the object is using the speed of sound.**
**The Parts That Make It Work** The sensor is made up of two different components,** the transmitter** and ** the receiver**. These are called transducers. The transmitter is making the ultrasonic sound and the receiver is listening for the reflected sound waves. Some ultrasonic sensors use a single transducer as both the transmitter and receiver.
![](/images/content/aaa95f-sensor-detector.png)
**Why Cant Humans Hear The Sound?**
Ultrasonic sensors typically use frequencies between 30kHz and 500kHz. In the case of the Micromelon Rover, the sensor uses approximately 40kHz. In general, humans can only hear sounds up to 20 kHz.
Wanna know something cool though? If you take a video of the ultrasonic sensor when it is running, the cameras microphone will hear it. We can hear it playing back in the video. An example of this is on the right. Hear the ticking sound when the sensor is pointed at the microphone?
**Ultrasonic Sensors Exist in Nature!**
Echo location is another name for ultrasonic sensing. Bats and dolphins are just two examples of animals who use ultrasonic sensing to detect where they are going and where to find food.
![](/images/content/624068-micromelon-dolphin.png)
Finley (above) works in Micromelon marketing
Finley (pictured) uses ultrasonic sensing to detect where pods of fish are in the sea when on lunch break. Unfortunately when I start yelling at lunch trying to find food, people get annoyed with me.
### **Ultrasonic Problems & Limitations**
**Sound Waves Reflected Away Or Absorbed**
![](/images/content/b91e97-incorrect-bounce-animation.gif)
When the emitted sound waves dont reflect back to our sensor we wont be able to get an accurate reading. This will happen when trying to detect angled or curved surfaces. Soft or textured surfaces can absorb the sound waves and reduce the range of the sensor.
To ensure you are able to get consistent readings, make sure the ultrasonic is pointed at flat, hard surfaces. A wide variety of surfaces will still be detected, but may be unreliable.
**Rover Ultrasonic Range Is Limited To Approximately 1m**
The further the sound waves need to travel, the quiter the echo becomes. If the echo becomes too quiet, the robot can no longer hear it and cant detect the object. In order for the sensor to detect more and more distant objects, the Rover needs to emit a louder sound, which requires more power.
### Programming The Ultrasonic Sensor
To write some code that uses the ultrasonic sensor, open the Micromelon Code Editor and connect Rover. You can use sensor view to see what the ultrasonic sensor is detecting. To open sensor view, click the ROVER button next to your Rovers name.
In the sensor view dialog, the ultrasonic value is located at the top of the rover diagram. The CM next to the value indicates centimetres. Point the ultrasonic sensor at different objects and watch this value to measure how far away they are.
**What does 255cm mean?**
255 is the returned value when the sensor is unable to detect an object. If you are seeing 255 it means you may be attempting to detect objects further away than 1m or because the sound waves are being absorbed or reflected away from the sensor.
![](/images/content/f16a1c-opening-sensor-view.gif)
![](/images/content/bd5aa7-using-sensor-mode-small-small.gif)
**Using The Ultrasonic In Code**
Lets write a simple program to print our ultrasonic sensor value every second.
![](/images/content/1e6d33-example-code.gif)
- Start by adding a **Print** statement. You can find this block in the ** Utilities** category.
- Place our ultrasonic sensor read inside the print statement.
You can find the **Read Ultrasonic** block in the ** Sensors** category. The Python command is ** Ultrasonic.Read()**.
- Wrap this Print statement in a **While True Loop**.
- Add a **Delay For 1 Second** block so this loop waits 1 second before running again.
- Press Play!
While this is running we will see our ultrasonic value every second.
- You can now write other code that makes decisions based on the ultrasonic sensor.
### Wrapping Up
Now that were familiar with what the ultrasonic is, how it works, and how to program with it, its time to start doing some activities that use the ultrasonic sensor.