Reader small image

You're reading from  Practical Python Programming for IoT

Product typeBook
Published inNov 2020
Reading LevelIntermediate
PublisherPackt
ISBN-139781838982461
Edition1st Edition
Languages
Right arrow

HC-SR04 distance measurement process

In this section, we will cover the process used to measure distance with the HC-SR04. Don't get concerned if this does not make immediately sense. I've provided the details here as background material, as this is the logical process that is implemented by our example program to make the sensor work. You will also find the process documented in the sensor's datasheet.

We measure distance with the HC-SR04 through the correct use and monitoring of the TRIG and ECHO pins. The process looks like this:

  1. Pull the TRIG pin HIGH for 10 microseconds. Pulling TRIG HIGH also makes the ECHO pin HIGH.
  2. Start a timer.
  3. Wait for either of the following to happen:
    • ECHO to go LOW
    • 38 milliseconds to elapse (from the datasheet, this is the time for >4 meters)
  4. Stop the timer.

If 38 milliseconds have passed, we conclude that there is no object in front of the sensor (at least within the effective range of 2 centimeters to 4 meters). Otherwise...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Practical Python Programming for IoT
Published in: Nov 2020Publisher: PacktISBN-13: 9781838982461