Introduction to Line Sensors

Objectives

  1. Understand how the line sensors differ from the IR and Sonar sensors
  2. Learn how to use the IntelliBrain bot line sensors
  3. Learn how to use the Line Sensors as input for the IntelliBrain bot

Important Words

  • line sensor

Before you start


Know how to create a project in Java IDE and RoboJDE (Getting Started Tutorial link)

Have basic familiarity with the IntelliBrain bot (Meet the IntelliBrain Bot Tutorial link)

Have completed both the Introduction to IR Sensors (link) and Introduction the Sonar (link) tutorials

Have a piece of white paper and a piece of black construction paper available


Using the Line Sensors


//picture of the line sensors on the IntelliBrain bot


The line sensors are of the same type as the IR sensors. Remember that these sensors are analog, which means they receive continuous data input. Each side of the robot has two sensors, the inner sensors will help it follow a line and the outer sensor will allow it to detect intesections (however, this will primarily be used in a later tutorial). Let's start making a new program named LineFollow now by bring in the imports we need.




import com.ridgesoft.intellibrain.IntelliBrain;

import com.ridgesoft.io.Display;

import com.ridgesoft.robotics.AnalogInput;  //the library we need to use the line sensors, the same on needed with the IR



public class LineFollow {



	public static void main(String[] args) {



		

	}

}



Now that we have the libraries we need, do you remember the next thing we need to do? You got it, create the line sensors by using the appropriate constructor. We'll do that now, creating a new sensor for each of the four line sensors on the robot. Don't forget to create the LCD display as well, that way we can use it later on in the program




import com.ridgesoft.intellibrain.IntelliBrain;

import com.ridgesoft.io.Display;

import com.ridgesoft.robotics.AnalogInput;



public class LineFollow {



	public static void main(String[] args) {



	AnalogInput leftOuter = new IntelliBrain.getAnalogInput(4);

	AnalogInput leftInner = new IntelliBrain.getAnalogInput(5);

	AnalogInput rightOuter = new IntelliBrain.getAnalogInput(7);

	AnalogInput rightInner = new IntelliBrain.getAnalogInput(6);



	Display display = IntelliBrain.getLcdDisplay();

		

	}

}



Now we have the four line sensors. Do you remember how we get information from an analog input? We use the .sample() method to obtain the value the sensor is reading at that time and we need a place to hold that value. We'll create a variable to hold the result from sampling the sensor next.




import com.ridgesoft.intellibrain.IntelliBrain;

import com.ridgesoft.io.Display;

import com.ridgesoft.robotics.AnalogInput;



public class LineFollow {



	public static void main(String[] args) {



	AnalogInput leftOuter = new IntelliBrain.getAnalogInput(4);

	AnalogInput leftInner = new IntelliBrain.getAnalogInput(5);

	AnalogInput rightOuter = new IntelliBrain.getAnalogInput(7);

	AnalogInput rightInner = new IntelliBrain.getAnalogInput(6);





	Display display = IntelliBrain.getLcdDisplay();



		



            int leftOutterSample = leftOutter.sample();

			int leftInnerSample = leftInner.sample();

    		int rightOutterSample = rightOutter.sample();

			int rightInnerSample = rightInnerSample();





			



		

		

	}

}





We're almost done. All we need to do now is to tell the program how long to be sampling (again we'll use a while(true) loop for this) and one other thing. The program is getting the information about the value the sensor is reading and storing it, but that isn't really of any use to us as we can't see it. Let's use the LCD display you created earlier to display the result of one of the sensors.




import com.ridgesoft.intellibrain.IntelliBrain;

import com.ridgesoft.io.Display;

import com.ridgesoft.robotics.AnalogInput;



public class LineFollow {



	public static void main(String[] args) {



	AnalogInput leftOuter = new IntelliBrain.getAnalogInput(4);

	AnalogInput leftInner = new IntelliBrain.getAnalogInput(5);

	AnalogInput rightOuter = new IntelliBrain.getAnalogInput(7);

	AnalogInput rightInner = new IntelliBrain.getAnalogInput(6);





	Display display = IntelliBrain.getLcdDisplay();



		while(true){



            int leftOutterSample = leftOutter.sample();

			int leftInnerSample = leftInner.sample();

    		int rightOutterSample = rightOutter.sample();

			int rightInnerSample = rightInnerSample();





			display.print(0, "RO" + rightOutterSample);

			



		}

		

	}

}



Now you've written the program to create the line sensors and to sample them, as well as display the value of one of them to the LCD display.


More Using the Line Sensors


  1. The code above displays the values for the right inner sensor and the right outer sensor. How would you get it to display the left sensor values? Go for it!

  2. Can you make the robot display both of the inner sensors? What about both the outer sensors?

  3. Do these values appear to mean anything?

  4. Place the robot on a piece of black construction paper. What are the values?

  5. Now place the robot on a piece of white paper. What are the values?

  6. Do the values make more sense now?

  7. How would you be able to tell if a sensor was on a line?