Distance IR Bricklet


  • Measures distances up to 150cm with IR light
  • Sensor can be changed
  • Output in 1mm steps (12bit resolution)


The Distance IR Bricklet can be used to extend the features of Bricks by the capability to measure distances. Sharp analog infrared proximity sensors can be attached to the Bricklet. After configuring the attached sensor you can read out the measured distance in millimeters. With configurable events it is possible to react on changing distances without polling.

Infrared sensors with different distance ranges are available in the shop:

Typically these types of sensors are used in robotics to measure distances for mapping or localization purposes. But you can also use this sensors in other applications, such as a finding out if a door is opened or closed.

Technical Specifications

Property Value
Sensor GP2Y0A41SK0F or GP2Y0A21YK0F or GP2Y0A02YK0F
Current Consumption See sensor datasheet

Depends on attached Sharp IR Sensor:

  • GP2Y0A41SK0F: 4cm - 30cm (1.57" - 11.81")
  • GP2Y0A21YK0F: 10cm - 80cm (3.94" - 31.50")
  • GP2Y0A02YK0F: 20cm - 150cm (7.87" - 59.06")

in 1mm steps, 12bit resolution

Dimensions (W x D x H) 45 x 13 x 5mm (1.76 x 0.51 x 0.19")*, fits on backside of sensor
Weight 2g*

* without cable and sensor


Test your Distance IR Bricklet

To test a Distance IR Bricklet you need to have Brick Daemon and Brick Viewer installed. Brick Daemon acts as a proxy between the USB interface of the Bricks and the API bindings. Brick Viewer connects to Brick Daemon. It helps to figure out basic information about the connected Bricks and Bricklets and allows to test them.

Connect the Distance IR Bricklet to a Brick with a Bricklet Cable (see picture below).

Distance IR Bricklet with infrared sensor connected to Master Brick

If you connect the Brick to the PC over USB, you should see a new tab named "Distance IR Bricklet" in the Brick Viewer after a moment. Select this tab. If everything went as expected you can now see the measured distance of the sensor, the output voltage of the IR distance sensor and a graph that shows the distance over time. In the image below we slowly moved a hand away from the sensor and to the sensor again.

Distance IR Bricklet in Brick Viewer

After this test you can go on with writing your own application. See the Programming Interface section for the API of the Distance IR Bricklet and examples in different programming languages.

Configure Infrared Sensor

The supported infrared sensors simply produce an output voltage based on the measured distance. This voltage is measured by the ADC of the connected Brick. To compute the corresponding distance to this voltage a voltage/distance mapping is needed. This mapping specific to the selected sensor type is stored on the Distance IR Bricklet. If you want to use an IR distance sensor not directly supported by us, you have to calibrate this voltage/distance mapping yourself.

Changing the Voltage/Distance Mapping

To write the voltage/distance mapping you have to connect the Bricklet with a Brick to your PC with has Brick Daemon and the Brick Viewer installed and running.

Press "connect" in the Brick Viewer and you should see the Distance IR tab. Click on it.

Select the "Distance IR Bricklet" tab, press the "File.." button and choose a voltage/distance mapping file. After this press the "Save" button to write the data onto the Bricklet. The sampling points from the mapping file are interpolated by a spline to get equidistant sampling points for the whole measurement range of the sensor..

After this press the reset button on the Brick or power cycle to load the newly stored voltage/distance mapping.

Available Voltage/Distance Mappings

We provide the voltage/distance mappings for the following sensors:

Type Range Mapping File
GP2D120* 4cm - 30cm (1.57" - 11.81") Download
GP2Y0A41SK0F 4cm - 30cm (1.57" - 11.81") Download
GP2Y0A21YK0F 10cm - 80cm (3.94" - 31.50") Download
GP2Y0A02YK0F 20cm - 150cm (7.87" - 59.06") Download

* is no longer sold, replaced by GP2Y0A41SK0F

You can write your own voltage/distance mapping for a sensor we currently do not offer. Or you can modify an existing mapping file to achieve a better quality of your sensor.

A voltage/distance mapping file consists of comments (lines beginning with #) and lines containing one <distance in cm>: <analog value in mV> tuple each. Look in the provided files above to get an idea.


A laser-cut case for the Distance IR Bricklet is available.

Case for Distance IR Bricklet

The assembly is easiest if you follow the following steps:

  • Screw spacers to the Bricklet,
  • screw bottom plate to bottom spacers,
  • build up side plates,
  • plug side plates into bottom plate and
  • screw top plate to top spacers.

Below you can see an exploded assembly drawing of the Distance IR Bricklet case:

Exploded assembly drawing for Distance IR Bricklet

Hint: There is a protective film on both sides of the plates, you have to remove it before assembly.

Programming Interface

See Programming Interface for a detailed description.

Language API Examples Installation
C/C++ API Examples Installation
C# API Examples Installation
Delphi/Lazarus API Examples Installation
Java API Examples Installation
JavaScript API Examples Installation
LabVIEW API Examples Installation
Mathematica API Examples Installation
MATLAB/Octave API Examples Installation
Perl API Examples Installation
PHP API Examples Installation
Python API Examples Installation
Ruby API Examples Installation
Shell API Examples Installation
Visual Basic .NET API Examples Installation
Modbus API    


The distances are wrong

This can have different causes. The Sharp IR sensors require 5V power supply. If the connected Brick is powered over USB, 5V may not be reached. The reason for this is a voltage drop about 0.5V caused by protection diodes on our products. You can use a stack supply, e.g. the Step-Down Power Supply to provide the sensor with 5V and get a better distance reading.

Another cause can be a calibration problem. First of all you should check if the calibration for the correct infrared sensor is installed (see here) and calibrate the ADC of your Brick (see here).

If the distance measurements are still not precise enough, you have to write a voltage/distance mapping that is specific for your device. The voltage/distance mapping files provided by us are averaged over several sensors.