Here we will be building yet another project with AVR Atmega16 Microcontroller. If you are new to AVR microcontrollers then you can refer to previous AVR projects and tutorials.
Building a robot is always a thrill for all electronics hobbyists. And this thrill can be maximized if the robot can automatically do some things without any external instructions. One of the most commonly built robot by electronics beginners is Line Follower Robot. As the name suggests robot will follow line drawn on the surface. The line need not be a straight line. Also, lines can be of any colours.
We previously built Line Follower Robot projects using different Controllers:
- Line Follower Robot using 8051 Microcontroller
- Line Follower Robot using PIC Microcontroller
- Line Follower Robot using Arduino
- Line Follower Robot using Raspberry Pi
- Line Follower Robot Using MSP430 Launchpad
Today we will use AVR microcontroller to build a Line follower Robot.
Mostly IR sensors are used to detect lines. The IR sensors are good in detecting white or black surfaces. Although you can use other sophisticated sensors which will be able to detect all colours and can make a robot which can follow all colour lines. The robot should be able to detect line even if the path is altered by changing the angle and keep following the line. Also, it should stop wherever the stop zone comes in the line.
Line follower robots are used extensively now a days in manufacturing industries, medical, domestic applications and goods warehouse. The robots are not limited to only these applications and can extend its applications in many future applications.
Concept of Line Follower Robot
The IR sensors are key player in this project. IR sensors are placed in front side of the robot to track the drawn black line and the surface. The robot is placed in between the line and with the help of IR sensors the robot keeps track of the line. IR sensors feedback the reading to microcontroller and with the help of IR reading, the microcontroller move motors left side or right side and again brings the robot to the path.
Line Follower Robot is able to track a line with the help of an IR sensor. This sensor has a IR Transmitter and IR receiver. The IR transmitter (IR LED) transmits the light and the Receiver (Photodiode) waits for the transmitted light to return back. An IR light will return back only if it is reflect by a surface. Whereas, all surfaces do not reflect an IR light, only white the colour surface can completely reflect them and black colour surface will completely observe them as shown in the figure below. Learn more about IR sensor module here.
Now we will use two IR sensors to check if the robot is in track with the line and two motors to correct the robot if its moves out of the track. These motors require high current and should be bi-directional; hence we use a motor driver module like L293D. We will also need a Microcontroller like ATmega16 to instruct the motors based on the values from the IR sensor. A simplified block diagram of the same is shown below.
These two IR sensors will be placed one on either side of the line. If none of the sensors are detecting a black line then AVR microcontroller instructs the motors to move forward as shown below
If left sensor comes on black line then the microcontroller instructs the robot to turn left by rotating the right wheel alone.
If right sensor comes on black line then the microcontroller instructs the robot to turn right by rotating the left wheel alone.
If both sensors comes on black line, robot stops.
This way the Robot will be able to follow the line without getting outside the track. Now let us see how the circuit and Code looks like.
Components Required
- DC Gear Motors(2 units)
- IR sensor module(2 units)
- L293D Module
- Wireless Power Source(e.g. Battery, Power bank)
- Robot Chaises
- Atmega16 Microcontroller IC
- 16Mhz Crystal Oscillator
- Two 100nF Capacitors
- Two 22pF Capacitors
- Push Button
- Jumper Wires
- Breadboard
- USBASP v2.0(To program Atmega16)
Circuit Diagram
Connect all the components as shown below in the Circuit Diagram
Programming Atmega16 for Line Follower Robot
Here the Atmega16 is programmed using USBASP and Atmel Studio7.0. If you don’t know that how Atmega16 can be programmed using USBASP then visit the link. Complete Program is given at the end of the project, just upload the program in Atmega16 using JTAG programmer and Atmel Studio 7.0 as explained in previous tutorial.
We have tried to keep the code as short and simple as we can. So we are using Macros and Special function registers in this code.
if(bit_is_clear(PINA,leftSen)){ // check if left sensor is OFF
This statement checks if the PA0 where left sensor is connected is LOW or HIGH.
If you want to learn more about this statement and other macros then go to this link
There are four conditions that we are following to read trough IR sensors. IR sensors are named according to their placement in frontside of the Robot. The left IR is Left sensor and right IR is right sensor. The following conditions will decide the movement of robot.
We have written the code according to above conditions. Only change is that we are using only two input pins of the L293D to drive both motors.
Complete code with a demonstration Video is given below.