CSE204L Report
CSE204L Report
PROJECT REPORT
CSE 204 LAB
Autumn 2024
1. Project Title:
0. Faculty Information:
Name of Faculty (COURSE) Dr. Md Zahangir Alam
E-mail 2312257@iub.edu.bd
E-mail
1. Abstract:
The robot is built using an Arduino Nano, which controls the speed and movement of two DC
motors. It also includes two wheels, one caster wheel for support, a robot chassis, and
infrared 5 (IR) sensors. These sensors play a key role in detecting the line and helping the
robot navigate.
Five IR sensors detect the line by distinguishing between black and white surfaces. Black
surfaces absorb the infrared signals, while white surfaces reflect them. The Arduino
processes this information and adjusts the robot's movement moving forward, turning left,
or turning right to stay on track.
2. Introduction:
A line-following robot is a basic robot that moves along a path defined by the user. The
path is usually a black line on a white surface or a white line on a black surface. At the
front underside of the robot, an IR sensor array detects the line and sends signals to the
Arduino Nano. The Arduino's microcontroller analyzes these signals and determines the
robot's movements. The robot has a simple design with three wheels: one free-rotating
wheel in the front center and two motorized wheels at the back. The Arduino Nano controls
the motor driver, which directs the robot to move forward, turn left, or turn right, following
the line. LFRs are commonly used in robotics education to teach concepts like sensors,
control systems, and real-time processing. They also find applications in robotics
competitions and industrial automation, such as automated guided vehicles. These robots
demonstrate the principles of autonomous navigation and feedback-based control systems.
3. Challenges:
The LFR can only follow a black line about 1-2 inches wide on a white surface.
It is a simple robot, and adding extra sensors increases complexity.
It requires a clear black or white path because IR sensors rely on reflections from
specific surfaces.
It moves slowly and struggles with unstable paths, varying line thicknesses, or sharp
angles.
Possible Improvements:
The LFR can be upgraded to a four-wheel-drive system for better stability. Additional
sensors can help it detect and avoid obstacles while returning to the line afterwards. Speed
control features and high-performance motors can improve its efficiency. It should also be
able to handle sharper turns, navigate areas without a line, and follow broken or interrupted
lines.
4. Components Description:
The main components of a Line Following Robot (LFR) are essential for its operation,
enabling it to detect and follow a line autonomously. Here's a description of the key
components:
These sensors detect the line by measuring the difference in light intensity between the line
and the surrounding surface. Typically, the line is darker than the background, allowing the
sensors to distinguish the path from the surrounding area.
Infrared Sensor
b) Microcontroller:
The Arduino Nano V3 is a small, powerful microcontroller board with an ATmega328P chip.
It has 14 digital pins, 8 analog pins, and works at 5V with a 16 MHz speed. Its compact size
and USB mini-B port make it great for small projects like robotics and DIY electronics. It’s
easy to program using the Arduino IDE and works with many sensors and modules.
Arduino Nano
Motors drive the robot’s wheels, allowing it to move forward, backward, and turn. The speed
and direction of the motors are adjusted based on feedback from the sensors to keep the robot
aligned with the line. Typically, DC motors or servo motors are used for simple movements,
while stepper motors may be used for more precise control.
d) Motors Driver:
A motor driver is used to control the direction and speed of the motors. It acts as an interface
between the microcontroller and the motors. It typically receives commands from the
microcontroller and adjusts the voltage supplied to the motors. Common motor drivers like
the L298N or L293D can drive two DC motors and are often used in LFRs.
Motor Driver
e) Chassis:
The chassis is the frame or body of the robot that holds all the components together. It
provides structural support and houses the various electronics and motors. The chassis can be
made of plastic, metal, or lightweight materials like acrylic or aluminum, depending on the
robot's size and application.
Chassis
f) Power Supply:
The power supply provides energy to all the components of the LFR, including the
microcontroller, sensors, and motors. This could be a rechargeable battery pack, Li-ion
batteries, or AA batteries. The power supply needs to provide the correct voltage and current
for each component.
1500mAh Battery
g) Wires and Connectors:
Function: Wires and connectors are used to link the various components (sensors,
motors, power supply, microcontroller) together. They ensure electrical signals are
properly transmitted between the components.
Types: Jumper wires, soldered connections, and connectors are used based on the
complexity and design of the robot.
h) Control Algorithm:
Function: The control algorithm is the logic that determines how the robot will
respond to sensor input. It processes the sensor data and adjusts the motor's actions to
keep the robot on the line. Common algorithms include:
o Threshold-Based Logic: If the sensor detects the line (or loses it), the robot
makes a turn or adjusts.
o PID Controller: A more advanced control system that adjusts the robot’s path
by considering past, present, and future errors in the robot’s alignment with the
line.
Each of these components works together to ensure the robot's effective operation, allowing it
to autonomously follow a line by processing real-time sensor data and adjusting its movement
accordingly.
5. Connection:
The wire connections of a Line Following Robot (LFR) depend on the specific components
being used, such as the sensors, motor driver, microcontroller, and motors. Below is a basic
guide to connecting the main components:
VOut + +12V
VOut - GND
+5V 5v 5v
Nano Sensor
A0 OUT 1
A1 OUT 2
A2 OUT 3
A3 OUT 4
A4 OUT 5
L298n Nano
EN A D10
IN 1 D9
IN 2 D8
IN 3 D7
IN 4 D6
EN B D5
L298n to Motor
6. Code:
#include<NewPing.h>
#define TRIGGER_Pin 2
#define ECHO_Pin 3
#define ena 10
#define inA 9
#define inB 8
#define inC 7
#define inD 6
#define enb 5
#define MAX_DISTANCE 20
//NewPing sonar(TRIGGER_Pin, ECHO_Pin, MAX_DISTANCE);
void setup()
{
//Serial.begin(9600);
mot_init();
other_init();
ustad_samne_plastic();
}
void loop()
{
//void stop();
line_follow();
//wheel(200,200);
//Serial.print("Distance: ");
// Serial.print(distance);
// Serial.println(" cm");
ustad_samne_plastic();
Serial.println("Obstacle detected! Motors stopped.");
} else {
line_follow();
}*/
line_follow();
};
void other_init()
{
lastSensor=0;
lastError=0;
//Serial.begin(9600);
}
void mot_init()
{
pinMode(inA,OUTPUT);
pinMode(inB,OUTPUT);
pinMode(inC,OUTPUT);
pinMode(inD,OUTPUT);
pinMode(ena,OUTPUT);
pinMode(enb,OUTPUT);
digitalWrite(inC,HIGH);
digitalWrite(inD,HIGH);
}
if(lm>0)
{
digitalWrite(inC,HIGH);
digitalWrite(inD,LOW);
}
else if(lm<0)
{
digitalWrite(inC,LOW);
digitalWrite(inD,HIGH);
}
if(rm==0)
{
digitalWrite(inA,HIGH);
digitalWrite(inB,HIGH);
}
if(rm>0)
{
digitalWrite(inA,HIGH);
digitalWrite(inB,LOW);
}
else if(rm<0)
{
digitalWrite(inA,LOW);
digitalWrite(inB,HIGH);
}
if(lm>254) lm=254;
if(lm<-254) lm=-254;
if(rm>254) rm=254;
if(rm<-254) rm=-254;
analogWrite(ena,abs(rm));
analogWrite(enb,abs(lm));
int readSensor()
{
s[0]=digitalRead(irPins[0]);
s[1]=digitalRead(irPins[1]);
s[2]=digitalRead(irPins[2]);
s[3]=digitalRead(irPins[3]);
s[4]=digitalRead(irPins[4]);
s[0]=1-s[0];
s[1]=1-s[1];
s[2]=1-s[2];
s[3]=1-s[3];
s[4]=1-s[4];
int error,sum;
sum=s[0]+s[1]+s[2]+s[3]+s[4];
if(sum!=0)
{
error=(s[0]*10+s[1]*20+s[2]*30+s[3]*40+s[4]*50)/sum - 45; //set point 45 is for 10 array
sensor. Make sure to change the setpoint according to your sensor size.
}
else
{
error=420;
}
if(s[0]==1) lastSensor=1;
digitalWrite(inA, LOW);
digitalWrite(inB, LOW);
digitalWrite(inC, LOW);
digitalWrite(inD, LOW);
analogWrite(ena, -255);
analogWrite(ena, 255);
}
void line_follow()
{
int error,corr;
float p,d;
error=readSensor();
if(error==420)
{
if(lastSensor==1) wheel(-uturn,uturn);
else if(lastSensor==2) wheel(uturn,-uturn);
}
else
{
p=kp*error;
d=kd*(error-lastError);
corr=p+d;
// Serial.println(corr);
wheel(base_L+corr,base_R-corr);
if((error-lastError)!=0) delay(5);
lastError=error;
}
}
The Robot follows a specific line path simultaneously. This line follower robot with multiple
modes compatibility works perfectly fine as it is designed to do.And thus attempt will be made
to solve the unexpected and unauthorized parking problems in the resident area using a
prototype valet parking robot. The slot type and state will be identified using Sharp IR Sensor.
And simultaneously, we can operate the Buzzer beep operation, object identification, LCD
display, and robot direction control operation and will finally execute parking near the end.
8. Discussion:
This project successfully created a line-following robot that uses an Arduino Nano and IR
sensors to detect and follow a path. The robot's design, including motor drivers, wheels, and
control algorithms, worked well to ensure smooth movement along the line.
Some challenges faced included difficulty handling sharp turns, varied line thicknesses, and
sensor accuracy issues. These challenges highlighted the need for better sensor placement and
control tuning. The robot also depends on specific surface and line conditions, like clear black
and white contrasts.
To improve, features like obstacle detection, faster speeds, and better adaptability to different
paths could be added. Using advanced control algorithms like PID made the robot more
accurate, offering ideas for further development. Overall, this project demonstrated the basics
of robotics and how such systems can be used in tasks like automated parking and navigation.
8. Conclusion:
This project successfully built a line-following robot using an Arduino Nano and IR sensors.
The robot followed a path as designed, showing it could process sensor data and move
accurately. Although challenges like handling sharp turns and sensor accuracy were faced, the
project met its main goals and identified areas for improvement. Adding features like obstacle
detection, better speed, and adaptability can make the robot more effective in real-world
tasks. Overall, this project provided a strong understanding of basic robotics and autonomous
movement.