Ultrasonic Distance Sensor
The StudioBot has an ultrasonic distance located at the front of the robot. These look like the 'eyes' of the robot.

import time
import board
import adafruit_hcsr04
sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.TRIGGER, echo_pin=board.ECHO)
while True:
try:
print((sonar.distance,))
except RuntimeError:
print("Retrying!")
time.sleep(0.1)Last updated