Example Programs

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW & DAQ: Ultrasonic Distance Measurement with HC-SR04 4 Terminal Sensor

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:

  1. Define the trigger and Echo terminal
  2. 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.

 

2017-10-31_14-07-27.jpg2017-10-31_14-08-01.jpg

**This document has been updated to meet the current required format for the NI Code Exchange.**

Anthony F.
Staff Software Engineer
National Instruments
Comments
Member chikiz
Member

Que complemento de software labview tengo que tener para que el ejemplo relacionado para el sensor ultrasonico HC SR04, pueda correr de forma correcta y no me envie errores al ejecutarlo

Anthony_F
NI Employee

Necesita un Multifunction DAQ como el PCI-6220.  Este ejemplo usa dos counters en el Multifunction DAQ, una para emitir un pulso y el otro para medir distancia.

Anthony F.
Staff Software Engineer
National Instruments
Member Toño SM
Member

hay alguna otra forma de realizar un .VI utilizando ese mismo sensor pero sin utilizar Multifunction DAQ.

Member Toño SM
Member

solo cuento con una LABJACK espero y me puedan ayudar a realizar este .VI utilizando esta targea de adquisicion de datos

Member animaster
Member

como puedo mmunicar el sensor ultasonicocon con el arduino conectado al labview

Member fernando9090
Member

se puede conectar con el daq

Member Siske
Member

Hi Guys

I really stroggled a lot to get this module/code working on the DAQ card PCI-6220. The problem was that the DAQ assistent I used to find the terminal to achieve the echo signal misguided me. Thus, use pin 14 on the breakout board for 5V, use pin 2 (PFI12/P2.4) to generate the signal, use pin 7 as ground and finally pin 41 (PFI4/P1.4) to aquire the echo signal. Then the code works perfect.

Member Anpu
Member

Hola, podrian enviarme quien tenga una programación de labview para medir la distancia del sesor ultrasonico hc-sr04 conectado al arduino, ya tengo el LIFA cargado al arduino, ya he comunicado el arduino con labview a un sensor de humedad, pero no logo optener datos del sensor ultrasonico, mi arduino es un mega2560 y la vercion del software del arduino es 1.0.1.

Gracias.

Member d20ryy
Member

Hello, this experiment on how to use myDAQmx