Let's Make Robots!

IR Sensor Info

IR Sensor Info

IR distance sensor - Sharp GP2YOA21YKOF
This sensor has a range of 10cm - 80cm. Approximately 4" - 32".
The sensor outputs an analog voltage based on the object distance. The
voltage ranges from 3v for a near object to .4v for a distant object.

The IR sensor is mounted on a a servo that sits on the rotating base.
This gives both an X and Y axis movement to the IR sensor. The base
rotation will sweep the sensor back and forth, across the width of the
bot platform. This will insure that the entire path width is clear. The
IR sensor is mounted on a servo that provides the Y Axis. This allows
for testing of drop offs and obstacles that are not on the floor.

The IR sensor is mounted in the 'vertical' position. That's due to two
reasons. 1) is using two servos for XY Axis panning. 2) The other is I have
zip fabricating skills. I'm currently using a USB interface bracket from
an old PC case as the mount.
Sensor reading averaging.

The best way to get reliable readings from the sensor is to take a series
of readings and average the results. This project will use the average of
20 readings as the final result. All readings are taken from the Arduino
A0 analog input.

Sensor positioning.
We have stairs in our home, this bot needs to avoid tumbling down a
stairwell. We have regular old walls and other various vertical obstacles
it needs avoid. The trick is we have furniture that blocks the path above
the floor level, like the base of an office chair.
So the challenge is making sure the Bot can proceed forward but not fall
down a hole while accounting for the wheel to wheel width of the platform.

I've attacked this challenge one step at a time. First step, find a
vertical sensor position that identifies a drop off while still giving
enough warning to avoid a vertical obstacle. To do this I put the bot
on my table and 'walked' the Y Axis servo through multiple positions and
took measurements. I started with the sensor in the full vertical
position, 90 degrees and then changed the angle 10 degrees at a time. In
my case that change was in a negative direction. Here are those findings.

Sensor Angle        Sensor Reading        Calculated Object Distance
    90                  Below 100               Sensor Docs say ~32"
    80                    80-105                    19"
    70                    200-205                    9.5"
    60                    300-310                    6"
    50                    395-405                    4.2"
    40                    485-495                    2.9"
    30                    545-555                    2"
    20                    580-585                    1.25"

The calculated distance is based on basic Right Triangle Trig. This
measurement correlates to where the beam will hit the floor.

I then did some more tabletop testing with the sensor at the 70 degree
angle. This allowed me to refine the obstacle detection portion of
the software and test the Calculated Object Distance.

Sensor Reading        Measured Object Distance
    >600                    3.5"
    >510                    4"
    >420                    5"
    >350                    6"
    >300                    7"
    >250                    8"
    >150                    9"
This testing was done with the goal of finding a minimum sensor reading
being that is stable. This will help define one part of a sensor reading
range that indicates a clear path. I.E. If the sensor reading drops below
a minimum there is a drop off. If it rises above a maximum the path is

Based on these readings and calculations I concluded that a vertical
angle of 70 degrees would give me a reliable enough reading to detect
drop offs and enough distance to detect vertical obstacles.
Testing of this angle proved to be very successful. The results can be
seen in the video Improved_Obstacle_and_Dropoff_Avoidance.   
Watching the video you can see that the Bot is hitting obstacles that
are off to either side. Now I need to figure out the details of sweeping
the sensor back and forth along the X axis.

Testing for obstacles across the whole width of the platform.
The main thing to figure out is how far to move the X axis servo in
order to have some confidence that the Bot wheels won't get hung up on
an obstacle. I did this by cutting a piece of card stock to the length
that was same as the Calculated Object Distance for the 70 degree sensor
angle. I fixed that to the top of the IR sensor mount and started
stepping the servo through its' angles 5 degrees at time. The testing
indicated that I use 60 degrees through to 135 degrees.

The next challenge is to test for obstacles that are at the same height
an above the platform. This requires moving the IR sensor vertically
as well as horizontally. Based on the current platform and IR sensor
height, the tallest part of the bot so far. We need to test the vertical
clearance at a max of 110 degrees. This means that once we take the
IR sensor servo higher than 90 degrees we no longer need to test for a
drop off. Now the software only needs to test for a sensor value reading
above 100.

For reference.
The X axis servo drives a base platform. Full deflection to the left is
0 degrees.
The Y axis servo drives the IR Sensor mount. The IR sensor is mounted
vertically. 0 degrees is full deflection looking down.