Dokumen - Tips Arduino Line Follower Robot
Dokumen - Tips Arduino Line Follower Robot
Dokumen - Tips Arduino Line Follower Robot
Overview
Arduino UNO board: This is the brain of this robot in which the
program is loaded to do the required functioning and is interfaced
with sensors and the motor driver to make the system work as
required.
Wheels: In it three wheels are employed, two at rear end and one at
front end. Rear wheels are attached with the motors and also control
the steering of robot. Front wheel is the loose steered wheel which
moves in the direction of the pressure applied to it.
Block diagram
Description
To make the robot follow the black line, IR sensors are employed with the
fact that black surface absorbs light and white surface reflects light.
The sensors are mounted on left front end and right front end of the robot
keeping the black line lies in between them. Until sensors are getting the
reflected light, the comparator sends logic 1 to the microcontroller and the
microcontroller in turn switches ON the motor associated with the sensor
and when any of the sensors comes up on the black line the
microcontroller stops the motor associated with that sensors and make the
robot to turn in the direction of the black line.
When the robot reaches end point and both the sensors are getting black
surface, robot stops.
Program:
/*left sensor attached to pin 0, right sensor attached to pin 2,
left motor attached to pin 5(+ve),6 and right motor attached to pin 7(+ve),8 and*/
int left_sensor=0;
int right_sensor=2;
void setup() {
pinMode(left_sensor, INPUT);
pinMode(right_sensor, INPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
void loop()
char value,v0,v2;
v0=digitalRead(0);
v2=digitalRead(2);
value=((v2<<2)|v0);
switch(value)
case 5
digitalWrite(6, LOW);
digitalWrite(8, LOW);
digitalWrite(5, HIGH);
digitalWrite(5, HIGH);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
break;
digitalWrite(5, LOW);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
break;
case 0:
digitalWrite(5, LOW);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
break;
}
Programming Digital I/O pins of Arduino UNO board:
Each pin is controlled by three commands associated with it which are
designated as:
pinMode()
digitalWrite()
digitalRead()
pinMode()
This configures the specified pin to behave either as an input or an output.
Syntax
pinMode(pin, mode)
Parameters
pin: the number of the pin whose mode you wish to set
mode: INPUT, OUTPUT.
Returns
None
Example
int ledPin = 13; // LED connected to digital pin 13
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
digitalWrite()
Write a HIGH or a LOW value to a digital pin.
If the pin has been configured as an OUTPUT with pinMode(), its voltage will
be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V
(ground) for LOW.
Syntax
digitalWrite(pin, value)
Parameters
pin: the pin number
value: HIGH or LOW
Returns
None
Example
Sets pin 13 to HIGH, makes a one-second-long delay, and sets the pin back to LOW.
void setup()
void loop()
digitalRead()
Reads the value from a specified digital pin, either HIGH or LOW.
Syntax
digitalRead(pin)
Parameters
pin: the number of the digital pin you want to read (int)
Returns
HIGH or LOW
Example
int ledPin = 13; // LED connected to digital pin 13
void setup()
void loop()