Using the Infrared Sensor Proximity Mode



In Proximity mode, the Infrared Sensor sends out an infrared signal, and it can detect the reflection of this signal by an object in front of the sensor. The strength of the reflected signal can be used to estimate the proximity of (distance to) the object. You could use the Proximity mode, for example, to detect when your robot gets close to a wall.
Infrared Sensor Proximity Mode Data
In Proximity mode, the Infrared Sensor gives the following data:
DataNumericValuesNotes
Proximity Numeric0 to 100The relative distance to an object in front of the sensor. 0 means very close, and 100 means far away.
Tips and Tricks
The Proximity value does not correspond directly to a specific distance. The value will depend on the color and material of the object in front of the sensor, and other factors.
The Infrared Sensor cannot detect Proximity to an object that is very close to the sensor (closer than about 1 cm or half an inch).
The Beacon mode of the Infrared Sensor also provides Proximity data, but only for detecting proximity to the IR Beacon. See Using the Infrared Sensor Beacon Mode for more information.
Examples Using the Infrared Sensor in Proximity Mode
Some examples of how you can use the Infrared Sensor in Proximity mode are below.
Example 1: Stop Driving Before Reaching a Wall
This program will make a robot drive forward until the Infrared Sensor detects that it is close to a wall or other object. After the driving starts, the program uses the Wait block in the Infrared Sensor – Compare – Proximity mode to wait for the Proximity to be less than 35 before stopping the robot.
Tips and Tricks
The distance that the robot stops before reaching an object will depend a lot on the color of the object. This is because light colored objects reflect (infrared) light better than dark objects.
Tips and Tricks
Remember to use the On mode of the Move Steering block when you want to drive while waiting for a sensor.
Example 2: Slow Down when Approaching a Wall
This program makes a robot gradually slow down as it approaches a wall or other object. It uses the Infrared Sensor block in the Measure – Proximity mode to get the Proximity on a Data Wire. This value is used for the Power input of the Move Steering block, and the process is repeated in a Loop so that the speed is continuously adjusted based on the Proximity.
Infrared Sensor Proximity Mode Blocks and Modes
The table below shows all of the programming blocks and modes that you can use with the Infrared Sensor in Proximity mode.
BlockModeUse
Wait Infrared Sensor – Compare – ProximityWait for the Proximity to reach a specified value.
WaitInfrared Sensor – Change - ProximityWait for the Proximity to change by a specified amount.
Loop Infrared Sensor – ProximityRepeat a sequence of blocks until the Proximity reaches a specified value.
Switch Infrared Sensor – Beacon ProximityChoose between two sequences of blocks depending on the Proximity.
Infrared SensorMeasure - ProximityGet the Proximity value on a Numeric data wire.
Infrared SensorCompare – ProximityCompare the Proximity to a threshold, and get the result on a Logic data wire.
IR Proximity Mode
Quick links