IR Sensors & Robot Alignment

Estimating distance using Sensors Reading

5 short-range IR sensor namely A0, A1, A2, A3, A5 are used during the construction of the robot. 1 long range IR sensor namely A4, is also used.

The graph below shows the non-linear graph obtained from the measurement of each IR sensor.

Two methods can be used to estimate the distance.

  • Polynomial Equation using trend line (Used order 4 for best accuracy). The approximate distance is shown in the area under the graph.
  • Linear Interpolation using lookup table.

Linear Interpolation method to determine distance

For faster computation of the estimation of distance on the Arduino board, interpolation is preferred over the polynomial equation. Interpolation estimates the distance based on the analog readings from the sensor. To estimate the distance, the respective lookup table for each IR sensor is created by measuring the analog values of the sensor at an interval of 5cm using the analogRead() function. The output of the sensor readings is normally affected by external noise. Hence, a median filter is designed to obtain “middle” values from 31 samples of the sensor reading.

To estimate the distance, the respective lookup table for each IR sensor is created by measuring the analog values of the sensor at an interval of 5cm using the analogRead() function. The output of the sensor readings is usually affected by external noise. Hence, a median filter is designed to obtain “middle” values from 31 samples of the sensor reading.

Insertion Sort algorithm was used to sort the 31 samples.

The simplified steps are described below:

1) Collect 31 samples of analog reading to an array using Arduino’s analogRead() function.

2) Sort the array of size 31 from ascending to descending using insertion sort.

  • Place an obstacle 5cm away from the sensor.
  • Create a for loop which loops from i = 0 to n.
  • Swap the ith element with the (i+1)th element if (i+1)th element is smaller. Repeat until the array is sorted in order.
  • Take the 16th element as the median from the array of size 31.
  • Repeat the above-mentioned steps until 40cm for short range sensor and 60cm for the long-range sensor.

The lookup Table of Sensor A0 is shown below:

Using the lookup table, linear interpolation estimates the distance of the robot from the sensor by connecting two adjacent known values with a straight line.

To illustrate the working principles of interpolation, let’s say the sensor read a value of 390. 390 falls between two known values from the lookup table 450 and 316.

The estimated distance can be calculated using the formula:

The approximate distance for analog reading of 390 is ≈12.23cm.

Robot Alignment

Placement of sensor Optimized for left wall hug and left wall calibration. Blind spots are mitigated by allowing short-range IR sensor to accurately detect obstacle from 10cm onwards and 15 cm onwards for long range IR sensor.
Alignment of direction
Alignment of distance
Validate Side

Alignment Calibration algorithm

Using the front and left sensors:

  1. Front alignment of direction
  2. Left alignment of direction
  3. If (left sensor is too close to wall or left sensor is too far from wall)
    1. Rotate Left
    2. Front alignment of direction
    3. Front alignment of distance
    4. Rotate Right
    5. Front alignment of direction
    6. Left alignment of direction
  4. Front alignment of distance