Lab5 Mechatronics
Lab5 Mechatronics
MECHATRONICS
LAB-5
Navigating with Line Follower Sensors
Members:
Garret Turner
Mason Dupuis
Cheryll Reyes
Activity 1: Build and Test the Object Detectors
Output
Observations
The four sensors (L, ML, MR, R) register either 0 or 1, with ML consistently reading 1 while the others
remain 0. This indicates that the middle-left sensor is detecting an object. The objective of this activity
is to ensure that all four sensors are functioning properly and capable of detecting an object
Activity 3 Line following navigation with boebot
Program
#include <Servo.h> // Include the Servo library
Servo servoLeft;
Servo servoRight;
void setup() {
Serial.begin(115200);
Serial.println("Testing Line Follower - ML & MR Center Priority");
// Setup motors
servoLeft.attach(13);
servoRight.attach(12);
halt();
delay(1000);
void loop() {
// Read sensor values
byte left = digitalRead(sensorFarLeft);
byte midLeft = digitalRead(sensorMidLeft);
byte midRight = digitalRead(sensorMidRight);
byte right = digitalRead(sensorFarRight);
void halt() {
servoLeft.writeMicroseconds(1500);
servoRight.writeMicroseconds(1500);
}
Observations
The line-following robot has four infrared sensors that help it detect and stay on track. It moves straight
when the line is centered, makes small adjustments by turning left or right, and takes sharper turns
when only the far-left or far-right sensor picks up the line. If none of the sensors detect the line, the
robot comes to a stop. Its motors are controlled using PWM signals, which adjust speed and direction
for smooth movement
Activity 4. Exercise (Homework)
Program
#include <IRremote.hpp>
#include <Servo.h>
#include <IRremote.h>
Servo servoLeft;
Servo servoRight;
void setup() {
Serial.begin(115200);
Serial.println("Testing Line Follower");
// Setup motors
servoLeft.attach(13);
servoRight.attach(12);
halt();
delay(1000);
void loop() {
int detect = irDetect(2, 3, 38000); // Get IR detection result
Serial.println(detect);
// If object detected, set moving to true (start moving)
if (detect == 0 && !moving) {
Serial.println("Start moving");
moving = true;
delay(500); // Short delay to prevent flickering detection
}
void followLine() {
// Read sensor values
byte left = digitalRead(sensorFarLeft);
byte midLeft = digitalRead(sensorMidLeft);
byte midRight = digitalRead(sensorMidRight);
byte right = digitalRead(sensorFarRight);
void halt() {
servoLeft.writeMicroseconds(1500);
servoRight.writeMicroseconds(1500);
}
Observations
The robot remains still until its IR sensor detects an object. Once detected, it waits for two seconds
before starting to move. It then follows a black line using four infrared sensors at the front, with the
middle-left and middle-right sensors playing a key role in maintaining stability. If the robot loses track
of the line, it stops and resets its movement flag to zero