Ali
Published © CC BY-SA

Line Follower Robot -Very Fast Using Port Manipulation

The presented robot captures line position with IR Sensors. If the robot get off the line it will U turn and back to the line again.

AdvancedFull instructions provided10 days3,277
Line Follower Robot -Very Fast Using Port Manipulation

Story

Read more

Code

Testing.ino

Arduino
No preview (download only).

Line_Tracker.ino

Arduino
No preview (download only).

Line_Tracker_For_Arduino_Uno.ino

Arduino
No preview (download only).

Code snippet #1

Plain text
<p>#include <br>#include 
 
void setup()
{
DDRB = B11111111;
}
void loop()
{
PORTB = PORTB | 0x20; // Writes PORTB5 low
_delay_ms(500);
PORTB = PORTB & 0xDF; // Writes PORTB5 high
_delay_ms(500);
}</p>

Code snippet #2

Plain text
<p>/* Line Follower robot - 5 sensors included/ direct port manipulation For Arduino Mega2560 created by: Ali Shwaiheen March 2018*/</p><p>#include  // header file to include input/output port
int  main(void)   //main function
{
unsigned char z;
DDRA = 0x00;  //set PORTA as input port  (DDRA = 0x00 DDRA=0b00000000) same command
DDRB = 0xFF;  //set PORTB as outputport</p><p>while(1) // create infinite loop(repeat forver)</p><p>{
    z=PINA; // read port A
    switch (z) // make decision
{
case (28): // Fully left 90 degrees
{
PORTB=0x09 ; // wirte High to PB0 & PB3
break;
}
case (30):// Fully left 90 degrees
{
PORTB=0x09;
break;
}
case (7):// Fully right 90 degrees
{
PORTB=0X06; // wirte High to PB1 & PB2
break;
}
case (15):// Fully right 90 degrees
{
PORTB=0x06;
break;
}
case (8):// Slightly left. 
{
PORTB=0x02; // wirte High to PB1
break;
}
case (12):// Slightly left.
{
PORTB=0x02;
break;
}
case (16):// Slightly left.
{
PORTB=0x02;
break;
}
case (24):// Slightly left.
{
PORTB=0x02;
break;
}
case (1):// Slightly Right.
{
PORTB=0x08;// wirte High to PB3
break;
}
case (2): // Slightly Right.
{
PORTB=0x08;
break;
}
case (3):// Slightly Right.
{
PORTB=0x08;
break;
}
case (6):// Slightly Right.
{
PORTB=0x08;
break;
}
case (4): // Straight
{
PORTB=0x0A; // wirte High to PB1 & PB3
break;
}
case (0):// U turn go back to the line
{
PORTB=0x09; // 09 is in hex numbers
break;
}
case (31)://STOP 
{
PORTB=0x00; // Write Low to PB0 to PB7
break;
}
}
}
return 0;
}</p>

Credits

Ali

Ali

4 projects • 3 followers
Electrical Engineer

Comments