Follow Lines and Avoid Edges

In the "Try This" section of Use IR Sensors to Roam, you discovered that black electrical tape is nearly invisible to our IR sensor setup.  In the "Your Turn" section of the same page, you were challenged to adjust the robot's response to the two IR sensors' states, which created a new behavior — pursuing your hand.  Combining these two concepts opens up potential for interesting applications.

Follow Lines

The program "3 Roaming PropBoe-Bot.spin" causes the robot to drive forward if no obstacle is detected, turn away from an object detected with one IR sensor, and back up if an object is detected by both IR sensors.  By pointing the IR emitters and receivers downward towards the floor, the Propeller Boe-Bot can use this program to follow a wide black electrical tape stripe on a light-colored  surface.  The light-colored surface will reflect infrared light and be visible as an object to avoid.  But, the electrical tape will absorb infrared light and appear as an unobstructed path.

Recommended Materials:

(1) Roll of black vinyl electrical tape
(1) Large sheets of white poster board

  • Apply rows of electrical tape to the poster board to make a curving stripe at least 4 inches wide.
  • Point the IR emitters and receivers downward and outward as shown below.
  • Load "3 Roaming PropBoe-Bot.spin" into your robot,  set it on one end of the stripe, and let it go.
  • If your robot seems to see IR reflections too easily, try adjusting the angle of the IR emitters and receivers. 
  • You can also try replacing the IR emitters' 1 k-ohm resistors with 2 k-ohm resistors.

IR emitter and receiver on BOE Shield-Bot pointed downward to detect a drop-off

Avoid Edges

By reversing the logic in "3 Roaming PropBoe-Bot.spin" you can make the Propeller Boe-Bot avoid the edge of a table. The goal is for the robot to drive forward as long as it does see the floor, turn away from the side where one IR sensor does not detect an obstacle, and back up when neither IR sensor detects an obstacle.   This activity could be done on a tabletop, but results might be disastrous to your robot if something goes wrong.  It is easy, and much safer,  to simulate a table edge with electrical tape.

Recommended Materials:

(1) More black vinyl electrical tape
(1) More sheets of white poster board

  • Apply rows of electrical tape around the edges of a piece of poster board, with no white showing between, to make a border about 4 inches wide.

Rows of black electrical tape applied near the edges of white poster board simulate a drop-off

  • Save a copy of "3 Roaming PropBoe-Bot.spin" under a new name.
  • In the repeat loop, modify each drive.Wheels method call by changing all instances of 100 to -100, and changing all instances of -100 to 100:
  repeat                                              ' Main loop repeats indefinitely
    objectL := ir.Detect(13, 12)                      ' Check for left object
    objectR := ir.Detect(0, 1)                        ' Check for right object

    if objectL == 0 and objectR == 0                  ' If no surface detected
      drive.Wheels(-100, -100)                          ' ...go backward
    elseif objectL == 1 and objectR == 1              ' If both sensors detect surface
      drive.Wheels(100, 100)                          ' ...go forward
    elseif objectR == 1                               ' If only right detects surface
      drive.Wheels(100, -100)                         ' ...turn right
    elseif objectL == 1                               ' If only left detects surface
      drive.Wheels(-100, 100)                         ' ...turn left

    time.Pause(20)                                    ' Wait 20 ms & before repeating loop      

  • Upload the program and place your robot in the middle of the tape-bordered poster board. It should drive around the center but not over the tape.
  • If your robot seems to see IR reflections too easily, try adjusting the angle of the IR emitters and receivers.  You can also try replacing the IR emitters' 1 k-ohm resistors with 2 k-ohm resistors.