Sunday, November 3, 2013

AVR Micro controller based Line Follower Robot using Infrared Sensor, Driver IC L293D/Relays & AVR Dev Board

Introduction:

This article presents the design and implementation of line follower robot using AVR Microcontroller. It is a machine that follows a line, either a black line on white surface or vise-versa. The path is sensed by the IR (Infra Red) sensors. The microcontroller controls two DC motors of robot to navigate through its path.

Basic Principle:

The basic principle involved in this is it captures the line position with IR sensors mounted at front end of the robot.  The block diagram of the line follower robot shows that, when the sensor senses the path, output will be 0s or 1s which are then fed to the microcontroller, and then the microcontroller decides the next move according to the program. When both the sensors are indicating low (0) then robot start moving on the black path, for white if it indicates high (1) then it moves along the path. 

Block Diagram



Mechanical parts:

Chassis    -    Buy from muincept.com
Castor Wheel    -    Buy from muincept.com
L-Clamp    -    Buy from muincept.com
Motor    -    Buy from muincept.com
Wheel    -    Buy from muincept.com
 


 Chassis:
Chassis, basically the frame of the robot on which motors and wheels are mounted and all the circuitry part is also placed on it.
AVR micro controller based line follower robot chassis

 Caster Wheel:
A Caster wheel is an undriven, single wheel that is designed to be mounted to the bottom of a larger object so as to enable that object to be easily moved. They are available in various sizes, and are commonly made of rubber, plastic, nylon, aluminum, or stainless steel, etc.
Caster Wheel

L-Clamp:

L-Clamp

 Wheel:

Wheel is a circular object that revolves on an axle and is fixed below a vehicle or other object to enable it to move over the ground.
Robot Wheels
 DC Motor:

DC Motors convert electrical energy (voltage or power source) to mechanical energy (produce rotational motion). They run on direct current.
DC Motor

Input and Output devices:

Battery Source    -    Buy from muincept.com
Voltage regulator    -    Buy from muincept.com
Sensor    -    Buy from muincept.com
Driver IC    -    Buy from muincept.com
AVR Microcontroller unit    -    Buy from muincept.com
Serial Cable    -    Buy from muincept.com

Source:

An ideal voltage source is a voltage source that maintains the same voltage across the source's terminals no matter what current is drawn from the terminals of the source or what current flows into the terminals.

DC source:

Direct current (DC) is the unidirectional flow of electric charge. Direct current is produced by sources such as batteries, solar cells, and commutator-type electric machines of the dynamo type, etc.

Voltage Regulator:

Voltage regulator, any electrical or electronic device that maintains the voltage of a power source within acceptable limits.

IC7805
IC 7805 is a 5V Voltage Regulator that restricts the voltage output to 5V and draws 5V regulated power supply.

Sensor:

IR reflective sensors have one emitter (IR LED) and one receiver (Phototransistor or photo diode. If we have white surface it reflects the light and it will sensed by the receiver, similarly if we have black surface it absorbs the light and receiver can not sense light.
Photo diode has property that if IR light fall on it its electrical resistance comes down (i.e. it comes down from 150kΩ to 10kΩ if no noise present).
IR Sensor
 Sample Calculation:                      
Say Receiver has resistance
Rs=150kΩ without light (on black surface)
Rs=10kΩ with light (on white surface)
The voltage that goes to comparator Without light: (on black surface)
Vp=(Rs÷(Rs+R))Vcc=150÷(150+10))*5=4.6875V
With light: (on white surface)
Vp=(Rs÷(Rs+R))Vcc=10÷(10+10))*5=2.5000V

Thus we get variation of voltage that is sensed by comparator IC (LM324).
This gives logical high or low according to input.

Comparator

Comparator is a device which compares two input voltages and gives output high/low. In circuit diagram it is normally represented by a triangle having- Inverting (negative) Input (-),Non Inverting (positive) Input(+), Vcc, Ground, Output.

Use of comparator in IR sensor

As above we see that two inputs are required for comparator. One input is from photo-receiver (like photo-diode), other is generated by us using potentiometer. The second voltage is also called as reference voltage for that sensor.


LM358The LM358 is a great, easy-to-use dual-channel opamp. LM358 applications include transducer amplifiers, DC gain blocks and all the conventional opamp circuits.

Driver IC:

L293D is a dual H-bridge motor driver integrated circuit (IC). Motor drivers act as current amplifiers since they take a low-current control signal and provide a higher-current signal. This higher current signal is used to drive the motors. L293D contains two inbuilt H-bridge driver circuits. In its common mode of operation, two DC motors can be driven simultaneously, both in forward and reverse direction. The motor operations of two motors can be controlled by input logic at pins 2 & 7 and 10 & 15. Input logic 00 or 11 will stop the corresponding motor. Logic 01 and 10 will rotate it in clockwise and anticlockwise directions, respectively.

Enable pins 1 and 9 (corresponding to the two motors) must be high for motors to start operating. When an enable input is high, the associated driver gets enabled. Similarly, when the enable input is low, that driver is disabled, and their outputs are off and in the high-impedance state.

AVR ATMega16 Microcontroller:

Microcontroller acts as the Brain of robot, which generates desired output for corresponding inputs. In present days, there are several companies that manufacture microcontrollers, for example ATMEL, Microchip, Intel, Motorola, Philips etc. We will be using ATMega16 microcontroller in our robot. ATmega16 is an 8-bit high performance microcontroller of Atmel’s Mega AVR family with low power consumption. Atmega16 is based on enhanced RISC (Reduced Instruction Set Computing) with 131 powerful instructions.
Most of the instructions execute in one machine cycle. Atmega16 can work on a maximum frequency of 16MHz. ATmega16 has 16 KB programmable flash memory, static RAM of 1 KB and EEPROM of 512 Bytes.

ATmega16 is a 40 pin microcontroller. There are 32 I/O (input/output) lines which are divided into four 8-bit ports designated as PORTA, PORTB, PORTC and PORTD.

ATmega16 has various in-built peripherals like USART, ADC, Analog Comparator, SPI, JTAG etc. Each I/O pin has an alternative task related to in-built peripherals.

AVR Pin Diagram

AVR Microcontroller Programmer Unit:

It is used to feed the .hex file from PC to AVR IC
muincept AVR Development board

Software Details:

The program code acts as the decision-maker embedded in the microcontroller i.e. it decides what will be the outputs for particular set of input combination. Programs for the AVR series of microcontrollers can be written in assembly (ASM) and C. AVR studio 4, Ponyprog etc. are some free development software’s for programming the ATMega16 Microcontrollers.

AVR Studio 4:

Atmel® Studio 4 is the integrated development platform (IDP) for developing and debugging Atmel ARM® Cortex™-M and Atmel AVR® microcontroller- (MCU-) based applications. The Atmel Studio 4 IDP gives you a seamless and easy-to-use environment to write, build and debug your applications written in C/C++ or assembly code.

AVR studio is an Integrated Development Environment (IDE) by ATMEL for developing applications based on 8-bit AVR microcontroller. Prior to installation of AVR Studio you have to install the compiler WinAVR. This will allow AVR Studio to detect the compiler.
Download from www.atmel.in/microsite/atmel_studio6/‎

Code for Line follower Robot:

#include<avr/io.h>                //Header file
#define sensor1 PA0                //Left Sensor
#define sensor2 PA1                //Right sensor
void sw();
int main(void)                //main function
 {
DDRB=0xFF;                //output pin high
DDRA=0xFC;                //input pin low
while(1)
{
PINA=0x03;                //initialize input pin high in pin register
sw();
}
}
void sw1()
{
if(bit_is_clear(PINA,sensor2))        //checks whether right sensor is low       
PORTB=0b00000000;                //both left and right side motor low if true
else
PORTB=0b00000001;                //right side motor turns on and left motor off if false       
}
void sw2()
{
if(bit_is_clear(PINA,sensor2))        //checks whether right sensor is low   
PORTB=0b00000010;                //right side motor turns off and left motor on if true
else
PORTB=0b00000011;                //both left and right side motor high if false
}
void sw()
{
if(bit_is_clear(PINA,sensor1))    //Checks whether left sensor is low
sw1();            //terminate to this function if true
else
sw2();            //terminate to this function if false
}

Ponyprog:

PonyProg is a serial device programmer software with a user friendly GUI framework available for Windows95/98/ME/NT/2000/XP and Intel Linux. Its purpose is reading and writing every serial device. At the moment it supports I²C Bus, Microwire, SPI eeprom, the Atmel AVR.

Serial Cable:

A serial cable is a cable used to transfer information between two devices using a serial communication protocol.

4 comments:

  1. i was willing learn this stuff since long time...this tutorial is so good and simple that i feel that i can give it a try now

    ReplyDelete
  2. atleast you should have shown a simulated circuit to help understand the code(which ports are input and which one is output port)

    ReplyDelete

You might also like