| port: |
Grove: A1 (C16, C17) |
| interface: | PWM |
| output values |
2 - 350 cm |
| Further information: | https://webshop.calliope.cc/Calliope-Ultraschallsensor |
| Order: | https://webshop.calliope.cc/Calliope-Ultraschallsensor |
The ultrasonic sensor can be used for the development of an autonomous vehicle among other things. At the Calliope office in Berlin, such a sensor is used to welcome visitors: the sensor monitors the door and as soon as someone moves through the entrance, the Calliope mini controls a small greeting card module which then plays a greeting message.
Connection to the Calliope mini:
The Grove ultrasonic sensor uses only a single digital pin to send the sound pulse and perform the measurement, calculating the distance based on the time difference. Therefore, any digital pin can be used to operate the ultrasonic sensor.
For Grove connectors, A1 (C16) can be used.
Makecode
The easiest way to use the ultrasonic sensor is with the Grove extension. This can be added via Extensions in the menu. After adding the package, the block “Ultrasonic sensor (in cm) at C16” will be available in the “Grove” category.

Python
Add package
In the Python editor, you first need to import the module "Ultrasonic sensor" into your project. To do this, download the following file:
Ultrasonic sensor vertical_align_bottom
In the Python editor, click on the "Projects" tab and then on "Open..." to load a file into your project. Select the file ultraschallsensor.py and add it to your project as an additional file by clicking the small icon in the "Modify file" dialog and selecting "Add file".
The module has now been added, and you can use from Ultraschallsensor import * to measure the distance with the two functions measure_in_cm (in centimeters) and measure_in_inch (in inches).


Coding
The values of the ultrasonic sensor can be stored in the variable sensor_pin via the digital pin to which the sensor is connected. In this example, the ultrasonic sensor is connected to the Grove pin A1 (C16/RX). Using the function measure_in_cm(), the distance can be measured in centimeters. The values can then be displayed on the LED matrix of the Calliope mini:
from calliopemini import *
from Ultraschallsensor import *
import time
sensor_pin = pin_A1_RX # Trigger und Echo am selben Pin (Grove-typisch)
while True:
abstand = measure_in_cm(sensor_pin)
display.show(abstand)
print("Entfernung: {} cm".format(abstand))
time.sleep_ms(100)You can find sensor and actuator projects that have already been realised on the project page.