Why Measure Distance?
Proximity sensors are critical for the most basic robotic function: Not bumping into things. Unlike complex vision systems, proximity sensors provide fast, reliable, and computationally cheap distance data, making them the first line of defense in robot safety systems.
Safety First
Simple sensors like ultrasonic and IR perform "reflex" actions—emergency braking when an object is too close, independent of complex AI software.
Precision Control
Laser rangefinders allow for precise tasks like maintaining exact altitude for drones or perfect alignment for charging docks.
Ultrasonic Sensors
Sound Waves
Uses high-frequency sound waves to detect objects and measure distance, similar to bat echolocation.
Range:2cm - 400cm
Principle:The sensor emits a short ultrasonic burst (ping) and listens for the echo. The time elapsed between emission and reception is used to calculate distance: d = (time × speed_of_sound) / 2.
Ideal For:
Obstacle avoidance, liquid level sensing, parking assist, distance measurement
Infrared Proximity Sensors
Optical
Uses reflected infrared light to detect the presence or distance of an object.
Range:10cm - 80cm (Short)
Principle:An IR LED emits light, and a photodiode measures the intensity (for proximity) or the angle (triangulation) of the reflected light to determine distance.
Ideal For:
Line following, cliff detection (stairs), close-range obstacle avoidance, object counting
Laser Rangefinders (1D ToF)
Time-of-Flight
Highly accurate single-point distance measurement using laser time-of-flight technology.
Range:5cm - 40m
Principle:Emits a focused laser beam and measures the precise time it takes to return. Unlike wide ToF cameras, this measures scanning points.
Ideal For:
Precision altitude holding (drones), precise docking, industrial measurement
Radar Sensors (mmWave)
Radio Waves
Uses millimeter-wave radio signals to detect objects, distance, and speed, even in adverse weather.
Range:30m - 200m
Principle:Transmits mm-wave radio signals (e.g., 60GHz or 77GHz) and analyzes reflected signals. Can measure range, velocity (Doppler), and angle.
Ideal For:
Automotive cruise control, drone collision avoidance, vital sign monitoring (breathing), perimeter security
Inductive & Capacitive Sensors
Industrial Proximity
Robust, short-range switches for detecting metal (Inductive) or any material (Capacitive).
Range:1mm - 20mm
Principle:Inductive: Generates electromagnetic field, metal disturbs it. Capacitive: Measures change in capacitance when any object enters the electric field.
Ideal For:
End-stops for arms, detecting metal parts on conveyor, liquid level sensing (through plastic)
Magnetic Proximity (Hall Effect)
Magnetic
Detects the presence of magnetic fields or magnets.
Range:1cm - 5cm
Principle:A semiconductor transducer varies its output voltage in response to a magnetic field.
Ideal For:
Door open/close detection, wheel speed sensing (odometry), brushless motor commutation
Sensor Characteristics
| Sensor | Detects Material | Typical Range | Best Environment | Cost |
|---|---|---|---|---|
| Ultrasonic | Any (Hard) | Medium (4m) | Clean Air | Low ($) |
| Infrared (IR) | Matte/Light | Short (80cm) | No Direct Sun | Very Low ($) |
| Laser (1D ToF) | Any | Long (40m) | Any | Medium ($$) |
| Radar (mmWave) | Reflective | Very Long | Fog/Dust/Rain | High ($$) |
| Inductive | Metal Only | Very Short | Dirty/Oily | Low ($) |
| Capacitive | Any | Very Short | Dry | Medium ($$) |
Find the Right Proximity Sensor
What material are you detecting?
// Basic Sketch for HC-SR04 Ultrasonic Sensor
const int trigPin = 9;
const int echoPin = 10;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop() {
// Clear the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Send 10 microsecond pulse to trigger sensor
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the echoPin (pulse duration in microseconds)
long duration = pulseIn(echoPin, HIGH);
// Calculate distance
// Speed of sound = 343m/s or 0.0343 cm/microsecond
// Distance = (Time * Speed) / 2
int distance = duration * 0.0343 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(100);
}