Ultrasonic sensor
sensoricon
port: Grove: A1 (C16, C17)
interface: PWM
output values

2 - 350 cm

Further information: http://wiki.seeedstudio.com/Grove-Ultrasonic_Ranger
Order: https://www.conrad.de/de/p/seeed-studio-101020010-ultraschall-entfernungsmesser-1369546.html

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:

Der Grove Ultraschallsensor nutzt nur einen digitalen Pin für die Sendung der Schallimpulses und der Messung und berechnet aus dem zeitlichen Differenz die Entfernung. Deshalb kann jeder digitale Pin verwendet werden, um den Ultraschallsensor zu verwenden.
Im Falle der Grove-Anschlüsse kann A1 (C16) verwendet werden.

Makecode

To see the current value of the ultrasonic sensor on the LED display, you can use the "show number 0" block from the "Basics" category. To recognize the ultrasonic sensor, the respective value of the pin on which the sensor sends the data must be queried. With the ultrasonic sensor, the measured values must be compared within a short time to determine the distance. This can be programmed by querying the active pin (C16).
But there is also a simpler way! To do this, a package is imported which does the calculation. This package can be loaded by selecting the item "Extensions" under "Advanced". Then a new window appears, in which the extensions are listed (by using the search input, these can be searched and many more can be found). Here the package "Grove" must be selected. The window is closed and the item "Grove" can be selected in the menu bar. Here you can find the block "Ultrasonic sensor (in cm) at C16". This block is used to output the distance of an object to the ultrasonic sensor in centimeters. To see this value, the block is inserted into the "show number" block instead of the "0".

Python

Paket hinzufügen

Im Pythoneditor musst du zuerst das Modul "Ultraschallsensor" in dein Projekt importieren. Lade dazu die folgende Datei herunter:
Ultraschallsensor vertical_align_bottom

In dem Pythoneditor klicke auf den Reiter "Projekte" und anschließend auf "Öffnen..." um eine Datei in dein Projekt zu laden. Wähle die Datei ultraschallsensor.py aus und füge sie zu deinem Projekt als weitere Datei hinzu, indem du in dem Dialog "Datei ändern" das kleine Icon klickst und "Datei hinzufügen" auswählst.
Nun ist das Modul hinzugefügt und die kannst über from Ultraschallsensor import *
mit den beiden Funktionen measure_in_cm in Zentimeter und measure_in_inch in Zoll die Entfernung messen.

Ultraschallsensor programmieren

Die Werte des Ultraschallsensors können über den digitalen Pin, an dem der Ultraschallsensor angeschlossen ist in der Variable sensor_pin gespeichert werden. Im Beispiel ist der Ultraschallsensor am Grove Pin A1 (C16/RX) angeschlossen. Über die Funktion measure_in_cm() kann die Entfernung in Zentimeter ausgegeben werden. Anschließend können die Werte auf der LED-Matrix des Calliope mini angezeigt werden:

Python
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.