This lesson uses a Raspberry Pi 4, an HYSRF05 distance sensor and Python to measure distance. The video has all the details.
The accompanying video does he following:
- shows how to wire the sensor to the Raspberry Pi,
- explains how the sensor works (at a high level)
- explains edges and rising and falling edges on pins
- explains using a list as a stack to store data
- explains line by line all the code necessary to get measurements from the sensor and reported through a python program
There are 5 things you’ll learn in this lesson:
- Understand the difference between using polling and interrupts to monitor a sensor
- Learn how to program a motion sensor using interrupts
- Define rising and falling edges
- Understand how to use a stack for temporary data storage
- Understand the concept of threads using a callback function
By the time I worked through learning about edge detection and ironing the bugs out of my code, the final program seems fairly robust. It still occasionally generates some results that are very inaccurate but under normal conditions, when the distance isn't changing too quickly, the measurements are quite reliable.