03 Laboratory Exercise 1
03 Laboratory Exercise 1
Rocabo jonray
Laboratory Exercise
IR Sensors: Line Follower
Objective:
Requirements:
Sensor Pins
The 3-channel Line sensor P6 has an analog comparator to change analog voltage appearing as
its input into a single-bit digital logic signal.
The reference voltage is fed to the positive input of the comparator. If the analog input fed
through the input exceeds the refer voltage, the comparator output switches to logic LOW, or else,
it assumes a logic HIGH state.
The sensitivity of the three comparators can be independently set by adjusting their reference
voltage through their corresponding adjustable trimmers.
A 3-channel analog comparator is a typical analog interface circuit. It can also be used with other
sensors with 0~5VDC output range functioning as a single-bit ADC.
Here are the following line sensor pin assignments:
Pin 5 = Left Line Sensor
Pin 6 = Center Line Sensor
Pin 7 = Right Line Sensor
The void setup will be used to specify the pinMode of the line sensors which are all INPUT. The
configuration of the line sensors in the void loop() or a function will be based on the set if-else
condition such as:
if(digitalRead(LN) == 0 && digitalRead(RN) == 0){ //indicates that all IR detected a
black surface, thus
forward();
}
Line B
2. Call on the instructor to demonstrate the exercise before submitting a PDF copy of the
code on eLMS. Ensure that each member submits.
#defin
e MS
12
//
Middle
Sensor
#define LS 13 // Left sensor
#define RS 11 // Right sensor
void setup()
{
Serial.begin(9600);
pinMode(MS, INPUT);
pinMode(LS, INPUT);
pinMode(RS, INPUT);
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(RM1, OUTPUT);
pinMode(RM2, OUTPUT);
}
void loop()
{
{
digitalWrite(LM1, LOW);
digitalWrite(LM2, HIGH);
digitalWrite(RM1, LOW);
digitalWrite(RM2, LOW);
Serial.println("Left");
}
else if(!digitalRead(LS) && digitalRead(RS)) // turn
right
{
digitalWrite(LM1, LOW);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, HIGH);
Serial.println("Right");
}
else if(!digitalRead(LS) && !digitalRead(RS)) // turn
right
{
digitalWrite(LM1, LOW);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, LOW);
}
}
delay(5);
}
3.
GRADING RUBRIC
Excellent Good Fair Poor
Criteria Points
4 3 2 1
The students did The student The student The student
Completeness
all missed a few of missed most of the missed all of the /20
(x5) the requirements. the requirements. requirements. requirements.
The code is The code is The code is The code is
Coding complete and complete but properly incomplete and
/20
(x5) properly improperly structured but improperly
structured. structured. incomplete. structured.
The robot traced The robot traced The robot The robot
Consistency all line tracks with all line tracks traced one (1) traced one (1)
/20
(x5) excellent with good line track with line track with
consistency. consistency. excellent good
consistency consistency
Total Score /60