Line Following Obstacle Avoiding Maze solving Robot part 6
Continue from Part 5
-
Encoder program:
int
motor_left[] = {11, 10};
int
motor_right[] = {12, 13};
int
a, count2=0,count=0,count1=0;;
int
last=0;
float
t;
float
s;
void
setup() {
Serial.begin(9600);
for
(int i = 0; i < 2; i++)
{
pinMode(motor_left[i],
OUTPUT);
pinMode(motor_right[i],
OUTPUT);
}
pinMode(A1,INPUT);
pinMode(A3,INPUT);
//
initialize serial communication at 9600 bits per second:
//
Serial.begin(9600);
}
//
the loop routine runs over and over again forever:
void
loop() {
int
sensorValue = analogRead(A3);
int
sensorValue1 = analogRead(A1);
//
read the input on analog pin 0:
if(count>19)
{
t=millis();
t=t/1000;
Serial.println(t);
s=(220/t);
Serial.println("speed=");
Serial.print(s);
analogWrite(motor_left[0],
0);
analogWrite(motor_left[1],
0);
analogWrite(motor_right[0],
0);
analogWrite(motor_right[1],
0);
delay(5000);
}
analogWrite(motor_left[0],
150);
analogWrite(motor_left[1],
0);
analogWrite(motor_right[0],
150);
analogWrite(motor_right[1],
0);
if
(sensorValue1>600)
{
if(last==0)
{
count+=1;
last=1;
Serial.println(count);
Serial.println(sensorValue);
delay(2);
// delay in between reads for stability
}
}
if(sensorValue1<300)
{
if(last==1)
{
count1=1;
last=0;
//
Serial.println(count1);
//
Serial.println(sensorValue1);
delay(2);
}
}
//
print out the value you read:
}
-
LCD program:
#include
<LiquidCrystal.h>
//
initialize the library with the numbers of the interface pins
LiquidCrystal
lcd(6, 5, 4, 3, 2, 1);
void
setup() {
//
set up the LCD's number of columns and rows:
lcd.begin(16,
2);
//
Print a message to the LCD.
Serial.begin(9600);
}
void
loop() {
//
set the cursor to column 0, line 1
//
(note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0,
1);
//
print the number of seconds since reset:
lcd.print(millis()/1000);
int
leftValue = digitalRead(8); //left sensor
int
rightValue = digitalRead(9); //right
int
sensorValue = analogRead(A0); // obstacle
Serial.println(sensorValue);
Serial.println(sensorValue1);
if
(sensorValue>400 )
{
lcd.print("obstacal, left move");
}
else
if(leftValue=0)
{
lcd.print("left
move");
}
else
if (rightValue=0)
{
lcd.print("right
move");
}
else
{
lcd.print("strigh move, line following");
}
OVERVIEW
OF ROBOT:
-
Circuit connection of the LOM robot:
Sensor | Pin No | color |
Obstacle sensor |
A0
5V
GND |
Black
Red
Brown
|
Left IR sensor |
8
5V
GND |
Orange
Black
green |
Right IR sensor |
9
5V
GND |
Green
Black
orange |
Left encoder sensor |
A1
GND
5V |
White
Green
and blue
Orange |
Right encoder sensor |
A5
GND
5V |
White
Green
and blue
Orange |
-
Working model:
-
The working model of a line follower consists of two motors, one ATmega8 circuit board, two wheels, two IR sensors, LEDs, wires and power supply.
-
The IR sensors get the input and according to the program the LEDs glow depending on the input. The two motors rotate together in one direction to go forward or backward. For taking a right turn, the motor at right side stops and left side one continues to rotate. This rotation depends on the program which gives instructions to the motor depending on the input that sensor gives.
-
IR sensors provide the input, motors give the output and the wheels make the robot to follow a line.
-
Follower robot is a mobile machine that can follow a path. The path can be a visible black line on a white surface.
-
The IR sensors receive an analog signal that depends on the intensity of light reflected by the black line of emitted beam by the LEDs.
-
These signals are sent to the ADC comparator which creates digital signals that are sent to Microcontroller.
-
The microcontroller gives instructions to motor to perform work.
-
The LCD display can display the obstacle detection and actuation of left motor and right motor.
-
Encoders read the motor speed and we can control the speed.
Comments