2. Infrared Sensor and its Calibration


1. Overview

In our project, Infrared sensors are used to provide precise measurement of distance from obstacles to the robot. . Two types of IR sensors are provided, which would send an infrared light and return a corresponding voltage according to the intensity of light reflected back. In order to get the distance in centimetres, sensor calibration are supposed to be done by mapping the returned voltage values into centimetres.

Sharp GP2Y0A21YKSharp GP2Y0A02

Figure 1: IR sensors (Short Distance on the Left and Long Distance on the Right)


2.Interface IR sensor with Arduino 

The IR sensors would return a corresponding voltage according to the intensity of light reflected back. This voltage value could be collected by analog input pins A0-A6 of Arduino Uno. In programming with the Arduino, analogRead() function is used to convert voltage values from 0-5 V to a integer from 0-1023. This integer value shows the distance from the obstacles to the robot.

Because, the sensor’s return voltage is unstable. It is necessary to collect multiple samples and preprocess the converted integers before mapping into distance. In our project, we collect 20 samples for one measurement and get the median number for distance calculation.

3.Sensor Calibration

In order to get the mearsure distance in centimetres, it is necessary to perform sensor calibration, which is mapping the returned voltage values into centimetres. Because the physical property of IR sensors, the returned voltage value is inversely proportional to the distance it senses. The integer value read from analog input pin is proportional to the voltage input. As a result, the integer value returned by analogRead() is inversely proportional to the distance measured.

An obstacles is put in front of the sensors from 10cm to 50cm and the measured integer values are kept for every 10 centimetres. Then a linear regression is performed for 1/measured_integer_values and corresponding distance. These are all implemented inside Matlab and the calibration result is shown in Figure 2 below.

IR sensor calibration

Figure 2: Calibration Result of IR Sensors

From Figure 2, whenever a integer value x is get from A0-A6, it would divide 1 and become 1/x. This 1/x would pass through the linear regression formula and convert to distance in centimetres.