This tutorial shows how to use the HC-SR04 Ultrasonic Sensor with Raspberry Pi and Python gpiozero. This sensor is a 5V device and I explain how to use it safely with the Raspberry Pi (which is a 3.3V device) using a simple voltage divider built from resistors.
A significant amount of time is spent on Python threading where I explain how to run code (specifically infinite loops) as a thread, allowing other code to run at the same time.
0:00 Intro
1:10 Voltage Divider Setup
2:23 Basic Schematic Diagram
2:48 Event-Driven Code Example
3:37 Continuous Distance Readout
4:17 Python Threading Explained
7:06 Complete Code with Threading
Full code: [ Ссылка ]
(Note: code posted may contain small updates and/or bug fixes not shown in the video)
Disclaimer:
"Raspberry Pi" and the distinct logo are a trademark of the Raspberry Pi Foundation.
Music: Wrong by Dan Henig, YouTube Music Library
![](https://s2.save4k.ru/pic/JvQKZXCYMUM/maxresdefault.jpg)