Line follower robot is a useful robot that is used in ware houses, industries, and stores etc, where it follows a dedicated path. 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. Also, it would stop while the designed spot is appeared.I used Direct port manipulation method (setting output pins directly) instead of using the Arduino default digitalWrite() functions. Using the port manipulation method in programming results in more space in HEX file and more speed while executingthe code.
For example:
Lets look at the blink example, this information is from the Arduino IDE
Sketch uses 928 bytes (2%) of program storage space. Maximum is 32,256 bytes.
Now using the following similar example (port manipulation )
<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>the above Sketch uses 488 bytes (1%) of program storage space. Maximum is 32,256 bytes.
See the figure above ( compare between the two similar sketches).
see a great introduction on https://www.arduino.cc/en/Reference/PortManipulat...
read more about Direct port manipulation, using the digital ports [tutorial part 3]
More about Bitwise maths and logic operators [tutorial part 4].
List of Components:
Or you just a hole car kit.
To make This Project doable for Every ages and make it easy as possible, I suggest to buy a hole kit from any supplier you like.
For example you can buy this Kit from Amazon Elegoo EL-KIT-012
you should buy extra IR sensors module from Amazon Infrared Black White Line Detection
you can see Instructions for Assembly
on ASSEMBLE ELEGOO SMART CAR ROBOT KIT V1.0
or on ASSEMBLE ELEGOO ARDUINO ROBOT VERSION 2.0
Remember: To buy extra IR sensors module If the kit comes with less than 5 IR sensor module.
you should place the the additional IR sensor besides others and try to fix them at the same level so they look as figure above).
You can use a glue gun as tool to fix the additional sensors.
Note: All the five sensors must be identical because some give a different output signal while detecting the same color of lines. If you have already in hands a different type dont worry you just need to take the inverter of the output signal.
let say A = 1| then Y=~A= 0. as we clearly deal with Boolean values. Another solution is change all sensors output signals from high to low manually and vise versa.
The detailed procedures as follow:
RT1Output Signals To pin A4.
The serial monitor shows the results upon moving the line tracker sensor in a white background to a black line. The sensor module has a HIGH output when subjected to the black line and LOW output signal when subjected to others whit or light color. See Figures above
I Figure out all the situations that i need for my designed path.which is when:
These are the basic cases above.
More possible case are found :
Two more un necessary cases: ( I Would include just in case happens)
Obviously we have 15 cases that we need to teach the robot to handle.
Note: Microcontroller Boards can be programmed direct by Port. Making a hole port as an input port or an output port.
Each port has 8 bits can be used separately one at a time or just make all the port as an input or output and that what I am going to do next for programming.
See Also (How to control arduino pins from registers without digitalWrite and digitalRead)
For Arduino Mega/uno see Port pin diagram above: for other board you may see the ports pin out and make change in connection only the sketch will work for sure, you just need to two different ports.
Note the two left motor Should Connect parallel to each other then to the motor drive as one. The same for the right motors.
Converting All binary Test Results To Decimal :
AS Shown in serial monitor only 5 Bits, Its actually 8 bits but in my Testing sketch I only identify for 5 inputs (5 sensors). Any way, I mean when serial shows 10000-- its in fact 00010000 as a binary number and 16 as Decimal ((you just add three zeros on the left )). If you want to Include more cases or want to add more sensors you can use any number converter calculator that can find online: Example
we have:
I Find a good pdf file explain the switch- case function that I`m using in programming see the attached file .
<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>Thanks to all. All are welcome to correct me if somethings go wrong. Feel free to ask questions.
All the time you spend reading my INSTRUCTABLES is appreciated.
Have fun:)