Difference between revisions of "Ultrasonic Sensor HC-SR04"

From Sketching with Hardware at LMU Wiki
Jump to navigation Jump to search
(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...")
 
Line 3: Line 3:
 
It sends out an ultrasound signal and detects the echo. By measuring the time you can calculate the distance.
 
It sends out an ultrasound signal and detects the echo. By measuring the time you can calculate the distance.
  
[[File:Ultra1.JPG|200px]]
+
[[File:Ultra1.JPG|300px]]
  
 
more details:
 
more details:
 
* https://randomnerdtutorials.com/complete-guide-for-ultrasonic-sensor-hc-sr04/
 
* https://randomnerdtutorials.com/complete-guide-for-ultrasonic-sensor-hc-sr04/
 
* https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf
 
* https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf
 
  
 
= How to connect it electrically =
 
= How to connect it electrically =

Revision as of 23:10, 30 August 2020

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.

Ultra1.JPG

more details:

How to connect it electrically

Stepper-c.JPG


Required Module and Files


How to control it in MicroPython

 1 from hcsr04 import HCSR04
 2 from time import sleep
 3 
 4 sensor = HCSR04(trigger_pin=12, echo_pin=14)
 5 sleep(1)
 6 i=0
 7 
 8 while True:
 9   distance = sensor.distance_cm()
10   print(i, ': Distance:', distance, 'cm')
11   i=i+1
12   sleep(0.5)



Related Tutorial Videos