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,
what happens there is port numbers will assigned values according to the bit pattern of the hex value.
For example above 0x03=00000011 so port number 6 and 7(ports started from 0 to 8 ports) will be assigned 1 and others will assigned 0.
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
which will assign A’s port 1 to 1.
which will assign A’s port 6 to 1.

Use either method and take inputs and make the outputs.

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

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


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

// 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






Motor runs clockwise





Motor runs anti -clockwise





Motor stops or decelerates





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

Facebook Fake Friendships

Well, this post is about one of my experiment on facebook and the reasons why I am off from the facebook. Almost everyone have facebook accounts now. There are plenty of friends on everyone’s accounts. Some people adding friends blindly, some do concern the facts about friends when accepting requests. Same story for the privacy policy as well. Some don’t give any attention at all. In my case, I was on facebook since 2008. I have about 360 friends, all are known by me personally. 99% of my friends on facebook are known to by meeting them and I don’t add strangers at all. So basically I can call all of them as my friends. With spread of the facebook, people get use to it in order to keep in touch with people. Yes it is quite useful. You can chat with friends, send messages, group collaborations, flirting, games, apps blah blah blah. It looks cool in feature wise.

Apart from all those features and apps, my concern is on the application that is appeared on your top right hand side when you log on to facebook. Yes, it is the birthday reminder. With this tool the way that people wishing a friend on a birthday has changed. Earlier we meet friends, give a call and wish on his/her birthday. But with facebook people began to wish on facebook. Write on wall “Happy birthday!!!” , sending a message or flowers , teddy bears, etc. as a response normally  the receiver put a comment “Thank you” and later some people used to just click the “like” button also. Now you may think, so what? Anyway they have wished. Isn’t it? Yes. But the thing is how many people actually wish you in their heart? People just don’t care whose birthday is that. They just click on the birthday list appeared on facebook and do type “happy birthday” and do some ctrl+C and ctrl+V for the rest .Why I am saying so is in 2009 I got 2 wishes from facebook which looked very odd. Odd in the sense those two have wished someone else. They did wish for some other guy who had same first name as me. On that day I have informed those two that you have dialed the wrong number but in 2010 also I got the same result. That’s why I am saying that these facebook wishes are so FAKE. Some people do care but many would not do so. They are just clicking it.

According to my knowledge your best friends don’t need facebook to remember your birthday. But some friends that really care you may also use it too. This year I have removed my birthday from the was just to see whether anyone notice my birthday on facebook. As expected no one wished me on facebook. In 2010 there were 212 wishes on my wall and 2011 nothing. This idea was come to me after reading this post by one of my friend. A script to wish on facebook. Ya you don’t need to waste clicks. Just put a bot there. It will do. Actually I am not using facebook now. I just didn’t delete my account as few friends who went abroad still send messages to it. So, no more time wasting on fb things. I know that few real friends of mine forgot to wish me on my birthday because of the deletion the birthday on facebook but still I know they really caring so I don’t expect them to remember my birthday. Also I got handful amount of  wishes apart from family. So without facebook also people care for me. So I am really happy about myself. I must say that I really don’t expect that everyone should remember the friend’s birthdays but I really hate the fake wishes. At least now I don’t get any fake wishes 🙂

The story was well explained on this blog post “The Loser’s Script – How to wish facebook friends on their birthdays automagically in linux” so I don’t explain it anymore. Now I am only using twitter as a social network. Twitter was completely a different experience for me. Because of twitter I made lot of caring friends. Firstly added as strangers but later become very close friends. Lot of my followers has helped me when I need help. No time waste as we do in facebook. Most importantly some friends on twitter have found my birthday even when I have hid is from the internet. In twitter I feel that relationships are much more genuine than facebook clicks. They are just clicks. So that’s about it. Leaving facebook  has helped me to save time , save mind from stupid comments  ,posts ,useless tags ,etc but unfortunately removing birthday has reduced the number of birthday gifts I receive normally 😦  but I know who are the people who needs me , who cares me even without the wishes or gifts.

What I believe is the human feelings do have a value you can’t just let it to be clicked blindly. If you really want to wish someone. Do it by your heart .spend some time for the people that you care. Don’t act as caring and keep click on the like button. So adios facebook. I am not an active user anymore: D

Back on Track

This small note is to apologize all the people who came to visit this blog for regular updates. I could not write anything for years now. I don’t make any excuses as there can’t be any fair reason not to write a blog post for such a long time. Therefore I don’t make excuses. But I am trying to do one thing, post something regularly. Yes I will do that. This video has motivated me to start writing again. hope this will help you to change your attitudes 🙂


This small note is to apologize all the people who came to visit this blog for regular updates. I could not write anything for years now. I don’t make any excuses as there can’t be any fair reason not to write a blog post for such a long time. Therefore I don’t make excuses. But I am trying to do one thing, post something regularly. Yes I will do that. Keep in touch.

Airtel in to mobile broadband


I went to Airtel store at Galle road few weeks ago to find out what are the HSDPA packages they offer. I have used Mobitel and Dialog HSDPA packages early so I know both are not delivering what we expect. The problems within those providers I have already discussed in my early posts. Airtel staff is seems very friendly 🙂  you don’t have to wait much, the system is efficient. The lady who talked with me about their HSDPA packages told me the details. As she said the speed is fine but I can’t believe that this speed is a possible one, 7.2Mbps? But it is ok if it is at least around 1Mbps. I found that Airtel is offering the best charges in Sri Lanka, looks very cheap comparing to others. But the thing is they are not so assure about the signal strength, means they haven’t got great coverage. That’s a big problem because we buy mobile broadband to use when we travel so it is a considerable fact. Airtel have full coverage only on Colombo 😦 . Most importantly Airtel’s unlimited package is truly unlimited. No FUP (Fair User Policy) as Dialog. That’s looks very cool to me because I hate Dialog FUP. Dialog gave me a package called “Unlimited” but actually it is a 6GB package, I cant even brows when they cut the speed to GPRS 😦 . My friend bought an Airtel HSDPA connection a month ago, according to him the only problem is the signal strength which is not look consistent. Also they are not sale HSDPA modems at a discount as Dialog but also they have locked the network in their modem also just like what Dialog did. But if you already have a modem bought form Dialog you can just unlock it thanks to Seejay.

How to Unlock the Huawei E220 HSDPA modem

Here is the full details about the Airtel HSDPA packages , any users please do comment about the connection , signal strength of the area because we all need to know about the connection, to find out whether it is really useful to move to Airtel as they said 🙂

Package name

Celebration 300

Celebration 600

Celebration 600

Activation fee




Monthly commitment



Monthly rental


Free data bundle




Charges for usage above free bundle

0.5cent per 1KB

0.5cent per 1KB

Downlink speed




Upload Speed