[1] a typical GP2Y0A41SK IR distance sensor
[1] a typical GP2Y0A41SK IR distance sensor
An IR (infrared) distance sensor is a device measuring the distance from an obstacle or an object's presence by sending a ray of infrared from its light emitter to that obstacle for the light to bounce off that obstacle and come back to be absorbed into the light detector (PSD).
The 2 main components of an IR distance sensor are the light receiver and emitter.
[2] Emitter is an IR LED/laser diode generating IR light.
Light receiver/detector or position sensor detector (PSD): A photodiode, phototransistor, or an advanced avalanche photodiode (APD), which absorbs incoming IR and converts it to electrical signals for processing. This is the "sense" function, whether for detection or communication.
Optical elements and signal processing: Lenses, filters, and circuits amplify, refine, and interpret the incoming IR signal for practical use, from automation triggers to decoding communications packets.
Standard IR distance sensors use optical geometry and triangulation, like in a GP2Y0A41SK.
Instead of measuring how much light bounces back, optical triangulation involves using a IR beam hitting an object and, reflects and spreads out in various directions (diffuse reflection) back to the receiver lens at a certain angle. Light hitting an object farther away at another distance reflects back through the lens at a shallower angle.
The position where the reflected beam, lands on the internal PSD array directly corresponds to the object's distance.
The sensor's PSD has a focusing lens in front. Light hitting the object at on its initial path at the first distance reflects back into the receiver lens at a steep angle.
Optical triangulation is superior to basic IR reflectivity since basic IR sensors only measure returning light's brightness. This means a dark black surface near the sensor may register the same brightness as a reflective white surface far way. Since triangulation relies entirely on the entry angle IO intensity, the PSD sensor is mostly immune to an object's changing color, surface finish, or material reflectivity.
Decoupling capacitors are used since the Sharp IR sensor periodically fires its internal IR LED in short intense pulses to measure. Each pulse causes a fast current draw surge. A decoupling capacitor (e.g., 10 μF) near the VCC and GND pins. Otherwise, such current surges cause voltage drops on power rails, inducing power-line noise and jittery.
mitigation: to reduce severity
jitter: shaky, nervous
Direct Sunlight / Strong Ambient IR Light: Heavy infrared radiation from direct sunlight or bright incandescent bulbs can flood the PSD array, overpowering the sensor's internal emitter signal and causing corrupted or erratic distance values.
Transparent, Translucent, or Highly Mirror-like Surfaces: Clear materials (such as glass, acrylic, or water) let the IR light pass straight through without reflecting it back. Highly polished mirrors cause specular glare, reflecting the beam away at an angle that misses the PSD receiver entirely.
Extreme Surface Angles: If the object's surface is tilted at an aggressive angle relative to the sensor (above ~15-20), the emitted light bounces off to the side rather than reflecting back into the receiver lens.
[D1]
For the GP2Y0A41SK0F IR sensor it has a distance range of from 4 to 30 cm. It'd be ~0.4 V if the object in front of its is beyond 30 cm.
The output voltage is higher if the object is closer. The closer the object, the lower the voltage, thus an IR distance sensor is also a proximity sensor.
The IR sensor's output voltage is lower if the object in front of it is farther. It's ~0.4 V if that object is beyond 30 cm.
This relationship between the output voltage and the distance from the obstacle can be depicted mathematically by the formula y = 12.806x-1.12, a relationship that is non-linear, where:
y = d = distance of receiver from obstacle (in cm)
x = V = sensor's output voltage
The distance formula uses a negative exponent since the output voltage is inversely proportional to distance. Since the triangulation's geometry causes voltage to drop logarithmically as distance increases.
A distance IR sensor like the Sharp IR sensor takes a measurement cycle each ~16.5 to 38 ms, depending on the model.
In an Arduino program that programs a Sharp IR sensor, if the analogRead() function is read faster than this sampling rate in the loop() function, you'll read stale data from the sensor's internal hold capacitor. A delay(20) function or timing check between reads avoids reading repeated/invalid values.
The sensor emits a cone-shaped IR beam with a view field of ~3°-5°. Since the emtiter and PSD lens are arranged horizontally side-by-side, mounting the sensor verticall vs. horizontally relative to a wall alters how edge transitions are detected-horizontal mounting gives better lateral resolution for wall-following.