Overview The example demonstrates how interface with HC-SR04 sensor.
Description: The HC-SR04 sensor uses sound waves to help compute the distance of an object by sending out ultrasonic sound waves to an object and measuring the time it takes to come back to the sensor. The sensor sends out about eight 40 kHz pulses and waits for an object to bounce the waves back to the receiver. It then outputs a high pulse proportional to the time it takes for the sound waves to be sent and received. To use the sensor, a continuous pulse train is generated by a counter output task with a set high time and low time. A 100 uS pulse send on the TRIG line triggers the HC-SR04 module to start sending the ultrasonic pulses followed by a 100 ms low time. A voltage high is sent on the ECHO line until the sound waves bounce back to the receiver. Since the speed of sound at sea level is known to be about 13397 inches per second we can use the high time of the ECHO line and the ratio of inches per second to get the distance traveled by the sound wave. To get the object distance we need to divide by this by two. This can be simplified into a single multiplication since the only unknown variable is the high time.
Steps to implement or execute code To implement this example:
Define the trigger and Echo terminal
Run the VI
Requirements Software LabVIEW 2012 or compatible NI-DAQmx 16.0 or compatible
Hardware cDAQ with C series that have counter feature module or compatible DAQ devices.
**This document has been updated to meet the current required format for the NI Code Exchange.**
Anthony F. Staff Software Engineer National Instruments