Real-Time Distance Measurement using LABVIEW and Arduino with an Ultrasonic Sensor
Objective :
The objective of the experiment "Real-Time Distance Measurement using LABVIEW and
Arduino with an Ultrasonic Sensor" is to demonstrate how distance can be measured in real-time
using an ultrasonic sensor with LABVIEW and Arduino.
Equipment Requirement:
Arduino Board
Ultrasonic Sensor (HC-SR04)
Jumper wires
Computer with LABVIEW software installed
Theory :
In this experiment, we use an ultrasonic sensor to measure the distance between the
sensor and an object in real-time. The ultrasonic sensor emits high-frequency sound waves which
bounce off the object and return to the sensor. By measuring the time taken for the sound wave to
travel to the object and back, the distance between the object and the sensor can be calculated.
The ultrasonic sensor used in this experiment contains two transducers - a transmitter and
a receiver. The transmitter sends out a burst of high-frequency sound waves which bounce off the
object and return to the receiver. The time taken for the sound wave to travel to the object and
back is measured by the Arduino board.
To calculate the distance, the time taken is divided by two and multiplied by the speed of sound
in air. The speed of sound in air is approximately 343 meters per second at room temperature.
Therefore, the formula used to calculate the distance is distance = duration * 0.034 / 2, where
duration is the time taken for the sound wave to travel to the object and back.
The LABVIEW software is used to interface with the Arduino board and display the distance
measurement in real-time. The ultrasonic sensor is connected to the Arduino board using jumper
wires. The VCC pin is connected to 5V, GND to GND, Trig to digital pin 12, and Echo to digital pin
11.
The Arduino IDE is used to write the code for the Arduino board. The code reads the data from
the ultrasonic sensor and calculates the distance using the above formula. The distance measurement
is then sent to the LABVIEW software using the VISA protocol.
In LABVIEW, the distance measurement is displayed on a numeric indicator and a waveform
chart. The numeric indicator displays the current distance measurement, while the waveform chart
displays the distance measurement over time.
Figure 5.1 Pin diagram of ultrasonic sensor (HC - SR04)
Figure 5.2 Arduino Programming for Real-Time Distance Measurement
Figure 5.3 Front panel diagram of Real time distance measurements using LabView and Arduino
Figure 5.4 Block diagram of Real time distance measurements using LabView and Arduino
Procedure :
1. Connect the ultrasonic sensor to the Arduino board using jumper wires as follow:
Connect the VCC pin of the ultrasonic sensor to the 5V pin on the Arduino board.
Connect the GND pin of the ultrasonic sensor to the GND pin on the Arduino
board.
Connect the Trig pin of the ultrasonic sensor to digital pin 12 on the Arduino
board.
Connect the Echo pin of the ultrasonic sensor to digital pin 11 on the Arduino
board.
2. Launch the Arduino IDE on your computer and open a new sketch.
3. Write a simple code in the sketch window of Arduino IDE to read the distance value from
the ultrasonic sensor.
4. Verify and upload the code to the Arduino board.
5. Connect the Arduino board to your computer via USB cable.
6. Launch LABVIEW software on your computer and create a new VI.
7. From the "Functions" palette, select "Instrument I/O" and drag and drop a "VISA Open"
block onto the block diagram.
8. Double-click the "VISA Open" block to open its properties.
9. In the "Resource Name" field, select the correct COM port that corresponds to the
Arduino board connected to your computer. The information regarding the port can be
found in the "Tools > Port" menu of the Arduino IDE.
10. From the "Functions" palette, select "Instrument I/O" > "VISA" and drag and drop a
"VISA Read" block onto the block diagram.
11. Double-click the "VISA Read" block to open its properties.
12. In the "Read Buffer Size" field, enter the number of bytes to read from the serial port
(e.g. 10 bytes).
13. From the "Functions" palette, select "Instrument I/O" > "VISA" and drag and drop a
"VISA Close" block onto the block diagram.
14. Wire the output of the "VISA Open" block to the input of the "VISA Read" block.
15. Wire the output of the "VISA Read" block to the input of the "VISA Close" block.
16. Add a "Scan From String" function from the "String" palette and connect it to the output
of the "VISA Read" function.
17. Add a waveform chart from the "Graphs and Charts" palette and connect it to the output
of the "Scan From String" function.
18. From the " Controls " palette, select "Numeric" and drag and drop a "Numeric Indicator"
control onto the front panel.
19. Connect the output of the "VISA Read" function to the input of the "Numeric Indicator"
control. This will display the distance readings in real-time.
20. Run the VI and observe the distance readings on the numeric indicator and waveform
chart.
Result :
The measurement of distance in real-time using an ultrasonic sensor with LABVIEW and
Arduino was successfully demonstrated. The distance was then displayed on a numeric
indicator and a waveform chart in LABVIEW.