# Project object: Acquire distance measurements and print the values to the console
#
# Hardware and connections used:
# Ultrasonic Distance Sensor VCC to 3.3 V
# Ultrasonic Distance Sensor to GND
# Ultrasonic Distance Sensor TRIG Pin to GPIO Pin 15
# Ultrasonic Distance Sensor ECHO Pin to GPIO Pin 14
#
# Programmer: Adrian Josele G. Quional
# modules
from picozero import DistanceSensor # importing the DistanceSensor class to easily handle distance calculations
from time import sleep
# creating a DistanceSensor object and specifying ECHO and TRIG pins
# any GPIO pin can be used for echo and trigger
ds = DistanceSensor(echo=14, trigger=15)
# continuously acquire distance measurements while the board has power
while True:
# printing the values to the console
# values are converted to cm because distance method returns values in m
# conversion factor used is 100 cm = 1 m
distance_cm = ds.distance * 100
print(f"Distance: {distance_cm} cm")
sleep(0.1)
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
ultrasonic1:VCC
ultrasonic1:TRIG
ultrasonic1:ECHO
ultrasonic1:GND