Asynchronously Reading a Sonar Distance Sensor

Author: Jonah Siekmann

To get the quadcopter to fly at a set altitude above crops, we need to use a distance sensor (or more likely, a combination of distance sensors). We’re going to use a sonar distance sensor for at least part of the altitude calculation. However, the speed of sound is pretty slow. In the time it takes the sensor to send a ping and receive the echo, dozens of milliseconds could have passed. So we need to read it asynchronously. This turned out to be a little trickier than I first thought, so I made an instructable on it. You can read it here:

https://www.instructables.com/id/Asynchronously-Reading-the-HC-SR04-Sensor/