CxD Archive
Code: Robotics
Code: Robotics
  • Code Introduction
  • TUTORIALS
    • A. Meet Your Robot
      • A-1 Circuit Board
      • A-2 Motors and Wheels
      • A-3 Other Components
    • B. Hello World Test
      • B-1 Arduino Code Editor
      • B-2 New App Template
      • B-3 Global Variable
      • B-4 Setup Function
      • B-5 Loop Function
      • B-6 Upload App to Robot
      • B-7 Add Sound
      • B-8 Use Button
    • C. Driving and Turning
      • C-1 Driving
      • C-2 Turns (Pivoting)
      • C-3 Test Wheel Encoders
      • C-4 Drive for Specific Distance
      • C-5 Pivot By Specific Angle
      • C-6 Drive Straight Continuously
    • D. Detect Objects in Path
      • D-1 Test Mechanical Bumpers
      • D-2 Detect Collisions
      • D-3 Test Ultrasonic Sensor
      • D-4 Avoid Collisions
    • E. Detect Lines on Surface
      • E-1 Test IR Line Sensors
      • E-2 Follow Line
      • E-3 Avoid Line
      • E-4 Count Lines Crossed
      • E-5 Follow and Count Lines
    • F. Detect Other Conditions
      • F-1 Detect Surface Drop-Off
      • F-2 Test Accelerometer
      • F-3 Detect If Upside-Down
      • F-4 Detect If Bumped
  • REFERENCES
    • Arduino Language
    • Arduino Code Editor
      • Create New App
      • Save and Rename App
      • Include RedBot Library
      • Verify App Code
      • Upload App to Robot
      • Download Copy of App
      • Use Serial Monitor to View Data
      • Robot Demo App Template
    • Physical Inputs
      • Push Button (D12)
      • Mechanical Bumpers
      • IR Line Sensors
      • Wheel Encoders
      • Accelerometer
      • Ultrasonic Sensor *
    • Physical Outputs
      • LED Light (D13)
      • Speaker (Buzzer)
      • Motors
    • Robot Behaviors
      • Producing Alerts
      • Driving
      • Turning
      • Detecting Objects
      • Detecting Lines
      • Detecting Other Conditions
    • Navigation Modes
      • Distance Navigation
      • Line Counting Navigation
      • Line Following + Counting Navigation
      • Autonomous Navigation
  • LINKS
    • Robotics Project Guidebook
    • Arduino Create Web Editor
    • Arduino Language Reference
    • RedBot Experiment Guide
  • ELEGOO Experiments
    • Getting the Arduino IDE
    • Starting with the `techCar` Template
    • Template Code for techCar.ino
    • Template Experiments
    • Reinstall the Original Remote App Functionality, If Needed
Powered by GitBook
On this page
  • Tutorial Goals
  • How IR Line Sensors Work
  • Adding Lines to Surface
  • Making Lines with Tape
  • Drawing Lines with Marker
Export as PDF
  1. TUTORIALS

E. Detect Lines on Surface

PreviousD-4 Avoid CollisionsNextE-1 Test IR Line Sensors

Last updated 6 years ago

In this fifth tutorial, you'll learn how to make your robot detect lines on the surface by using its IR line sensors.

Tutorial Goals

The goals of this tutorial are to help you:

  • Program a robot app that uses the IR line sensors to follow a line

  • Program a robot app that uses the IR line sensors to avoid a line

  • Program a robot app that uses the IR line sensors to count lines crossed

How IR Line Sensors Work

The RedBot has three IR line sensors (left, center, and right) mounted at its front close to the surface. The bottom of each line sensor has an LED that transmits infrared (IR) light, which is invisible to the human eye. The bottom of each sensor also has an IR detector, which measures how much of the IR light is reflected back by the surface that the robot is driving on.

The amount of reflected IR light that is detected depends on several factors, including the color of the surface, as well as the distance between the sensor and the surface:

  • A light-colored surface reflects more IR light, while a dark-colored surface reflects less IR light.

  • If the surface is farther away from the sensor, the IR light becomes more scattered, and less IR light will be reflected back to the detector. Even a small increase in the distance between the sensor and the surface will significantly reduce the amount of reflected IR light.

The most common use of the IR sensors is to detect a line on the surface. The robot can be programmed to follow the line, avoid the line, count the number of lines crossed, etc.

The IR sensors can also be used to detect a surface drop-off (such as a stair step leading down, a hole in the surface, etc.). The robot can be programmed to avoid driving over the drop-off by stopping, changing direction, etc.

Adding Lines to Surface

Detecting lines with the IR sensors works best with a uniform dark line on a uniform light surface (or vice versa). The line also needs to be the right width: not too wide – but not too narrow. The line must be at least 0.25 inch wide – but no more than 1 inch wide.

Making Lines with Tape

If you have a light-colored hard surface (such as tile floor, etc.), black electrical tape works very well for making lines.

If you have a dark-colored hard surface, white electrical tape or white masking tape works well for making lines.

If you are using large sheets of paper (e.g., butcher paper, flip chart paper, etc.) for your surface, you might be able to use tape to make lines on the paper. However, be aware that black electrical tape is elastic and can pull on the paper (causing the paper to wrinkle, which interferes with line detection). To minimize this, use short sections of electrical tape, and avoid stretching the electrical tape when applying it to the paper.

Drawing Lines with Marker

If you are drawing lines on large sheets of paper, be sure to use a black felt-tip permanent marker (e.g., Sharpie) to make lines. Dry erase markers generally do not work well (pigment is not dark enough).

Also be sure to keep the paper as flat and smooth as possible when using (or when storing). Wrinkles or folds in the paper interfere with line detection. Paper can be rolled for storage, but roll carefully to avoid wrinkling.

Bottom View of IR Line Sensor