An Arduino-Based Distance Measuring Syst ...

An Arduino-Based Distance Measuring System with a DAQ-like Interface to LabVIEW

Sep 02, 2024

Introduction

In this tutorial, we will guide you through building a robust distance measuring system using an Arduino and multiple ultrasonic sensors, designed to interface seamlessly with LabVIEW. By the end of this article, you’ll understand how to set up and code an Arduino to read multiple distance sensors almost in parallel and control it through a LabVIEW application. This project is ideal for anyone looking to create a simple yet powerful Data Acquisition (DAQ)-like system using readily available hardware and software.

Why Measure Distances with Multiple Sensors in Parallel?

Measuring distances using multiple sensors almost in parallel is crucial in various applications, such as timing systems for races, obstacle detection in robotics, and multi-point monitoring in industrial environments. Achieving near-simultaneous measurements ensures that all sensors provide data from the same moment in time, which is critical for accuracy and reliability in time-sensitive applications.

Understanding Ultrasonic Sensors

Ultrasonic sensors work by emitting a high-frequency sound wave that bounces off objects and returns to the sensor. The sensor then measures the time taken for the sound wave to return (echo) and uses this time to calculate the distance to the object based on the speed of sound.

The typical formula used is:

Where the speed of sound is approximately 343 meters per second at room temperature. The factor of 2 accounts for the round trip of the sound wave.

Sensor interface is extremely simple 4 pins. 2 power pins Vdd and Gnd 1 trigger pin to be excited with a 10us pulse and 1 Echo pin to be sensed to measure the delay.

Requirements

Arduino Code Explanation

Our Arduino firmware is designed to handle multiple sensors efficiently by using a state machine structure that mimics the "open-configure-run-close" model typical of LabVIEW. This design allows easy control from the LabVIEW interface over serial communication.

Key Components of the Arduino Code

  1. Pin Assignments: We define arrays for the trigger (trigPins), echo (echoPins), and power (powerPins) pins of the sensors, allowing easy scalability for more sensors.

  2. State Machine Structure: The code utilizes an enum to define two states: IDLE and MEAS. The state machine controls whether the Arduino is waiting for commands (IDLE) or actively measuring (MEAS).

    • IDLE State: The Arduino waits for commands from LabVIEW. It can respond to identification requests (*IDN?), start measuring (START), set or query the delay (DELAY x, DELAY?), but cannot perform measurements.

      MEAS State: The Arduino continuously measures distances and sends the data back to LabVIEW. In this state, only the STOP command is valid, allowing the system to return to IDLE.

  3. Serial Command Processing: Commands sent from LabVIEW are processed to control the state machine and configure the measurement parameters dynamically. Communication set is different depending on the state of the state machine.

  4. Measuring Distances Almost in Parallel: To achieve near-parallel measurements, the Arduino triggers all sensors in quick succession and then checks the echo pins concurrently in a loop. This ensures that the time difference between measurements from different sensors is minimized.


LabVIEW Interface

Our LabVIEW interface is designed to control the Arduino-based system via serial communication, following a structured flow: initialize, configure, run, read, and close.

  1. Initialize: Opens a serial port to the Arduino and sends the *IDN? command to verify communication and identify the system.

  2. Configure: Allows the user to set the measurement delay (DELAY x) and view the current delay (DELAY?).

  3. Run: Starts the measurement process by sending the START command.

  4. Read: Continuously reads the data sent by the Arduino, displaying the distance for each sensor. Distances calculation is done in LabVIEW avoiding costly floats computations in the microcontroller.

  5. Stop: Sends the STOP command to halt measurements .

  6. Close: closes the serial port.

Building a Solid Arduino Firmware/LabVIEW Object Class API

By structuring the Arduino firmware and LabVIEW interface as we have, we create a modular and extensible system that can easily adapt to new requirements. The use of a state machine in the Arduino firmware aligns well with LabVIEW’s “open-configure-run-close” paradigm, ensuring smooth operation and integration.

Conclusion

This project demonstrates the power and flexibility of using an Arduino for distance measurement with a professional DAQ-like interface in LabVIEW. By following this guide, you can build a robust and scalable measurement system suitable for a variety of applications.

Download the code

The complete Arduino code and LabVIEW VIs are available for download at a "name your price" model, making this an accessible project for hobbyists and professionals alike. Download here.

Save for Later

If you are reading this content on a mobile device you can send this article to your email using this link: MAIL TO ME

¿Te gusta esta publicación?

Comprar Filippo Persia un café

Más de Filippo Persia