Introduction: Line Follower Robot

Picture of Line Follower Robot
I made a line follower robot with PIC16F84A microprocessor equipped with 4 IR sensors. This robot can run on the black and white lines.

Step 1: First Step

Before everything you must know how to make a Printed Circuit Board and how to solder components on it. You also need to know how to program a PIC16F84A IC.
Here are the links to good instructables about making a PCB and Soldering:

Step 2: Things You Need

Picture of Things You Need
To make this robot you need the following things:
  • Some copper board
  • Printed circuits
  • Saw
  • Sandpaper
  • Iron
  • Circuit board acid
  • 1mm drill
  • Soldering oil
  • Soldering wire
  • Soldering iron
  • Wire cutter
  • Some wire
  • 2x Plastic wheels
  • 1x Spherical front wheel
  • Glue
Circuit boards components:
  • A 4 AA battery holder
  • U1 = PIC16F84A Microcontroller + Socket
  • U2 = 7805 = 5V Voltage Regulator
  • U3 = LM324 Comparator
  • U4 = L298 Motor Driver + Aluminum Radiator
  • XT = 4MHz Crystal
  • C1 = C2 = 22pF Ceramic Capacitors
  • C3 = 100uF Electrolyte Capacitor
  • C4 = C5 = 100nF Ceramic Capacitors (104)
  • D = 8 x 1N4148 Diodes
  • R1 = 4.7K Resistor
  • R2 = R3 = 10K Resistors
  • R4 = R5 = R6 = R7 = 1K Resistors
  • R8 = 10K Resistor
  • R9 = 1K Resistor
  • R10 = R11 = 47K Resistors
  • R12 = R13 = R14 = R15 = 100ohm Resistors
  • R16 = R17 = R18 = R19 = 10K Resistors
  • RP = LP = MP = FP = 10K Potentiometers
  • L Motor = R Motor = 60rpm MiniMotors with Gearbox (6V)
  • R Sensor = L Sensor = M Sensor = F Sensor = TCRT5000 Infrared Sensors
  • ModeLED = LBLED = RBLED = Small Red LEDs
  • LFLED = RFLED = Small Green LEDs
  • Mode = Left = Right = Small Buttons
  • SW = Toggle Switch = On/Off Switch
  • J = Jumper = A piece of wire

Step 3: Making the Circuit Boards

Picture of Making the Circuit Boards

Print the circuits on a glossy paper with a laser printer. Cut copper boards, clear them with sandpaper and put the printed circuits on them. After pressing the hot iron on the boards remove the papers and soak boards in acid, wait till visible copper disappears. Wash the boards, drill the holes and clear them with sandpaper.

* I have only a symbolic diagram of the robot that you can see here.

Step 4: Soldering Components

Picture of Soldering Components

Solder all parts on the boards.
Be careful of the correct direction of components.
Use a socket for PIC16F84A IC.
Solder motors and battery holder on the back side of the Bottom board and put some pieces of paper around motors to avoid unexpected contacts in the circuit.
Solder C4 and C5 right on the motors.
Put a piece of paper among potentiometers legs to avoid contacts.

Step 5: Soldering All Together

Picture of Soldering All Together

Connect terminals with same name on the boards together by some piece of wires (You can use the extra legs of the other components).
Solder the Back board to the Top board.
Solder the Front board to the Top board.
Bend the wires and put three boards on the battery holder and solder Front board and Back board to the Bottom board (Use some long flexible wires to contact terminals of the Back and Bottom boards).
Connect + terminal on the Top board to the battery holders + pole.

Step 6: Wheels

Picture of Wheels

Connect 2 plastic wheels to the motors and cover them with a rubber band.
Attach a wheel to the Back board in front of the robot with some glue, I used a dead LED as front wheel but it makes the robot move slow and I recommend to use a spherical wheel.
Cover the gearboxes with sheets of thin plastic.

Step 7: Programming the Robot

Picture of Programming the Robot

Download the robot program (Code.hex) and program the PIC16F84A IC. Set the configuration word to 0x3FF2.

Step 8: RUN

Picture of RUN

Put 4 AA batteries into the battery holder, make a path, and turn on the robot.
If the robot does not work check soldering carefully.
Now you must adjust potentiometers to robot be able to detect black and white areas. Turn all potentiometers to leftmost position then turn back about 90 degrees to the right. Hold the robot on the line, move it over a turning if the motors state does not changed change the potentiometers value.
Now put the robot on the path to follow it.

Step 9: Custom Movement

You can define a custom movement for the robot by pressing the Mode button.
When the Mode LED is off the robot is on its default state.
After pressing the Mode button the Mode LED turns on, now you can hold the robot in different states and change the state of the motors depend on their default state by Left and Right buttons.
After pressing the Mode button again the Mode LED starts blinking, now you can hold the robot in different states and change the state of the motors depend on values of the sensors by the Left and Right buttons.
To switch to default state, press Mode button again.
There are four states for the motors:
  1. Default state
  2. Forward (Green LED is on)
  3. Backward (Red LED is on)
  4. Stop (Both Green and Red LEDs are on)

Step 10: How It Works?

This robot has 4 IR sensors that scan the path.
If the Right and Left sensors has same values and the values of them are different from the Middle or Front sensors the robot is on the line and motors running forward. Else the robot is out of line so the robot keeps moving till one of  the side sensors value changes then it turns to the direction that its sensor value changed.
You can read the program source code (Code.bas) to understand it better.


UtkarshVerma (author)2017-05-18

So finally I got my robot to work! Woohoo!!

Also I would like the author to add one detail to this instructable, its almost a hack.

"For those who are unable to get the TCRT5000 sensor. They can use regular 3mm IR LED and receivers. The only thing they havce to keep in mind is to wire the IR RECEIVER pins in the opposite manner of TCRT5000, that is , the GND of receiver should be connected to VCC and the +ve pin of receiver should be connected to the LM324 input pin.

Also keep in mind to place a piece of carboard between the pair to avoid direct contact." That is all.

I will post the pics of my robot soon!

vahidyou (author)UtkarshVerma2017-05-19


UtkarshVerma (author)vahidyou2017-05-19

thanks...but It's still not as quick receptive as yours. It strays away from the line a lot. Currently busy with setting the sensitivity of the sensors

UtkarshVerma (author)2017-05-08

So, I tried remaking the entire project back from scratch but I'm still facing the same problem I had faced in the last build. My motors are not starting up, even when I manually apply 5V to the inputs. What could this mean?

BTW, my motors are working fine. I tested them by individually powering them.

vahidyou (author)UtkarshVerma2017-05-10

If you apply 5V at motor driver inputs when PIC is not in the socket the problem is related to your motor driver. Send me clear photos of your robot.

UtkarshVerma (author)vahidyou2017-05-16

I hooked up everything. But when I turn on my robot, its left and right motors run in opposite directions, which leads to the robot rotating at one place. Do I have to configure something?

vahidyou (author)UtkarshVerma2017-05-16

move sensors over a black line in a white background (use paint not laser printer to draw the line), move it over a turning, and check the behavior of motors, maybe you must swap the wires of on of your motors. Also don't forget step 8.

UtkarshVerma (author)vahidyou2017-05-16

yes, i did step 8. For lines, i am using white chart papers pasted over black chart paper. The width of the track is 4cm. Also, when I turn my LFR on, both the Green LEDs should light up, but in my case only the left Green LED, and the Right Red LED light up, even when the robot is placed on a track. I also double checked my sensor and L324 wirings as well, no problem there.

I would like to add that I'm using a pair of IR LED and an IR Receiver instead of TCRT5000. I also took care in placing a piece of cardboard between the two IR LEDs as well. What am I missing?

vahidyou (author)UtkarshVerma2017-05-17

Remove the PIC and test your sensors one by one using a voltmeter. Black wire to GND, red wire to sensor pin on the PIC socket, hold sensor over a black area it must shows 0V and hold sensor on a white area it must shows 5V.

UtkarshVerma (author)vahidyou2017-05-11

Regarding that, I found out that the L298 IC I had bought was not working at all. So sad that I had to make this LFR twice just to find that one component was not working. I have reordered it and will post the results.

UtkarshVerma (author)vahidyou2017-05-11

Regarding that, I found out that the L298 IC I had bought was not working at all. So sad that I had to make this LFR twice just to find that one component was not working. I have reordered it and will post the results.

Also, I'm currently powering up my LFR using a 9V battery

EhsanI2 (author)2017-05-14

Hi, I'd like some help. I've been stuck on making this for ages and now I'm faced with a few problems.

Firstly, instead of sensors and L298 chip I have IR module and L298 module. as for the L298 I can use it directly instead of making it as you have, right? And for the sensors, they have 3 pins, VCC, GND and OUT - so I should just connect them directly according to the circuit diagram right?
My other problem is with burning the PIC; I'm using the G540 Genius Programmer and it's giving me an error: "No configuration word in the HEX file"

vahidyou (author)EhsanI22017-05-15

Hi, You can use the symbolic circuit diagram and connect the output pins of PIC directly to input pins of motor driver module. But for the IR modules if the output is digital you can connect it directly to PIC inputs, otherwise if the output is analog (I think it is analog) you must use a comparator for each sensor to convert signal to analog. Set the configuration word manually to 0x3FF2.

dausmus (author)2017-05-12

Hi, nice instructable. I like the simplicity that gives such control in different conditions. Elegant!

After reading the man, many, many comments asking you to do all their work for them, I am impressed with your patience.

All commenters- this is an Instructable. It's so you can build your own and change things as you wish. Don't ask authors to do your part of the effort for you. If you lack basic knowledge- go learn it, search online for instructions, ask a nearby friend- the author is not responsible for teaching you how to solder, etc. Perhaps there is an instructable for soldering, debugging, programming PICs. Go find those yourself, and only ask the author questions to clarify things *directly not clear* for the *specific project* they are presenting.

vahidyou (author)dausmus2017-05-13

Thank you.

dausmus (author)vahidyou2017-05-13

:-) No problem... you have more patience than I would have. a great big thumbs up for your patience.

dausmus (author)2017-05-12

For all those asking how to debug their "motors not running:

remove the PIC from its socket. Apply 5V to the driver chip pin and watch the motor turn in the correct direction. If the motors do the right hting, then you have a wiring problem or a PIC problem or a programming problem.

If the motors still don't do the right thing, then remove the driver chip and apply motor power directly to the two motor leads (+ to one, - to the other). If you don't first remove the driver chip, you will damage it! If the motors spin appropriately then you have a wiring problem or a driver chip problem. Not too many things for you to check. If the motors don't spin, then you have a motor problem or a motor-power wiring or battery problem. Simple- just spend your OWN time checking your wiring, soldering, copper traces, and doing proper testing.

vahidyou (author)dausmus2017-05-13

A very good and clear step by step troubleshooting. Thank you a lot dausmus.

dausmus (author)vahidyou2017-05-13

You are welcome! Keep up the great instructables!

MegaDAS made it! (author)2017-04-28

A step by step guidance to make LINE FOLLOWER ROBOT, follow this project that provides Codes and circuits to make your own robot


Watch the complete project video from here:

TorgnyA (author)2017-03-24

Awesome project, very efective LF and the home made design rocks, keep it up!

vahidyou (author)TorgnyA2017-03-25


iamnajerah (author)2017-03-17

Hi may I ask if can I use 5 channel line tracker sensor with h-bridge and aceduino (arduino clone)? I have project and need to do the line follower.

vahidyou (author)iamnajerah2017-03-18

Yes, It's a new project, with new sensor arrangement, new processor, ...

iamnajerah (author)vahidyou2017-03-18

How can I do that? I mean 3channel line tracker sensor?

vahidyou (author)iamnajerah2017-03-19

Just add two more sensors ans connect them to the microcontroller using a circuit i used for each sensor, then add them to your program and change the code to use them.

Christian JamesC2 (author)2017-03-16

good day sir,

can i replaced pic 16f877a instead of pic16f84a because there is no available stock in our market...

thank you sir

yes, you can use any microcontroller but you must change the PCB and you need a little changes in the program.

Christian JamesC2 (author)2017-03-07

hi sir, just wanna ask if the motor drive that you used which is L298 can be replace with L293D? and does all the LED's have a specific function?

Yes, why not?

yes, you can. front led is the state indicator and the 4 back leds are motors indictors. you can omit motors leds.

hi sir instead of using pcb can i mount all the components in breadboard just in case there is something i want to change in the circuit?

Christian JamesC2 (author)2017-03-13

sir i don't see the motor driver in the circuit? do you have a complete circuit diagram sir with the motor driver included? :)

No, I have not. See the below comment, you can find useful diagrams there.

Christian JamesC2 (author)2017-03-07

sir can i replace the motor driver L298 with L293D?

reknit (author)2016-11-16

Sir, where is the LS port the bottom board? I cant find it in the pdf that you have given' thanks

vahidyou (author)reknit2016-11-17

Beside L Sensor

klogdonio (author)vahidyou2016-11-28

thanks sir' can I use 1/2W resistors instead of 1/4W?

vahidyou (author)klogdonio2016-11-28


klogdonio (author)vahidyou2016-11-30

sir, can you please show the actual picture on how you solder the rear part of the car? the one with the motor driver part. And also the connections of the batteries and the motors cause I can't figure it out.. thanks!

vahidyou (author)klogdonio2016-12-01

I just have the photos that exists here, solder terminals with the same name together. The circuit diagram of L298 motor driver (you can find it in above comments) can help you a lot.

klogdonio (author)vahidyou2016-12-01

Sir, does the motors will start when I placed the battery supply on the circuit board even though there is no PIC? I'm curious if the circuit that I built is already functioning even there is no program yet. thanks'

vahidyou (author)klogdonio2016-12-02

no, the PIC activates the motors.

klogdonio (author)vahidyou2016-12-10

sir what is the used of 4 variable resistors? can you please send the schematics of the front board? is the led on the comparator will light when I ON the circuit? thanks'

vahidyou (author)klogdonio2016-12-11

please read the steps 8, 9 and 10.

klogdonio (author)vahidyou2016-12-02

is your 4 batteries connected in series?

vahidyou (author)klogdonio2016-12-02

yes and just end points used for powering, midpoints a just for fastening battery holder to the pcb. you can ignore them.

klogdonio (author)vahidyou2016-12-09

sir, the motors aren't working.. what could be the problem?

About This Instructable



Bio: I'm a mechanical engineer, and I like computer programming, mechanics, electronics and specially the robotics.
More by vahidyou:Serial Port Over WiFiCheap Logic AnalyzerCheap STK500 AVR programmer for Atmel Studio
Add instructable to: