Example Code

Laser Displacement Sensing and Data Logging with NI USB DAQ and LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Programming Language

  • LabVIEW G

Code and Documents

Attachment

Third-Party Code Repository

Some users manage their code in repositories outside of ni.com. Use your best judgment when following links to third-party sites. https://www.micro-epsilon.in/fileadmin/download/products/cat--optoNCDT--en.pdf

Description

Laser displacement sensors are non-contact devices that measure distance, position, height, or thickness with high precision using laser technology. In this example, the optoNCDT 1910 laser sensor (model ILD1910-750) is used, connected via a 17-pin plug-in cable to an NI M Series USB DAQ device. The system acquires analog voltage output from the sensor, converts it to displacement (mm) in LabVIEW, displays the results in real time, and logs the data for further analysis.

This setup is ideal for applications requiring accurate, high-speed, and non-contact measurement such as quality control, automation, or structural monitoring where physical contact with the target is not possible or desirable.

mceclip1.png

mceclip0.png

How to Use

mceclip2.png

mceclip0.pngmceclip1.png

 

Hardware Setup

Step Action
1 Connect the sensor’s analog output (typically 0–10 V) to an analog input channel on your NI USB DAQ (e.g., Dev1/ai0 or ai20). Use the 17-pin connector cable as specified by the sensor manual.
2 Ensure the sensor and DAQ share a common ground.
3 Power on the sensor and DAQ device.

 Run and Observe

  • Start the VI. The graph will show real-time displacement.
  • The data is scaled to mm and can be logged for analysis.
  • Use the Stop button to end acquisition and clear the DAQ task.

Additional Information

Modify for Other Use Cases

  • Multiple Sensors: Add more channels in the DAQmx Create Channel VI.
  • Different Ranges: Adjust scaling factor and voltage range for your sensor.
  • Event Logging: Add logic to log only when displacement exceeds a threshold.
  • Continuous Monitoring: Use continuous sample mode for long-term data collection.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors