Ultrasonic Sensor HC-SR04: Difference between revisions
Jump to navigation
Jump to search
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| | [[File:Ultra1.JPG|x300px]] | ||
[[File:Hc-sr04-1.JPG|x300px]] | |||
more details: | more details: |
Revision as of 23:26, 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.
more details:
- https://randomnerdtutorials.com/complete-guide-for-ultrasonic-sensor-hc-sr04/
- https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf
How to connect it electrically
Required Module and Files
- We use hcsr04.py
- this is downloaded from https://github.com/rsc1975/micropython-hcsr04
- the original file is at https://github.com/rsc1975/micropython-hcsr04/blob/master/hcsr04.py
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