How to build a Line Following Robot 3 – Program the pic using C programming.

In this post I am going to explain the major part of your robot building process. let’s moving to the coding part. In order to program your robot you will need to get inputs from your sensors and make decisions and give output signals to the motor controlling unit. Well for this project we will be using a pic micro controller. (16F877a)

When you give inputs to the pic make sure that you provide it as a pulse.(exact voltage as 5V) use CD4093 kind of IC  for this purpose.

To write the c program I have used the IDE mikroC. To insert the program to the pic I have used picstart plus.

Before start the coding please check the clock rate is correct according to the controller you use.

when assigning ports it can be done in this way,
PORTA=0×03;
what happens there is port numbers will assigned values according to the bit pattern of the hex value.
For example above 0×03=00000011 so port number 6 and 7(ports started from 0 to 7.total 8 ports) will be assigned 1 and others will assigned 0.
PORTA=0x0a;
a means decimal 10 which means 0x0a=00001010 in binary. So in A ports 4 and 6 will be assigned to 1.

Or else you can do it in this way which will be easy to understand
PORTA.F1=1;
which will assign A’s port 1 to 1.
PORTA.F6=1;
which will assign A’s port 6 to 1.

Use either method and take inputs and make the outputs.

void main() {
TRISD = 0×00; //initiating port D for outputs
TRISB = 0xFF; //initiating port B for inputs

Pwm1_Init(5000); //initiating pwm 1
Pwm2_Init(5000); //initiating pwm 2
Pwm1_Start();
Pwm2_Start();

while(1){

if((PORTB.F1==0)&&(PORTB.F2==0)&&(PORTB.F3==0)){   // check the sensors like this and take relevant action.

Pwm1_Change_Duty(150);
Pwm2_Change_Duty(150);
}
………
// like that you can complete the algorithm

}
}

See you soon with next post.

How to build a Line Following Robot 2 – Motor controlling unit

Well, the motor controlling circuit with L293D is simple as follows. The line follower can turn left or right by changing wheel speeds. There for a simple control mechanism will be enough.

Pin 4 and 5 controls left motor while pin 6 and 7 controls the right motor.

H-Bridge IC


High Left

High Right

Low Left

Low Right

Description

On

Off

Off

On

Motor runs clockwise

Off

On

On

Off

Motor runs anti -clockwise

On

On

Off

Off

Motor stops or decelerates

Off

Off

On

On

Motor stops or decelerates

If you need to give pwm(pulse wave modulation) signal separately to each motor , you can disconnect pin 1 and 9 from +2V and give pwm1 to pin 1 and pwm2 to pin 9.

In next post we will discuss how to program the pic to follow the line.

How to build a Line Following Robot 1 – Identifying the line

To follow the line robot need to identify the line first. Well there are few things you can do to identify a black line on white background or vice versa. One way is use LDR array and tracks the light reflection level. Black line will not reflect the light as white color. Or you can use IR beam. In this post I am going to discuss how we can use IR beams to identify the line. Black color will reflect the IR beam but white will not. Setting up your sensors will depend on your design. To keep the things simple you can arrange them linear. To gain speed you can arrange them to an arrow shape. In this example we will use 3 IR sensors and locate them as an arrow. There are several IR types to make the following circuit work you will need 3mm IR receivers. For IR emitters we can use both 3mm and 5mm.

If the width of the line to be followed is 2cm, you can go for the following set up.

Circuit diagram for the IR unit as follows.

The IC LM324 can handle 4 IR sensors. We need only 3 to track the line we will use the 4th sensor to identify obstacles.

We will see how to make the circuit to control the motors in next post.

In to the Robotics

As moving to the final year of my BSc reading I had the opportunity to take robotics as an elective subject. Even though I was an IT student I have choose this subject because I love electronic gadgets and robots very much. Actually the subject is fine than I thought it in the first hand. Later on I was assigned to assignment .The objective is to build a line following robot using a pic. It was a group assignment and i was assigned to a group with some enthusiastic guys. As we work on the assignment we had few problems with pic programming. As usual we did google but strangely there was nothing on google .I said “nothing” because even there were content we could not understand it. More or less what I have felt is that the people who knew this subject are not willing to help much. So here I am going to explain how to build a simple line following robot. My next posts will be a step by step guide to build a solution to a line following robot. I will keep the content as simple as possible in both software and hardware. But if you don’t know how to identify the pins of a led and to program a simple hello world program in c this guide will not help you at all. First of all we need to identify, why we build this robot? What are the requirements? What are the technologies that going to use? By analyzing all those things, a design should be made.

Following videos shows few simple robots which we can get an idea how to build your own one.

A simple moving robot

A line following robot

A balancing robot

Follow

Get every new post delivered to your Inbox.