OBSTACLE DETECTION BASED ROBOT USING IR SENSORS A Mini Project report submitted in Partial fulfillment of the requirements For the award of degree of BACHELOR OF TECHNOLOGY In ELECTRONICS AND COMMUNICATION ENGINEERING By Under the esteemed guidance of Prof. M.V.H.BHASKARA MURTHY M.Tech (Ph.D) Department of E.C.E S.RAMAKRISHNA SAI V.CH.PAVAN KUMAR PATNAIK (08MP1A0450) (08MP1A0457) 1
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
OBSTACLE DETECTION BASED ROBOT
USING IR SENSORS
A Mini Project report submitted in
Partial fulfillment of the requirements
For the award of degree of
BACHELOR OF TECHNOLOGY
In
ELECTRONICS AND COMMUNICATION ENGINEERING
By
Under the esteemed guidance of
Prof. M.V.H.BHASKARA MURTHY M.Tech (Ph.D)
Department of E.C.E
S.RAMAKRISHNA SAI V.CH.PAVAN KUMAR PATNAIK
(08MP1A0450) (08MP1A0457)
L.HARISANKAR P.GANESH
(08MP1A0433) (08MP1A0439)
1
SRI VAISHNAVI COLLEGE OF ENGINEERING
SINGUPURAM, SRIKAKULAM, ANDHRA PRADESH.
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
2011
CERTIFICATE
This is to certify that the mini project work entitled “OBSTACLE
DETECTION BASED ROBOT USING IR SENSORS”, is a bonafide work done by
130 Powerful Instructions – Most Single-clock Cycle Execution – 32 x 8
General Purpose Working Registers
Fully Static Operation
Up to 16 MIPS Throughput at 16 MHz – On-chip 2-cycle
Multiplier.
High Endurance Non-volatile Memory segments.
8K Bytes of In-System Self-programmable Flash program memory
– 512 Bytes EEPROM ,1K Byte Internal SRAM
Write/Erase Cycles: 10,000 Flash/100,000 EEPROM –
Data retention: 20 years at 85°C/100 years at 25°C
Optional Boot Code Section with Independent Lock Bits
In-System Programming by On-chip Boot Program.
True Read-While-Write Operation.
17
Programming Lock for Software Security.
Peripheral Features.
One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture
Mode
Real Time Counter with Separate Oscillator – Three PWM Channels
8-channel ADC in TQFP and QFN/MLF package
6-channel ADC in PDIP package Six
Channels10-bit Accuracy Byte-oriented
Two-wire Serial Interface – Programmable
Serial USART
Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator
Special Microcontroller Features
Power-on Reset and Programmable Brown-out
Detection – Internal Calibrated RC Oscillator
External and Internal Interrupt Sources
Five Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-
down, and Standby
I/O and Packages
23 Programmable I/O Lines
28-lead PDIP, 32-lead TQFP, and 32-pad QFN/MLF
Operating Voltages
2.7 - 5.5V (ATmega8L)
4.5-5.5V (ATmega8)
Power Consumption at 4 MHz, 3V, 25C
Active: 3.6 mA
Idle Mode: 1.0 mA
Power-down Mode: 0.5 µA
2.1.2 A.V.R Description:
18
The AVR core combines a rich instruction set with 32 general purpose working
registers. All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU),
allowing two independent registers to be accessed in one single instruction executed in one
clock cycle. The resulting architecture is more code efficient while achieving throughputs up
to ten times faster than conventional CISC microcontrollers.
The device is manufactured using Atmel’s high density non-volatile memory
technology. The Flash Program memory can be reprogrammed In-System through an SPI
serial interface by a conventional non-volatile memory programmer or by an On-chip boot
program running on the AVR core. By combining an 8-bit RISC CPU with In-System Self-
Programmable Flash on a monolithic chip, the Atmel ATmega8 is a powerful microcontroller
that provides a highly-flexible and cost-effective solution to many embedded control
applications.
The ATmega8 AVR is supported with a full suite of program and system
development tools, including C compilers, macro assemblers, program debugger/simulators,
In-Circuit Emulators, and evaluation kits.
BLOCK DIAGRAM:
Figure 2.1 Block Diagram of Microcontroller-ATMEGA8
2.1.3 Architecture:
19
Figure 2.2 Architecture of ATMEGA8
2.1.4 PinDiagram:
20
Figure 2.3 Pin Diagram of ATMEGA8
2.1.5 Pin Description
VCC Digital supply voltage.
GND Ground.AREF AREF is the analog reference pin for the A/D Converter
ADC7.6 In the TQFP and QFN/MLF package, ADC7..6 serve as analog inputs to the A/D converter These pins are powered from the analog supply and serve as 10-bit ADC channel
AVCC
AVCC is the supply voltage pin for the A/D Converter, Port C (3.0), and
ADC (7.6). It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter. Note that Port C (5.4) use digital supply voltage, VCC.
RESET It is input. A low level on this pin for longer than minimum pulse
21
generates input.
Port B (PB7..PB0)
XTAL1/XTAL2/TOSC1/TOS2
Port B is an 8-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). Port B output buffers have symmetrical drive
characteristics with both high sink and source capability. As inputs,
Port B pins that are externally pulled low will source current if the pull-
up resistors are activated. The Port B pins are tri-stated when a reset
condition becomes active, even if the clock is not running .Depending
on the clock selection fuse settings, PB6 can be used as input to the
inverting.
Port C (PC5..PC0)
PC6/RESET
Port C is a 7-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port C output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port C pins that are externally pulled low will source current if the pull-up resistors are activated. The Port C pins are tri-stated when a reset condition becomes active, even if the clock is not running If the RSTDISBL Fuse is programmed, PC6 is used as an I/O pin
Port D (PD7..PD0) Port C output buffers have symmetrical drive characteristics with both high sink and source
2.2 POWER SUPPLY:
Power supply block consists of following units:
Step down transformer
Bridge rectifier circuit
Filter
Voltage regulators
Figure 2.4 A simple 5V DC Regulated Power Supply System
22
2.2.1 Step Down Transformer:
The step-down transformer is used to step down the supply voltage of 230v ac from
mains to lower values as the various IC’s used in this project require reduced voltages. The
transformer consists of primary and secondary coils. To reduce or step down the voltage, the
transformer is designed to contain less number of turns in its secondary core. The outputs
from the secondary coil which is centre tapped are the ac values of 0v and 12v. The
conversion of these ac values to dc values is done using the full wave rectifier.
Figure 2.5 Step down transformer
2.2.2 Rectifier Unit:
A bridge rectifier is an arrangement of four diodes connected in a circuit. That
provides the polarity of output voltage of any polarity of the input voltage. When used in
its most common application, for conversion of alternating current (A.C) input into direct
current (D.C) output, it is known as a bridge rectifier. The diagram describes a diode-
bridge design known as a full wave rectifier. This design can be used to rectify single
phase A.C. when no transformer centre tap is available. A bridge rectifier makes use of
four diodes in a bridge arrangement to achieve full wave rectification. This is a widely
used configuration, both with individual diodes wired as shown and with single
component bridges where the diode bridge is wired internally.
For both positive and negative swings of the transformer, there is a forward path
through the diode bridge. Both conduction paths cause current to flow in the same
direction through the load resister, accomplishing full-wave rectification. While one set of
diodes is forward biased, the other set is reverse biased and effectively eliminated from the
circuit.
23
2.2.3 Filter:
Capacitors are used as filters. The ripples from the dc voltages are removed and pure
dc voltage is obtained. The primary action performed by capacitor is charging and
discharging. It charges in positive half cycle of the ac voltage and it will discharge in
negative half cycle. So it allows only ac voltage and does not allow the dc voltage. This
filter is fixed before the regulator.
2.2.4 Regulator unit:
Regulator regulates the output voltage to a specific value. The output voltage is
maintained irrespective of the fluctuations in the input dc voltage. Whenever there are any
ac voltage fluctuations, the dc voltage also changes, and to avoid this regulators are used.
2.3 Motors
2.3.1 DEFINITION:
Motor is a device that creates motion, not an engine; it usually refers to either an
electrical motor or an internal combustion engine.
It may also refer to:
Electric motor, a machine that converts electricity into a mechanical motion
o AC motor, an electric motor that is driven by alternating current
Synchronous motor, an alternating current motor distinguished by a
rotor spinning with coils passing magnets at the same rate as the
alternating current and resulting magnetic field which drives it
Induction motor, also called a squirrel-cage motor, a type of
asynchronous alternating current motor where power is supplied to the
rotating device by means of electromagnetic induction
o DC motor, an electric motor that runs on direct current electricity
Brushed DC electric motor, an internally commutated electric motor
designed to be run from a direct current power source
Brushless DC motor, a synchronous electric motor which is powered
by direct current electricity and has an electronically controlled
24
commutation system, instead of a mechanical commutation system
based on brushes
o Electrostatic motor, a type of electric motor based on the attraction and
repulsion of electric charge
o Servo motor, an electric motor that operates a servo, commonly used in
robotics.
2.3.2 DC Motor
A DC motor is an electromechanical device that converts electrical energy into
mechanical energy that can be used to do many useful works. DC motors comes in various
ratings like 6V and 12V. It has two wires or pins. When connected with power supply the
shaft rotates. You can reverse the direction of rotation by reversing the polarity of input.
Figure 2.6 Dc Motor
Motor gives power to your MCU. Means power to do physical works, for example
move your robot. So it is essential to know how to control a DC motor effectively with a
MCU. We can control a DC motor easily with microcontrollers. We can start it, stop it or
make it go either in clockwise or anti clock wise direction. We can also control its speed but
it will be covered in latter tutorial. The design of the brushed DC motor is quite simple.
Permanent magnets
Electro-magnetic windings
2.3.3 Principle
When a rectangular coil carrying current is placed in a magnetic field, a torque acts on
the coil which rotates it continuously. When the coil rotates, the shaft attached to it also
rotates and thus it is able to do mechanical work.
25
Every DC motor has six basic parts -- axle, rotor (a.k.a., armature), stator,
commutator, field magnet(s), and brushes. In most common DC motors the external magnetic
field is produced by high-strength permanent magnets. The stator is the stationary part of the
motor -- this includes the motor casing, as well as two or more permanent magnet pole
pieces. The rotor (together with the axle and attached commutator) rotates with respect to the
stator. The rotor consists of windings (generally on a core), the windings being electrically
connected to the commutator. The above diagram shows a common motor layout -- with the
rotor inside the stator (field) magnets.
2.3.4 Construction:
Figure 2.7 Parts of Dc motor
Parts of a DC Motor:
Armature
A D.C. motor consists of a rectangular coil made of insulated copper wire wound on a
soft iron core. This coil wound on the soft iron core forms the armature. The coil is mounted
on an axle and is placed between the cylindrical concave poles of a magnet.
Commutator
A commutator is used to reverse the direction of flow of current. Commutator is a
copper ring split into two parts C1 and C2. The split rings are insulated from each other and
mounted on the axle of the motor. The two ends of the coil are soldered to these rings. They
rotate along with the coil. Commutator rings are connected to a battery. The wires from the
battery are not connected to the rings but to the brushes which are in contact with the rings.
26
Figure 2.8 Basic Commutator
Brushes:
Two small strips of carbon, known as brushes press slightly against the two split
rings, and the split rings rotate between the brushes. The carbon brushes are connected to a
D.C. source.
2.3.5 Working of a DC Motor
When the coil is powered, a magnetic field is generated around the armature. The left
side of the armature is pushed away from the left magnet and drawn towards the right causing
rotation.
Figure 2.9 A Simple Electric Motor
27
When the coil turns through 900, the brushes lose contact with the commutator and the
current stops flowing through the coil.
Direction of Rotation
A DC Motor has two wires. We can call them as positive terminal and negative
terminal, although these are pretty much arbitrary names (unlike a battery where these
polarities are vital and not to be mixed!). On a motor, we say that when the + wire is
connected to + terminal on a power source, and the - wire is connected to the - terminal
source on the same power source, the motor rotates clockwise (if you are looking towards the
motor shaft). If you reverse the wire polarities so that each wire is connected to the opposing
power supply terminal, then the motor rotates counter clockwise. Notice this is just an
arbitrary selection and that some motor manufacturers could easily choose the opposing
convention. As long as you know what rotation you get with one polarity, you can always
connect in such a fashion that you get the direction that you want on a per polarity basis.
Figure 2.10 DC Motor Rotation vs Polarity
Facts:
DC Motor rotation has nothing to do with the voltage magnitude or the current
magnitude flowing through the motor.
DC Motor rotation does have to do with the voltage polarity and the direction of the
current flow.
28
Motor Start and Stop:
Starting a motor is a very hazardous moment for the system. Since you have an
inductance whose energy storage capacity is basically empty, the motor will first act as an
inductor because current cannot change abruptly in an inductor, but the truth of the matter is
that this is one of the instances in which you will see the highest currents flowing into the
motor. Stopping the motor is not as harsh as starting. The reason why the motor stops so fast
is because as a short is applied to the motor terminals, the Back EMF is shorted. Because
Back EMF is directly proportional to speed making Back EMF = 0.
2.3.6Advantages and Disadvantages:
Advantages:
Easy to understand design
Easy to control speed
Easy to control torque
Simple, cheap drive design
Disadvantages:
Expensive to produce
Can't reliably control at lowest speeds
Physically larger
High maintenance
Dust
2.4 OBSTACLE SENSOR
Figure 2.11 Obstacle Sensor
29
This sensor is a short range obstacle detector with no dead zone. It has a reasonably
narrow detection area which can be increased using the dual version. Range can also be
increased by increasing the power to the IR LEDs or adding more IR LEDs
The photo below shows my test setup with some IR LED's (dark blue) as a light
source and two phototransistors in parallel for the receiver. This setup works like a first LDR
but with IR. It has a range of about 10-15cm (4-6 inches) with my hand as the object being
detected.
2.4.1 Circuit of obstacle sensors:
Starting from the left you can see two IR LEDs with a resistor and transistor in series.
The transistor allows the processor to turn the LEDs on or off. This is necessary to tell the
difference between the ambient IR from daylight and indoor lighting and the reflected light
from the LEDs that indicates the presence of an object.
Next we have two phototransistors in parallel with a 1M resistor in series. You could
use only one but I wanted to cover a wider area so my transistors will point in slightly
different directions. If either one detects IR it will allow more current to flow. Since
volts=current x resistance, even a small increase in current will create a reasonable increase
in voltage across the 1M resistor. Unfortunately the low input impedance of many A/D
converters will act like a small resistor in parallel with the 1M resistor and dramatically
reduce the output to the processor. This is where our BC549 transistor comes in to save the
day. In conjunction with the 1K and 10K resistors it amplifies the signal so that the analog
input on the processor gets a nice strong signal. The BC549 is not too critical and it has hfe
of 490 when measured with a multimeter. You should probably have hfe of at least 200-300.
This has the advantage that you can flex the leds and transistors outward to cover a
large area. This is a reversing sensor to prevent him reversing into anything and as such will
cover a wide area. I will make single Led/Phototransistor sensors for front left and front right.
This will allow him to avoid crashing into obstacles when his rangefinder/object tracker is
looking elsewhere.
Note: That the phototransistors are slightly forward of the blue LEDs. This helps stop stray
light from the LEDs being detected.
30
Figure 2.12 Circuit Diagram of Obstacle Sensor
2.4.2 Features
Modulated IR transmitter
Ambient light protected IR receiver
3 pin easy interface connectors
Bus powered module
Indicator LED
Up to 12 inch range for white object
Can differentiate between dark and light colors.
2.4.3 Applications
Proximity Sensor
Obstacle Detector Sensor
Line Follower Sensor
Wall Follower Sensor
31
Chapter 3
Software
AVR STUDIO
3.1 Introduction:
AVR Studio is a Development Tool for the AT90S Series of AVR micro controllers.
This manual describes the how to install and use AVR Studio. It enables the user to fully
control execution of programs on the AT90S In-Circuit Emulator or on the built-in AVR
Instruction Set Simulator. AVR Studio supports source level execution of Assembly
programs assembled with the Atmel Corporation's AVR Assembler and C programs compiled
with IAR Systems’ ICCA90 C Compiler for the AVR microcontrollers. AVR Studio runs
under Microsoft Windows95 and Microsoft Windows NT.
AVR Studio enables execution of AVR programs on an AVR In-Circuit Emulator or
the built-in AVR Instruction Set Simulator. In order to execute a program using AVR Studio,
it must first be compiled with IAR Systems' C Compiler or assembled with Atmel's AVR
Assembler to generate an object file which can be read by AVR Studio.
The key window in AVR Studio is the Source window. When an object file is opened,
the Source window is automatically created. The Source window displays the code currently
being executed on the execution target (i.e. the Emulator or the Simulator), and the text
marker is always placed on the next statement to be executed. The Status bar indicates
whether the execution target is the AVR In-Circuit Emulator or the built-in Instruction Set
Simulator.
By default, it is assumed that execution is done on source level, so if source
information exists, the program will start up in source level mode. In addition to source level
execution of both C and Assembly programs, AVR Studio can also view and execute
programs on a disassembly level. The user can toggle between source and disassembly mode
when execution of the program is stopped.
All necessary execution commands are available in AVR Studio, both on source level
and on disassembly level. The user can execute the program, single step through the code
either by tracing into or stepping over functions, step out of functions, place the cursor on a
statement and execute until that statement is reached, stop the execution, and reset the
execution target. In addition, the user can have an unlimited number of code breakpoints, and
32
every breakpoint can be defined as enabled or disabled. The breakpoints are remembered
between sessions.
The Source window gives information about the control flow of the program. In
addition,
AVR Studio offers a number of other windows which enables the user to have full
control of the status of every element in the execution target. The available windows are:
1. Watch window: Displays the values of defined symbols. In the Watch window, the
user can watch the values of for instance variables in a C program.
2. Register window: Displays the contents of the register file. The registers can be
modified when the execution is stopped.
3. Memory windows: Displays the contents of the Program Memory, Data Memory,
I/O Memory or EEPROM Memory. The memories can be viewed as hexadecimal values or
as ASCII characters. The memory contents can be modified when the execution is stopped.
4. Peripheral windows: Displays the contents of the status registers associated with
the different peripheral devices:
• EEPROM Registers
• I/O Ports
• Timers etc.
5. Message window: Displays messages from AVR Studio to the user
6. Processor window: Displays vital information about the execution target, including
Program Counter, Stack Pointer, Status Register and Cycle Counter. These parameters can be
modified when the execution is stopped.
3.2 Why AVR?
As microprocessors evolved, devices increased in complexity with new hardware and
new instructions to accomplish new tasks. These microprocessors became known as CISC or
Complex Instruction Set Computers. Complex is often an understatement; some of the CISCs
that I’ve worked with have mind-numbingly complex instruction sets. Some of the devices
have so many instructions that it becomes difficult to figure out the most efficient way to do
anything that isn’t built into the hardware.
Then somebody figured that if they designed a very simple core processor that only
did a few things but did them very fast and efficiently, they could make a much cheaper and
easier to program computer. Thus was born the RISC, Reduced Instruction Set Computers.
33
The downside was that you had to write additional assembly language software to do all the
things that the CISC computer had built in. For instance, instead of calling a divide
instruction in a CISC device, you would have to do a series of subtractions to accomplish a
division using a RISC device. This ‘disadvantage’ was offset by price and speed, and is
completely irrelevant when you program with C since the complier generates the assembly
code for you.
Although I’ll admit that ‘CISC versus RISC’ and ‘C versus assembly language’
arguments often seem more like religious warfare than logical discourse, I have come to
believe that the AVR, a RISC device, programmed in C is the best way to microcontroller
salvation (halleluiah brother).
The folks that designed the AVR as a RISC architecture and instruction set while
keeping C programming language in mind. In fact they worked with C compiler designers
from IAR to help them with the hardware design to help optimize it for C programming.
3.3 WINAVR
WINAVR is not just one tool, like many other software names. It is instead a set of
tools, these tools include avr-gcc (the command line compiler), avr-libc (the compiler library
that is essential for avrgcc), avr-as (the assembler), avrdude (the programming interface),
avarice (JTAG ICE interface), avr-gdb (the de-bugger), programmers notepad (editor) and a
few others. These tools are all compiled for Microsoft Windows and put together with a nice
installer program.
When referring to the version, you are most of the time referring to the version of the
compiler, avr-gcc.
For example currently WinAVR includes version 3.3 of avr-gcc. However, it is not
WinAVR 3.3 as some people call it, to refer to which release you are using that is done by
date. For example WinAVR 20030424. The 20030424 is a date code, which is discussed
later.
WinAVR is a suite of executable, open source software development tools for the
Atmel AVR series of RISC microprocessors hosted on the Windows platform. It includes the
GNU GCC compiler for C and C++.
34
WinAVR is a collection of executable software development tools for the Atmel AVR
processor hosted on Windows.
These software development tools include:
Compilers
Assembler
Linker
Librarian
File converter
Other file utilities
C Library
Programmer software
Debugger
In-Circuit Emulator software
Editor / IDE
Many support utilities
3.3.1 Compiler
The compiler in WinAVR is the GNU Compiler Collection, or GCC. This compiler is
incredibly flexible and can be hosted on many platforms; it can target many different
processors / operating systems (back-ends), and can be configured for multiple different
languages (front-ends).
The GCC included in WinAVR is targeted for the AVR processor, is built to execute
on the Windows platform, and is configured to compile C, or C++.
Avr-gcc is just a "driver" program only. The compiler itself is called cc1.exe for C, or
cc1plus.exe for C++. Also, the preprocessor cpp.exe will usually automatically be prepended
with the target name: avr-cpp.exe. The actual set of component programs called is usually
derived from the suffix of each source code file being processed.
3.4 AVRISP2:
The AVRISP2 combined with AVR studio can program all AVR 8-bir RISC