Ultrasonic Sensor HC-SR04

From Sketching with Hardware at LMU Wiki
Revision as of 23:09, 30 August 2020 by Skwhadmin (talk | contribs) (Created page with "= Description = The HC-SR04 is an ultrasonic distance sensor that can measure distances from 2cm to 400cm. It sends out an ultrasound signal and detects the echo. By measuring...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Description

The HC-SR04 is an ultrasonic distance sensor that can measure distances from 2cm to 400cm. It sends out an ultrasound signal and detects the echo. By measuring the time you can calculate the distance.

more details:


How to connect it electrically


Required Module and Files


How to control it in MicroPython

from hcsr04 import HCSR04
from time import sleep

sensor = HCSR04(trigger_pin=12, echo_pin=14)
sleep(1)
i=0

while True:
  distance = sensor.distance_cm()
  print(i, ': Distance:', distance, 'cm')
  i=i+1
  sleep(0.5)



Related Tutorial Videos