Wednesday, September 3, 2025 · 0 min read
Improving IR Distance Sensor Accuracy With Dewesoft DAQ Equipment
Understanding how an infrared distance sensor operates is crucial to designing reliable levitation control systems. In this project, I analyzed the Sharp GP2Y0A21YK0F IR sensor using Dewesoft’s high-resolution SIRIUS data acquisition system and DewesoftX software. The study revealed unexpected signal behavior, prompting the development of custom filtering techniques to ensure accurate distance measurement.
Engineers commonly utilize infrared (IR) sensors in automation, robotics, and consumer electronics for tasks such as object detection, obstacle avoidance, and distance measurement.
Infrared sensors
An infrared (IR) sensor works by emitting infrared light—a type of electromagnetic radiation invisible to the human eye—and detecting the reflection of that light from nearby objects. Here's a basic breakdown of how it operates:
IR Emitter
The sensor features an infrared LED that emits an IR light beam.Object Detection
When an object is within range, the emitted light hits the object and reflects.IR Detector
A photodiode or phototransistor in the sensor detects the reflected light.Signal Processing
Based on the amount and angle of the reflected light, the sensor generates an analog or digital signal corresponding to the object's presence or distance.
In distance-measuring IR sensors, like the Sharp GP2Y0A21YK0F, the sensor uses a triangulation method:
The reflected light hits a position-sensitive detector (PSD) at different spots depending on the object's distance.
The sensor calculates distance based on this reflection angle and outputs a corresponding voltage signal.
Data acquisition and analysis system
The Dewesoft SIRIUS (Figure 1) is an advanced measurement device designed to accurately capture and analyze a variety of signals, including voltage signals from sensors. SIRIUS offers a modular design and superior technical features, enabling it for a wide range of industrial and research applications.
Here are some of the key features of the SIRIUS device:
High accuracy and resolution: The Dewesoft SIRIUS features 24-bit analog-to-digital (A/D) converters, ensuring exceptional accuracy and resolution in measurements. This feature is essential when measuring sensor voltages, where accurate and reliable measurements of small signal changes are required.
Wide dynamic range: The device uses Dewesoft’s patented DualCoreADC® technology, which prevents oversaturation and provides a wide dynamic range. This capability enables SIRIUS to accurately capture both small and large voltage signals without loss of quality.
Low noise: SIRIUS has low noise, which is essential when measuring weak voltage signals from sensors. Low noise enables better measurement quality and more accurate signal analysis.
Measurement synchronization: All measurement channels in SIRIUS are fully synchronized, enabling precise timing of the captured data. This timing is critical in dynamic applications, where synchronizing different signals is crucial for accurate analysis.
Modularity and adaptability: SIRIUS is a modular device, meaning it can be adapted to meet the specific needs of the user. The STG input module enables accurate voltage measurement from various sensor types. Users can combine multiple input modules, such as voltage, current, temperature, and others, in a single device.
Sharp IR distance sensor
I chose the Sharp GP2Y0A21YK0F IR sensor for distance measurement. Infrared (IR) sensors operate by detecting infrared light, a part of the electromagnetic spectrum invisible to the human eye. Such sensors use infrared LEDs to emit light and detectors to detect reflected light. In this way, they can detect the presence of objects and measure their distance. The primary advantage of IR sensors is their ability to detect objects even in darkness, as they do not rely on visible light.
Sharp GP2Y0A21YK0F is an IR sensor designed for distance measurement. This sensor operates on the principle of triangulation, utilizing infrared light to measure the distance to the object. The infrared LED emits light that is reflected from the object and returns to the sensor, where a position-sensitive detector (PSD) detects it. Based on the angle at which the reflected light returns, the sensor calculates the distance to the object.
The sensor has a detection range of approximately 10 cm to 80 cm. Figure 3 shows the sensor characteristic, as specified in the data sheet. The sensor supplies a voltage range of 4.5 V to 5.5 V, with a typical current of 30 mA. The sensor output is an analog voltage signal that varies in proportion to the distance to the object.
The sensor has three connectors: two for the power supply and one for the sensor output. Figure 3 illustrates a schematic diagram of the sensor, along with the meanings of the individual connectors.
The sensor analysis
The distance or height sensor is one of the most essential components in my ball height control system. For the regulation to work effectively, it is crucial to receive continuous information about the ball's height. The sensor converts the distance into a voltage.
First, the sensor had to be analyzed. I obtained the basic data from the data sheet, but I analyzed the sensor anyway to create an algorithm for data acquisition based on this analysis.
I connected the sensor to the first channel of the SIRIUS device, which I had connected via USB to a computer where the DewesoftX program was open. DewesoftX is a data acquisition and signal processing software used for numerous test and measurement applications across all markets.
The first thing I had to do in DewesoftX was to create a new setup file. First, I set the sampling rate and the channel on which to capture the signal from the sensor. Figure 4 shows this setting.
In the "Channel Setup" section, I then performed some quick channel settings, as shown in Figure 5.
After that, I had everything ready to start the measurement, so I clicked on the "Measure" tab. A form opens with a signal recorder, and it is also possible to add other displays.
I made a short measurement so that I could zoom in on the signal and analyze it more easily. After I had completed the measurement, I opened the "Analyze" tab and loaded the recorded measurement there, allowing me to examine it.
The sensor works quite unexpectedly. Figure 6 shows the approximate signal from the sensor, where it is clear that a noisier and quieter signal are alternating. The frequency of this change is 25 Hz. Such behavior poses a significant problem for control, as it can occur that I, at one time with the same average voltage, capture a completely different voltage than during the subsequent capture. This alternation would cause an extremely unpredictable control response.
As a result, I had to find a way to filter the signal. There are many analysis tools in DewesoftX that I could use to help me with this. First, I performed an FFT analysis of the signal to determine which frequencies were present in the signal. Figure 7 illustrates that the low-frequency component is prominent, followed by numerous high-frequency components.
Using the mathematical tools provided by DewesoftX, I created a low-pass FIR filter of order 1000 with a cutoff frequency of 100 Hz and applied it to the sensor signal. Figure 8 illustrates this filter, while Figure 9 shows a comparison between the unfiltered signal and the filtered signal using the FIR filter.
However, implementing such a high-order FIR filter on an FPGA is quite challenging, so I sought an alternative solution. I further brought the sensor signal closer to the noise region. Figure 10 illustrates this transfer. I found that the noise consists of high-amplitude spikes. These occur at a frequency of 1 kHz.
I came up with the idea of averaging the signal within a 1 kHz window and then filtering it accordingly. Using mathematics in DewesoftX, I created a filter based on averaging with a 1 kHz window. This filtering works by taking a portion of the signal that lasts 1 ms. Within this time window, all samples are summed and then divided by the total number of samples. Figure 11 illustrates the filtered signal obtained using this procedure, along with the sensor signal and the FIR filter. I also noted that it gives almost the same result as an FIR filter of order 1000.
Such a filter still does not yield an ideal result, as the signal in the noise region exhibits a slightly higher amplitude. However, after using the filter, the signal is much more repeatable.
Measurement and sensor characteristics
The voltage had to be converted to height, since that’s the data I was interested in. First, I measured by moving the ball around the cylinder with the sensor mounted on the cylinder and recording the intermediate heights at which I located the ball; Figure 12 displays this measurement.
In analyzing this measurement, I recorded the voltages at specific heights and saved the data in a table (Table 1). Additionally, it was necessary to convert the voltage into an AD conversion value in binary form, the form in which the FPGA receives the measurement.
Height [cm] | Voltage [V] | ADC value [bin] | ADC [dec] |
---|---|---|---|
50 | 0,897 | 010001011001 | 1113 |
45 | 0,955 | 010010100001 | 1185 |
42 | 0,99 | 010011001100 | 1228 |
40 | 1,01 | 010011100101 | 1253 |
35 | 1,13 | 010101111010 | 1402 |
30 | 1,3 | 011001001101 | 1613 |
25 | 1,7 | 100000111110 | 2110 |
23 | 1,9 | 100100110110 | 2358 |
21 | 2,08 | 101000010101 | 2581 |
20 | 2,15 | 101001101100 | 2668 |
18 | 2,28 | 101100001101 | 2829 |
17 | 2,33 | 101101001100 | 2892 |
15 | 2,386 | 101110010001 | 2961 |
14 | 2,35 | 101101100100 | 2916 |
13 | 2,26 | 101011110101 | 2805 |
12 | 2,19 | 101010011110 | 2718 |
11 | 2,22 | 101011000011 | 2755 |
I then created a characteristic in DewesoftX by entering the values into a table. It turned out that the characteristic (Figure 13) deviates considerably from the one given in the data sheet. Based on the measured characteristic, I concluded that the usable range of the sensor is only from 15 to 50 cm.
Conclusion
In conclusion, the analysis of the Sharp GP2Y0A21YK0F IR distance sensor using Dewesoft measurement equipment highlighted both the sensor's capabilities and limitations in practical applications.
While the sensor provides a convenient analog voltage output proportional to distance, the presence of high-frequency noise and fluctuating signal patterns poses challenges for the reliable use of this device in control systems.
By leveraging the advanced signal processing tools of DewesoftX, including FFT analysis, FIR filtering, and custom averaging filters, I significantly improved signal clarity and repeatability.
Furthermore, empirical calibration revealed deviations from the datasheet, confirming that accurate, application-specific characterization is essential. Overall, this analysis demonstrates the importance of thorough testing and data processing to ensure sensor performance aligns with system requirements.