AVR Line Follower


The purpose of this document is to help you build a Line Following Robot.

Starting with an overview of the system the document would cover implementation details like circuits and algorithms, followed by some suggestions on improving the design.


What is a line follower?

Line follower is a machine that can follow a path. The path can be visible like a black line on a white surface (or vice-versa) or it can be invisible like a magnetic field.

Why build a line follower?

Sensing a line and maneuvering the robot to stay on course, while constantly correcting wrong moves using feedback mechanism forms a simple yet effective closed loop system. As a programmer you get an opportunity to ‘teach’ the robot how to follow the line thus giving it a human-like property of responding to stimuli.

Practical applications of a line follower: 

Automated cars running on roads with embedded magnets; guidance system for industrial robots moving on shop floor etc.


  • Knowledge of basic digital and analog electronics. (A course on Digital Design and Electronic Devices & Circuits would be helpful)
  • C Programming
  • Sheer interest, an innovative brain and perseverance!


I started with building a parallel port based robot which could be controlled manually by a keyboard. On the robot side was an arrangement of relays connected to parallel port pins via opto-couplers. 

The next version was a true computer controlled line follower. It had sensors connected to the status pins of the parallel port. A program running on the computer polled the status register of the parallel port hundreds of times every second and sent control signals accordingly through the data pins. 

The drawbacks of using a personal computer were soon clear – 

  • It’s difficult to control speed of motors 
  • As cable length increases signal strength decreases and latency increases.
  • A long multi core cable for parallel data transfer is expensive.
  • The robot is not portable if you use a desktop PC.

The obvious next step was to build an onboard control circuit; the options – a hardwired logic circuit or a uC. Since I had no knowledge of uC at that time, Iimplemented a hardwired logic circuit using multiplexers. It basically mapped input from four sensors to four outputs for the motor driver according to a truth table. Though it worked fine, it could show no intelligence – like coming back on line after losing it, or doing something special when say the line ended. To get around this problem and add some cool features, using a microcontroller was the best option.

The AVR microcontroller:

“Atmel's AVR® microcontrollers have a RISC core running single cycle instructions and a well-defined I/O structure that limits the need for external components. Internal oscillators, timers, UART, SPI, pull-up resistors, pulse width modulation, ADC, analog comparator and watch-dog timers are some of the features you will find in AVR devices. AVR instructions are tuned to decrease the size of the program whether the code is written in C or Assembly. With on-chip in-system programmable Flash and EEPROM, the AVR is a perfect choice in order to optimize cost and get product to the market quickly.”
- http://www.atmel.com/products/avr/

Apart form this almost all AVRs support In System Programming (ISP) i.e. you can reprogram it without removing it from the circuit. This comes very handy when prototyping a design or upgrading a built-up system. Also the programmer used for ISP is easier to build compared to the parallel programmer required for many old uCs. Most AVR chips also support Boot Loaders which take the idea of In System Programming to a new level. Features like I2C bus interface make adding external devices a cakewalk. While most popular uCs require at least a few external components like crystal, caps and pull-up resistors, with AVR the number can be as low as zero!

Cost: AVR = PIC > 8051 (by 8051 I mean the 8051 family)

Availability: AVR = PIC <8051

Speed: AVR > PIC > 8051

Built-in Peripherals:

This one is difficult to answer since all uC families offer comparable features in their different chips. For a just comparison, I would rather say that for a given price AVR = PIC > 8051.

Tools and Resources:

8051 has been around from many years now, consequently there are more tools available for working with it. Being a part of many engineering courses, there is a huge communitiy of people that can help you out with 8051; same with books and online resources. In spite of being new the AVR has a neat tool chain (See ‘References and Resources‘). Availability of online resources and books is fast increasing.
Here, 8051 > AVR = PIC