You are on page 1of 13


TITLE 2-Way Sound Sensitive Line Follower

Made under the supervision of Mr. Tarique Aziz Research Engineer Robosapiens Technologies Pvt. Ltd

Made by Abhishek Das SIP/10/2096 June, 2011

I would like to thank Mr. Tarique Aziz for his help throughout the term of this project. I am indebted to him, for his thoughtful supervision and clear advice. My family and friends have also made this an enjoyable task as a result of both their personal support and the comments that only friends can make.

Table of Contents

Acknowledgements Table of Contents 1. Introduction 1.1. Objectives 1.2. Project Overview 2. Components Used 2.1. DC Geared Motors 2.2. IR Sensors 2.2.1. IR LED 2.2.2. Photodiode 2.2.3. Operational Amplifier 2.3. Motor driver IC (L293D) 2.4. AVR Microcontroller (ATmega8) 3. Working 4. Algorithm 5. Source Code 6. References and Resources

2 3 4

11 11 12 13

1. INTRODUCTION 1.1. Objectives

Following were the main objectives of the project. 1. To develop a line following robot that follows a black path on white background, unaffected by any stray sounds, and stops at the end. 2. To make the robot turn around and return back as a line follower when a sound is produced.


Project Overview

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. Sensing a line and manoeuvring 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. The principle of the line follower is based on sensing the background surface making use of IR sensor. Basically IR sensor takes input by detecting the reflection of the IR rays from the surface and accordingly gives its output to the motors.

2. COMPONENTS USED 2.1. DC Geared Motors

In our line follower DC geared motors are used. WHY DC MOTOR? Easy to control Require only two signals To change the direction of rotation, just reverse the polarity Speed can be controlled by the voltage USE OF GEARS To provide enough torque Increases the torque at the expense of speed


IR Sensors

Sensors are basically electronic devices which are used to sense the changes that occur in their surroundings. The change may be in colour, temperature, moisture, sound, heat etc. They sense the change and work accordingly. IR sensors consist of emitter and detector. Emitter emits the IR rays and detector detects it. The IR sensor basically consists of three components: IR LED (emitter) Photodiode (detector) Operational Amplifier (LM358)



IR LED is a light emitting diode which emits IR radiations. The basic function of the emitter is to convert electricity into light. It works on the principle of recombination of the electron-hole pair. As in the conduction band of a diode, electrons are the majority carrier and in the valence band, holes are majority carrier. So when an electron from a conduction band recombines with a hole of valance band, some amount of energy is released and this energy is in the form of light. The amount of energy released depends upon the forbidden energy gap. The IR Led has two legs, the leg which is longer is positive and other leg is negative.



The photodiode is a p-n junction diode which is connected in reverse bias. The basic function of the detector is to convert light into electricity. As its name implies, it works effectively only when a certain number of photons or certain amount of light falls on it. When no light is falling on the photodiode it has infinite resistance and acts

as an open switch but as the light starts falling on the photodiode, the resistance decreases and when full intensity of light is incident on the photodiode then its resistance becomes zero and it starts acting like a closed switch.


Operational Amplifier

It is a DC-coupled high gain amplifier with differential inputs and single output. Typically the output of the op-amp is controlled by either negative feedback or positive feedback. Due to the fact that it performs several operations like addition, subtraction, multiplication, integration etc, it is named as operational amplifier. It has two inputs, inverted (Pin 2) and non-inverted input (Pin3). The signal which is applied to the inverted input gives output 180 degree out of phase with input whereas in the non-inverted input gives output in phase with that of input. Op-amp has a variety of uses in different electronics devices. In the line follower it is used in the comparator mode. The op-amp IC which is used here is LM358, which is an 8-pin IC having two inbuilt op-amps. In the comparator mode, the reference voltage is set at the inverted input pin and then it is compared with the input at non inverted pin. As the voltages at two input pins of op-amp is compared, as the voltage at Pin 3 exceeds the reference voltage at Pin 2 the output of the comparator becomes high (5 V) otherwise it becomes low (0 V). The reference voltage at Pin 2 is set with the help of variable resistor.

Internal block diagram of LM358 IC

Circuit diagram of IR sensor


Motor Driver IC (L293D)

L293D IC is a dual H-bridge motor driver IC. One H-bridge is capable of driving a DC motor bidirectionally. L293D IC is a current enhancing IC. As the output from the sensor is not able to drive motors by itself so L293D is used for this purpose. L293D is a 16 pin IC having two enable pins which should always high to enable both the H-bridges.

Pin Diagram of L293D


AVR Microcontroller (ATmega8)

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. - Apart from 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 Cs. 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 Cs require at least a few external components like crystal, caps and pull-up resistors, with AVR the number can be as low as zero!



The robot uses IR sensors to sense the line. The output of the sensors is an analog signal which depends on the amount of light reflected back, this analog signal is given to the comparator to produce 0s and 1s which are then fed to the C. When a sensor is on the line it reads 0 because rays are not reflected back and when it is off the line it reads 1 because reflected rays are incident on the photodiode.

1. If both sensors read 1, go straight. 2. If left sensor reads 0 and right sensor reads 1, turn left. 3. If right sensor reads 0 and left sensor reads 1, turn right. 4. If both sensors read 0, stop and wait for sound. 5. If motors are not running and sound is detected, turn around. 6. Go to step 1


#include <avr/io.h> #include <util/delay.h> void main () { int left, right, sound; DDRB = 0xff; DDRC = 0x00; while (1) { left = PINC & 0b0100000; right = PINC & 0b0010000; sound = PINC & 0b0000001; if (left==0b0100000 && right==0b0010000) { PORTB = 0b00001001; _delay_ms(50); } if (left==0b0000000 && right==0b0010000) { PORTB = 0b00000101; _delay_ms(50); } if (left==0b0100000 && right==0b0000000) { PORTB = 0b00001010; _delay_ms(50); } if (left==0b0000000 && right==0b0000000) { PORTB = 0b00000000; if (sound==0b0000001) { PORTB = 0b00001010; _delay_ms(100000); _delay_ms(100000); _delay_ms(100000); _delay_ms(100000); _delay_ms(100000); } } } }


Books: Robotics with AVR Toshendra K. Sharma Links: Atmel Corp. Makers of the AVR microcontroller One of the best sites AVR sites WinAVR An open source C compiler for AVR Robotics India An Indian site devoted to robotics. Must see Tools: AVR Studio Compiler: WinAVR Programmer: AVR Loader v1.1 (GUI based on AVRDude)