0% found this document useful (0 votes)
20 views19 pages

Design and Implementation of an Infrared Distance Sensing System with Real-Time Data Analysis Using Arduino and LabVIEW

The project focuses on designing and developing an infrared (IR) distance sensing mechanism using Arduino and LabVIEW, aimed at accurate object detection and distance measurement. It integrates hardware components like an IR transmitter and receiver with software for data visualization and calibration. The system is intended for applications in automation and robotics, enhancing navigation capabilities by detecting obstacles in dynamic environments.

Uploaded by

Jasmine Hindawi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views19 pages

Design and Implementation of an Infrared Distance Sensing System with Real-Time Data Analysis Using Arduino and LabVIEW

The project focuses on designing and developing an infrared (IR) distance sensing mechanism using Arduino and LabVIEW, aimed at accurate object detection and distance measurement. It integrates hardware components like an IR transmitter and receiver with software for data visualization and calibration. The system is intended for applications in automation and robotics, enhancing navigation capabilities by detecting obstacles in dynamic environments.

Uploaded by

Jasmine Hindawi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Sensors - ME0348 (2025) Students project

A Design and Development of an IR distance sensing mechanism


with Data Analysis and Calibration Using Arduino and LabVIEW

From Mechatronics engineering students


in the SATS department

Mohammed Eltallaa
Zaid Ateh
Yasmin Alhendawy

14.01.2025

ID numbers Mohmmad:
20211102066
Zaid:
20221102036
Yasmin:
20211102068

1
Sensors - ME0348 (2025) Students project

Instructor Dr. Natheer


Almtireen

Table of Contents
1.Introduction 3
1.1 Motivation 3
1.2 Objective 3
2. Methodology 4
2.1 IR Sensing Mechanism 4
2.2 LabVIEW 5
3.Concept of the system 6
3.1 Key Features of the system 6
3.2 Components and Materials6
3.3 Design and circuit modelling 7
3.4 Structural Analysis 8
4. Programming and Control 9
4.1 Arduino Code 9
4.2 Filtering inside Arduino 11
5. LabVIEW Implementation 12
5.1 Configuration 12
5.2 Data Visualization 13
6. Tests 14
6.1 Initial Testing 14
6.2 Calibration 14
7. Discussion 16
7.1 Performance Analysis 16
7.2 Summary of the system’s advantages and disadvantages 16
7.3 Future improvements 17
8. Final Concept 18
9. Conclusion 19

2
Sensors - ME0348 (2025) Students project

1 Introduction
1.1 Motivation
Infrared (IR) sensors are essential components in modern technology, enabling
precise detection of objects, distance measurement, and motion tracking across
various applications. These sensors operate by emitting infrared light and detecting
the reflections from nearby objects, making them versatile for both industrial and
personal use.
In this project, we aim to construct an IR sensor system, integrating hardware and
software components to achieve accurate and reliable measurements. The
hardware will include an infrared transmitter and receiver circuit designed to detect
objects or measure distances based on reflected IR light. On the software side, we
will utilize LabVIEW, a powerful graphical programming platform widely used for
data acquisition, processing, and visualization.
Through this project, we aim to understand the principles of IR sensing operations,
explore signal processing techniques, and harness LabVIEW's capabilities to design
a functional and interactive system. This document outlines the design,
construction, and testing process of an IR sensor, highlighting the integration with
LabVIEW to achieve a seamless, user-friendly solution for various usages.

1.2 Objective
The primary objective of this project is to design and construct an IR sensor system
capable of performing two key functions: detecting and measuring distances to
nearby objects. The project involves developing a robust hardware setup with an
infrared transmitter and receiver to generate and capture IR signals. By integrating
the IR sensor with LabVIEW, the system will enable real-time data processing,
visualization, and calibration to ensure accurate distance measurements.
In addition to distance detection, the IR sensor will be utilized in dynamic
environments as an obstacle/wall detector for robotic navigation. This functionality
will allow robots to identify and avoid obstacles, enhancing their ability to move
safely and efficiently in complex surroundings or mazes. By combining the
capabilities of the IR sensor with the advanced processing and control features of
LabVIEW, this project aims to create a versatile, reliable system that is suitable for
applications in automation, robotics, and beyond.

3
Sensors - ME0348 (2025) Students project

2 Methodology
2.1 IR Sensing mechanism
An IR sensor consists of two parts, the emitter circuit, and the receiver circuit. This
is collectively known as a photo-coupler or an optocoupler.
The emitter is an IR LED, and the detector is an IR photodiode. The IR photodiode is
sensitive to the IR light emitted by an IR LED. The photodiode’s resistance and
output voltage change in proportion to the IR light received. This is the underlying
working principle of the IR sensor.
The type of incidence can be direct incidence or indirect incidence:
1. direct incidence: the IR LED is placed in front of a photodiode with no
obstacle.
2. indirect incidence: both the diodes are placed side by side with an
opaque object in front of the sensor. The light from the IR LED hits the
opaque surface and reflects to the photodiode.
An IR receiver LED and an IR transmitter LED are both types of light-emitting diodes
(LEDs) that are used in infrared (IR) communication. Also, IR receiver LED is a
device that detects infrared signals from remote controls and other IR sources. It is
typically a small, clear, or translucent device that is sensitive to IR light in a specific
frequency range. When an IR signal is detected, the IR receiver LED will emit a small
amount of visible light, which can be used to confirm that a signal has been
received.

4
Sensors - ME0348 (2025) Students project

2.2 LabVIEW
LabVIEW provides a graphical interface to visualize sensor data, such as distance
readings or obstacle alerts. we can design custom dashboards with graphs,
indicators, and alarms to make the system intuitive and interactive.
Benefits of LabVIEW:
 Easy Integration with Hardware
 LabVIEW supports a wide range of hardware interfaces, including
microcontrollers (like Arduino or ESP32), data acquisition devices, and
sensors.
 Using LabVIEW, you can directly communicate with your IR sensor system for
seamless operation.
 Minimal Coding Requirements

5
Sensors - ME0348 (2025) Students project

3 Concept of the system


3.1 Key Features of the system
 LCD Display: Displays either a single reading or an average of multiple
readings based on button input.
 Button Control: When the button is pressed, it triggers the display of a
single filtered distance reading for 2 seconds. If the button is not pressed,
the code automatically updates the average distance every 2 seconds.
 Filtering for Stable Readings: A low-pass filter is applied to smooth out the
raw sensor data, reducing noise and ensuring more stable distance
readings.
 Distance Calculation: Uses pre-calibrated voltage-distance pairs to convert
raw sensor data (voltages) into accurate distance measurements using
linear interpolation.

3.2 Components and Materials


 system: Arduino uno, Buttons, Wires, Bread board.
 Sensing system: Perf board, Resistors (47, 20*10k, 2.4, 220), IR
photodiode, IR led, NPN transistor, Capacitor 100µF.
 Applications used: Arduino ide, LabVIEW.

6
Sensors - ME0348 (2025) Students project

3.3 Design and circuit modelling of the sensor

(1) (2)

3.4 Structural Analysis


1st Circuit: IR Transmitter Circuit
Components and Functionality:
 IR LED (Infrared Light-Emitting Diode): The black triangle in the circuit is
an IR LED that emits infrared light, which is invisible to the human eye. This
acts as the transmitter.
 Resistors:
o Rim (47 Ω): Limits the current flowing through the IR LED to prevent
damage.
o R1 (220 Ω): Acts as a base resistor for the NPN transistor.

o R2 (10 kΩ): Pulls the transistor base to ground when the Arduino
output is low.

7
Sensors - ME0348 (2025) Students project

 NPN Transistor: Used as a switch to control the IR LED. When the Arduino
digital pin is HIGH, the transistor allows current to flow through the IR LED,
turning it on.
 Capacitor (10 µF): Stabilizes the power supply to prevent noise or
fluctuations in the circuit.

Operation:
 The Arduino digital pin controls the IR LED. When the pin outputs HIGH, the
transistor switches on, completing the circuit for the IR LED to emit light.
 The capacitor ensures stable operation, especially in noisy environments. And
allows high current through LED

2nd Circuit: IR Receiver Circuit


Components and Functionality:
 IR Photodiode: Detects the reflected IR light from an object. The black
triangle symbol here is a photodiode that responds to infrared radiation. It
controls the amount of current that goes in the circuit when the current is
hight the voltage is higher
 Resistor (10 kΩ): Acts as a pull-down resistor, creating a voltage divider to
control sensitivity.
 Arduino Analog Input: Reads the voltage level across the pull-down
resistor, which varies depending on the IR light detected.
Operation:
 When an object reflects the IR light emitted by the IR LED, the photodiode
detects this reflected light.
 The amount of IR light received changes the voltage across the pull-down
resistor, and this change is read by the Arduino analog input as a varying
signal.

How the IR Sensor Works as a Module


1. The IR LED continuously emits infrared light.
2. If an object comes close, it reflects this IR light back toward the photodiode.
3. The photodiode detects the reflected light, and the Arduino measures the
corresponding voltage signal to determine the presence or distance of the

8
Sensors - ME0348 (2025) Students project

object.

4 Programming and Control


4.1 Arduino Code
1. #include <LiquidCrystal.h>
2. const int rs = 12, en = 11, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
3. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
4.
5. #define sen A0
6. #define btn 3
7. #define led 13
8. #define digout 9
9.
10. bool buttonPressed = false;
11.
12. float filteredDistance = 0;
13. const float alpha = 0.1;
14.
15. void setup()
16. {
17. pinMode(led, OUTPUT);
18. pinMode(digout, OUTPUT);
19. pinMode(btn, INPUT_PULLUP);
20. lcd.begin(16, 2);
21. lcd.clear();
22. digitalWrite(led, LOW);
23. Serial.begin(9600);
24. }
25. void loop()
26. {
27. static unsigned long lastUpdateTime = 0;
28. static float averageDistance = 0;
29.
30. if (digitalRead(btn) == LOW)
31. {
32. buttonPressed = true;
33. digitalWrite(led, HIGH);
34. }
35. else
36. {
37. digitalWrite(led, LOW);
38. }
39.
40. if (buttonPressed)
41. {
42. float singleDistance = getFilteredDistance();
43. lcd.clear();
44. lcd.print("Single Reading:");

9
Sensors - ME0348 (2025) Students project

45. lcd.setCursor(0, 1);


46. lcd.print(singleDistance, 2);
47. lcd.print(" cm");
48. Serial.println(singleDistance, 2);
49. buttonPressed = false;
50. delay(2000);
51. }
52. else
53. {
54. if (millis() - lastUpdateTime >= 500)
55. {
56. averageDistance = getAverageFilteredDistance();
57. lcd.clear();
58. lcd.print("Avg Distance:");
59. lcd.setCursor(0, 1);
60. lcd.print(averageDistance, 2);
61. lcd.print(" cm");
62. Serial.println(averageDistance, 2);
63. lastUpdateTime = millis();
64. }
65. }
66. }
67.
68. float getFilteredDistance()
69. {
70. digitalWrite(digout, HIGH);
71. delayMicroseconds(40);
72. float read = analogRead(sen);
73. digitalWrite(digout, LOW);
74. delayMicroseconds(500);
75.
76. float rawDistance = analogToDistance(read);
77. filteredDistance = alpha * rawDistance + (1 - alpha) * filteredDistance;
78. return filteredDistance;
79. }
80. float getAverageFilteredDistance()
81. {
82. float readings[5] = {0};
83. for (int i = 0; i < 5; i++)
84. {
85. readings[i] = getFilteredDistance();
86. }
87. float sum = 0;
88. for (int i = 0; i < 5; i++)
89. {
90. sum += readings[i];
91. }
92. return sum / 5;
93. }
94. float analogToDistance(float analogValue)
95. {
96. float voltage = analogValue * (5.0 / 1023.0);
97.
98. float voltageValues[] =
{4.49,4.45,4.42,4.40,4.38,4.33,4.31,4.25,4.24,4.19,4.13,3.98,3.79,3.57,3.33,3.15,3.04,2.87,
2.72,2.63,2.58,2.53,2.45,2.39,2.34,2.30};
99. float distanceValues[] = {0.0,1.0,2.0,3.0,4.0, 5.0,6.0,7.0,8.0,9.0
,10.0,11.0,12.0,13.0,14.0, 15.0, 16.0,17.0,18.0,19.0, 20.0,21.0,22.0,23.0,24.0, 25.0};
100.
101. for (int i = 0; i < 26; i++)

10
Sensors - ME0348 (2025) Students project

102. {
103. if (voltage >= voltageValues[i + 1] && voltage < voltageValues[i])
104. {
105. float slope = (distanceValues[i + 1] - distanceValues[i]) / (voltageValues[i +
1] - voltageValues[i]);
106. float distance = distanceValues[i] + slope * (voltage - voltageValues[i]);
107. return constrain(distance, 0, 25);
108. }
109. }
110. return constrain(distanceValues[0], 0, 25); }

4.2 Filtering inside Arduino


Purpose of the Filter:
The low-pass filter is used to smooth out noisy data from the IR sensor. This ensures
the distance readings are more stable and less affected by random fluctuations or
rapid changes in sensor output.
How our Filter Works:
1. The filter gives more weight to the previous filtered value (by multiplying it with
(1 - α )) and less weight to the new raw reading (by multiplying it with α ).

2. This means sudden changes in the raw data are dampened because the new
value contributes only a small portion ( α = 0.1) to the updated filtered value.

3. Over time, the filter averages out the noise, resulting in smoother and more
stable readings.
The low-pass filter enhances the reliability of sensor data by reducing noise and
minimizing random fluctuations caused by environmental factors like electrical
interference or light variations. It ensures stable and steady distance readings,
preventing unnecessary jumps in the displayed values. Additionally, it smooths out
gradual changes in distance, providing a more consistent and user-friendly output.
Note: Calibration is included in the code of the Arduino, but we will discuss it after
the initial tests section.

11
Sensors - ME0348 (2025) Students project

5 LabVIEW Implementation
5.1 Configuration

This LabVIEW system interfaces with an Arduino via serial communication to


receive, process, and display data. Here’s a concise breakdown of the system:
1. VISA Open & Close: Establish and terminate a serial connection.
2. VISA Resource Name: Specifies the communication port (e.g., COM3).
3. VISA Read: Reads data from the serial port.
4. Byte Count: Tells VISA Read how many bytes to retrieve (each number uses
2 bytes).
5. Return Count: Verifies the number of bytes received to ensure proper
communication.
6. Scan Value: Converts the received string data into a float for processing.
7. Distance Indicator: Displays the final processed result (e.g., distance
measurement).
8. Filter Block: Processes the raw data to reduce noise and smooth the signal.
9. Graph Indicators (filtered / unfiltered): Show the raw and filtered data
visually for analysis.

12
Sensors - ME0348 (2025) Students project

10.While Loop (Black Box): Ensures continuous data reading and processing.
11.Stop Button: Terminates the loop and closes the serial connection.
This system allows for real-time data acquisition, filtering, and visualization,
showcasing how LabVIEW can integrate with hardware for effective data analysis.

5.2 Data Visualization

1. "Before Filtering" Graph: Shows the raw, unfiltered data received from the
sensor. Noise or fluctuations in the signal are visible here.
2. "After Filtering" Graph: Displays the processed (filtered) data. This graph
typically has smoother and more reliable output, highlighting the effect of the
filtering process.
The graphs illustrate the change in readings over distance versus time. Before
filtering, the data was filled with unwanted noise and fluctuations. However, after
applying LabVIEW's built-in filter functions, the data became smoother, resulting in
better acquisition and improved signal clarity.
This front panel offers real-time control and visualization of the system, enabling the
user to monitor data quality and performance effectively.

13
Sensors - ME0348 (2025) Students project

6 Tests
6.1 Initial Testing
During initial testing of the IR sensor, we assumed the relationship between the
detected signal and distance was linear, which resulted in significant errors in the
measurements. However, after plotting data for 25 points, we discovered that the
relationship was non-linear. By fitting a quadratic curve to the data, we achieved a
more accurate representation of the sensor's behaviour, significantly improving its
performance and reducing errors.

6.2 Calibration
We calibrated the system through Arduino code at first we created Two arrays,
voltageValues[ ] and distanceValues[ ] to store known data points.
voltageValues[ ] represents the voltages observed at specific distances.
distanceValues[ ] represents the corresponding distances (in cm).
These points are obtained through experimental calibration, where voltage readings
are recorded at various distances (0 cm to 25 cm).
We used Interpolation to Estimate Distance:
The goal was to determine the distance corresponding to a given voltage, which
might not match any specific point in voltageValues[ ]. The code identifies two
calibration points (nearest neighbours) between which the given voltage lies and
uses linear interpolation to estimate the distance.
1. Calibration Data as Points on the Plot:
- The voltageValues[ ] represent the x-axis (voltage readings from the IR
sensor), while the distanceValues[ ] represent the y-axis (corresponding distances
in cm).
- These form a set of discrete data points, plotted as a curve based on the
relationship between voltage and distance. The curve is typically non-linear, as the
response of an IR sensor to distance is not perfectly proportional.
2. Finding the Range (Segment of the Curve):

14
Sensors - ME0348 (2025) Students project

- For a given voltage input, the algorithm identifies which two neighbouring points
(on the x-axis) the input voltage lies between. This corresponds to a segment of the
curve on the plot.
3. Linear Interpolation on the Curve:
- Within this segment, the calibration assumes the curve is approximately linear.
- By drawing a straight line between the two neighbouring points, the algorithm
estimates the corresponding distance for the input voltage. This is essentially
finding the y-coordinate for a given x-coordinate within the segment.
4. Constraining to the Measurable Range:
- Since the calibration only covers distances between 0 and 25 cm, any
interpolated distance outside this range is capped at 0 or 25 cm.

Visual Representation:
Imagine a plot with:

- Y-axis: Voltage (4.5 V to ~2.3 V).


- X-axis: Distance (0 cm to 25 cm).
- The calibration data points form a smooth, decreasing curve (higher voltages
correspond to closer distances, while lower voltages correspond to farther
distances).
- The algorithm's role is to approximate the smooth curve with small linear
segments between the calibration points. For a given input voltage, it uses the
nearest segment to interpolate the distance value.

15
Sensors - ME0348 (2025) Students project

This method ensures a balance between simplicity and accuracy, providing


reasonable estimates for distances based on the known calibration curve.

7 Discussion
7.1 Performance Analysis
1. Accuracy Across the Range:
- The sensor showed inconsistent accuracy in the range between 0 cm and 13
cm. This could be due to the non-linear relationship between voltage and distance,
which is more pronounced at closer ranges, making precise interpolation more
challenging.
- Between 13 cm and 22 cm, the sensor performed significantly better, with
accurate and reliable readings. The maximum effective range was determined to be
22 cm, beyond which the sensor was unable to provide reliable data.

2. Impact of Light Conditions and Surface Reflections:


- The sensor's performance was heavily influenced by ambient light conditions
and surface reflectivity. Strong ambient light, particularly from sunlight or other
IR sources, caused interference, leading to fluctuating or erroneous readings.
Reflective surfaces amplified the detected IR light, resulting in overly high voltage
readings, while matte or dark surfaces reflected less light, reducing the detected
signal strength.

3. Precision and Response Time:


- The sensor provided fast readings with good precision under stable conditions.
However, occasional random or zero errors were observed, which could stem
from electrical noise or transient environmental factors. These errors, while
infrequent, highlight a need for additional filtering or smoothing of the output.

4. Effect of Object Colour/roughness:


- The colour of the object being detected had a significant impact on the
readings. Lighter and more reflective colours (e.g., white or metallic) reflected more
IR light, resulting in higher voltage signals and shorter perceived distances.
Conversely, darker colours (e.g., black) absorbed more IR light, reducing the signal

16
Sensors - ME0348 (2025) Students project

strength and leading to longer perceived distances. This behaviour is due to the IR
sensor's dependence on the amount of reflected IR light, which varies based on the
surface's reflectivity and absorption properties.

7.2 Summary of the system’s strengths and weaknesses


Advantages Disadvantages

Small size Sensitivity to Ambient Light


Simple Circuit Design Requires calibration (to measure base
ambient light level)
Low cost 1
Nonlinear ( 2
)
d
Non-Contact Detection Limited Range
Fast Response Time Directional Limitation
Adjustable Sensitivity Low Penetration Through Obstacles

Easy to integrate with various Temperature Dependency


microcontrollers
Stable Operation Reflective Surface Limitation

7.3 Future improvements


1. Enhanced Calibration: Implement more precise calibration methods or
adapt production-line calibration to improve measurement accuracy.
2. Capacitor Testing: Experiment with different capacitors to optimize
current flow and improve sensor performance especially in smaller ranges.
3. Wider Photodiode Half-Angle: Utilize photodiodes with a higher half-
angle to enhance detection coverage.
4. Microprocessor Integration: Integrate a microprocessor for better data
processing and advanced functionality.

17
Sensors - ME0348 (2025) Students project

8 Final Concept
This IR sensor system is a compact, cheap, versatile solution for measuring small
distances, utilizing pre-calibrated data and advanced filtering to ensure accurate
and stable readings. By integrating features like a low-pass filter and user-controlled
modes for single or average measurements, the system is designed to be reliable
and user-friendly. This system has a wide range of potential applications, including
proximity sensing, obstacle detection in robotics, maze-following robots, industrial
automation, and home security systems, making it a valuable tool for technological
solutions such as walls detecting mechanism for self-emptying vacuums.

Pins configuration:
01-> 5v
03-> ground
04-> analog in
05 -> digital out

18
Sensors - ME0348 (2025) Students project

9 Conclusion
Creating an IR sensor from scratch, incorporating all the filtering, calibration, and
integrating LabVIEW into the process, transforms the project into a rich learning
experience. The addition of LabVIEW introduces a dynamic dimension to the
development, enabling the visualization, processing, and analysis of data in real-
time. This reinforces the importance of integrating software tools with hardware for
effective system design.
By designing circuits, interpreting raw signals, and fine-tuning calibration processes,
we delve deep into the fundamentals of sensor design and signal processing.
LabVIEW serves as an invaluable tool, bridging the gap between theoretical
concepts and practical implementation. It allows for intuitive data representation
and interactive control, making complex processes more approachable and
enhancing debugging efficiency.
This project not only expands our technical skillset but also emphasizes the
importance of interdisciplinary thinking—merging hardware development with
software solutions. It challenges us to think critically, adaptively solve problems,
and continually improve. Ultimately, it cultivates a comprehensive understanding of
sensor systems while fostering a mindset of innovation and lifelong learning.

The End

19

You might also like