robotics guide(technogenious solutions)
TRANSCRIPT
-
7/29/2019 Robotics Guide(Technogenious Solutions)
1/48
Page1www.technogenious.com [email protected]
Chapter 1: Robots
Introduction
You must have been thinking about what a robot isthe answer is really simple..any
machine that solves your problems, works efficiently and doesnt get tired..
Then whats the difference between a simple machine and a robot. The answer is vague but
generally a robot is a machine with motion. For example you may term a JCB machine as a robot
but not a photocopy machine.
What kinds of skills robot building requires
Robot building =mechanical engg. skills +electronics engg. skills +computer engg. skilss
Mechanical engg. Skills are required mostly for the construction part of the robot. The success of
some kind of robots depend mostly on the construction part e.g. humanoid robots.Their
construction matters a lot to us.
Electronics engg. Skills are required for the circuitry part of the robots. All the robots contain a
bunch of electronic circuits and their interconnections. What components are required and how
to interconnect them is really important for making a robot and thats where electronics skills
jump in.
Computer engg. Skills are required for giving brain to the robot. Most autonomous and semi
autonomous robots require some kind of program instruction to be embedded in them using
which they can find out what they are to do whenever certain event arises.
Types of Robots
Robots are of three types
1.
Manual Robots : These are the robots which have no brain i.e. no intelligence. They justdo what you tell them to do using either a wired or wireless medium.
2. Semi-Autonomous Robots : These are the robots which do have brain but still they needour assistance to work properly.
3. Autonomous Robots: These are the robot which are wholly self contained i.e. they dontneed our assistance to work. They have their own brain and using their brain they decide
-
7/29/2019 Robotics Guide(Technogenious Solutions)
2/48
Page2www.technogenious.com [email protected]
what they are to do. Although this brain is also embedded by us in the robots but after
embedding we dont need to tell them what they are to do.
We will be concerned mostly with autonomous robots and will be discussing them only
throughout the book.
Basic Parts
Now we talk about what basic parts make up a robot.
Robot =Sensor +motors +power source +microcontroller
Microcontroller may be optional in case of very simple robots but its necessary for others.
Sensors are the input devices for the robot and provide information about the environment.Motors are the output devices and are responsible for providing motion to the robot.
Microcontroller is the brain of the system and its where we embed the instructions that form the
intelligence.
Now you are familiar with what makes up a robot. Now we should discuss in detail various parts
of the robots.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
3/48
Page3www.technogenious.com [email protected]
Chapter 2: Sensors
Introduction
Sensors are the input devices that provide information about the environment to the robot. This
information might be related to colour, amount of light, temperature, distance of obstacles etc.
Depending on what kind of information the sensor provides there are a number of sensors. Out of
the available ones we will be discussing following.
1. IR sensor2. Light sensor3. Temperature sensor4. TSOP based obstacle detector
IR sensor
In this topic we will learn IR sensor. How to design it and how to use it? In IR sensor there is
an emitter and a detector. Emitter emits the IR rays and detector detects it. This sensor is usually
used in making a line follower robot and edge avoider robot.
Basic Principle :
In a line follower robot the basic need is to distinguish between black and white colour. The
property is that white colour reflects all the light falling on it and black colour absorbs it. So
when IR light from emitter falls on white colour it is reflected and falls on the detector whereas
in case of black colour object no light reflects back on detector.The other colours except black
also reflect light but to different proportions.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
4/48
Page4www.technogenious.com [email protected]
In a edge avoider robot the basic need is to distinguish whether the sensor is on the table oroutside it. The table is never of black colour.So when sensor is on the table,it reflects portion of
light falling on it and when outside the table no light is reflected back to the sensor.
Sensor behavior if it is on the table and outside the table(supposing table of blue colour)
Cicruit Diagram :
The IR LED and IR photodiode are used as follows. The resistance of the sensor(photodiode)decreases when IR light falls on it. A good sensor will have near zero resistance in presence of
light and a very large resistance in absence of light. We have used this property of the sensor to
form a potential divider. When the IR LED comes over the black line the comparator
IC(LM358N) gives 0 as output otherwise when it is over the white surface it gives 1 as output.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
5/48
Page5www.technogenious.com [email protected]
Sensitivity of IR sensor
The sensitivity of sensor means that how much effectively the sensor senses the change that is
occurring in its surrounding. The sensitivity of the IR sensor is controlled by reference voltage,
the voltage set using the variable resistance.
Large value of reference voltage less sensitive. Small value of reference voltage more sensitive.
Light Sensor
In this topic we will learn Light sensor. How to design it and how to use it? In Light sensor
there is a detector.A detector is always paired with emitter. In this case light source acts as the
emitter. The light source may be a bulb,sunlight or anything. Emitter emits the light and detector
detects it. This sensor is usually used in making a light searching robot.
Basic Principle:
The detector used in light sensor is LDR(Light Dependent Resistor). The property of LDR is that
its resistance decreases when light falls on it(although some are there that work opposite).
-
7/29/2019 Robotics Guide(Technogenious Solutions)
6/48
Page6www.technogenious.com [email protected]
Ciruit Diagram:
The resistance of the LDR decreases when light falls on it. A good LDR will have near zero
resistance in presence of light and a very large resistance in absence of light. We have used this
property of the LDR to form a potential divider.When the light falls on the LDR the comparator
IC(LM358N) gives 1 as output otherwise it gives 0 as output.
Sensitivity of L ight sensor
The sensitivity of light sensor means that how much effectively the sensor senses the light that is
present in its surroundings. The sensitivity of the Light sensor is controlled by reference voltage,
the voltage set using the variable resistance.
Large value of reference voltage less sensitive. Small value of reference voltage more sensitive.
Temperature Sensor
In this topic we will learn Temperature sensor. How to interface it and how to use it? The most
commonly used temperature sensor is LM35. Its pinout is shown below.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
7/48
Page7www.technogenious.com [email protected]
The most used convention is connect Vcc to +5V although datasheet says you can any voltagefrom 4-20V and connect Gnd pin to ground. Now you have Out pin that provides you the
temperature output in terms of voltage.
Basic Principle:
The voltage at pin OUT varies linearly with temperature.
Variation =10 mV per degree centigrade
How to use:
Since it provides analog output and mostly we work with digital devices in case of our robots
(brains i.e. microcontrollers are digital), we connect the OUT pin of this sensor to the input of
ADC(analog to digital convertor) and then provide the output of the ADC to the microcontroller.
The microcontrollers we will be dealing with have inbuit ADCs so you dont have to use
separate ADCs.
TSOP based obstacle detector
In this topic we will learn TSOP based obstacle detector sensor. How to design it and how to use
it? In this sensor again there is an emitter and a detector. Emitter is an IR led as in case of IR
sensor and detector now is TSOP1738(other variations also exist e.g. TSOP1740/1742 etc)
instead of IR photodiode.
Limitation of IR sensor:
Although simple IR sensor can also be used to detect obstacles as in case of edge avoider robot it
is used to detect whether it is on the table or not. But the limitation is it cant be used in sunlight
-
7/29/2019 Robotics Guide(Technogenious Solutions)
8/48
Page8www.technogenious.com [email protected]
since sunlight has lots of infrared radiations in it which already reduce the resistance of sensor to
near zero and the effect of light from IR led is like the effect of a drop in the sea. To avoid this
limitation TSOP based sensor is used. In this light from IR led is modulated at certain frequency(38 Khz in our case) and the detector is chosen to respond at only IR light modulated at that
frequency(TSOP1738 in our case). Since sunlight doesnt contain IR light modulated at certain
frequency it doesnt have any effect on our detector in this case.
Circuit Diagram:
The circuit has three main parts
1.TSOP1738
2. IR led3. 555 timer and associated components.
555 timer generates a square wave of 38 KHz that is used to drive IR led. In this IR led is made
to blink at 38 KHz and this light when falls on TSOP1738 acivates it and it outputs a 0.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
9/48
Page9www.technogenious.com [email protected]
Remember TSOP1738 is active low i.e. it outputs a 0 when light falls on it and otherwise it
outputs 1. Now I will tell you how to choose component values to generate a square wave of
certain frequency.
Astable mode of 555 timer:
To generate a square wave 555 timer must be operated in astable mode and the circuit used is
An astable circuit produces a 'square wave', this is a digital waveform with sharp transitionsbetween low (0V) and high (+Vs). Note that the durations of the low and high states may bedifferent. The circuit is called an astable because it is not stable in any state: the output iscontinually changing between 'low' and 'high'.
The time period (T) of the square wave is the time for one complete cycle, but it is usually betterto consider frequency (f) which is the number of cycles per second.
T =0.7 x (R1 +2R2) x C1 and f =1.4/( (R1+2R2) x C1 )
T =time period in seconds (s)f =frequency in hertz (Hz)R1 =resistance in ohms ( )R2 =resistance in ohms ( )C1 =capacitance in farads (F)
The time period can be split into two parts:T =Tm +TsMark time(output high):Tm =0.7 (R1 +R2) C1Space time(output low):Ts =0.7 R2 C1
Many circuits require Tm and Ts to be almost equal; this is achieved if R2 is much larger thanR1.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
10/48
Page10www.technogenious.com [email protected]
Chapter 3: Motors
Introduction
Motors are the output devices that are used to provide motion to the robot. Motion may be
related to robot moving from one place to another,it may be related to movement of a robotic
arm whose base is kept stationary to pick and place objects etc. The following kind of motors are
generally used in robotics
1. DC Geared Motor2. Simple DC motor3. Stepper Motor4. Servo Motor
DC Geared Motor
A DC Geared motor has two terminals. When we apply Vs(+ve voltage) to terminal1 and
Ground to terminal2 the motor rotates in one directions and if we apply ground to terminal1 and
Vs to terminal2 it rotates in opposite direction. The function of gears is to increase the torgue andreduce the speed. See one thing speed and torgue are inversely proportional. That means if you
decrease the speed, torgue will increase and vice versa. Basically a DC geared motor has a
simple DC motor on the rear side whose speed is very high and in the front part it employs a
combination of gears that reduces the speed and increases torgue. This is the reason why when
we remove the applied voltage a DC geared motors stops at the point where voltage was
-
7/29/2019 Robotics Guide(Technogenious Solutions)
11/48
Page11www.technogenious.com [email protected]
removed whereas simple DC motor continue to rotate for a second or more even after removing
the voltage applied.
Driving DC Geared Motor
A DC geared motor usually draws current more than the maximum value per pin of the
microcontrollers therefore we cannot attach their two terminal directly to two pins of
microcontroller and operate it by appliying 1 to one pin and 0 to other. If we do so
microcontroller will get damaged since motor draws more current than microcontroller pins can
provide. So some kind of driver is needed inbetween.The driver to be used depends on whether
we want unidirectional motion or bidirectional motion.
Unidirectional Motion using transistor
In the above circuit giving high voltage (e.g. 5V) on input pin motor will start rotating sincegiving high voltage on input pin will turn on the transistor which will connect the motors lower
terminal to the ground and motor will start. One more thing a diode has been used in the circuit.
Why is it needed? Normally we do not use this diode in this circuit but it is really necessary.
You know why because when we stop the motor the back current generated by it will flow
through diode instead of transistor. If it werent so our transistor would have got damaged.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
12/48
Page12www.technogenious.com [email protected]
Unidirectional Motion using relay
This circuit is almost same as the above one except current passing through motor now passes
through relay instead of transistor. So the transistor used in this circuit can be of low current
rating as compared to the one used in the above circuit. The circuit is shown below.
When we switch on the transistor by applying 1 to its base, current passed through the coil in therelay which causes the contact to change from NC to NO and motors one terminal now is
connected to Vs and other to ground thereby causing motor to rotate in one direction. The diode
has been used for the same reason as for the previous circuit but now for the back current
generated by the coil in the relay.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
13/48
Page13www.technogenious.com [email protected]
Bidirectional Motion using Hbridge
In Fig.1 simple H-bridge Connection is shown using switch. Where all the switches are open and
the motor is not receiving any potential difference V or current I and hence it is not rotating.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
14/48
Page14www.technogenious.com [email protected]
In Fig.2 switches S2 and S3 are open and S1 and S4 are closed which creates a potential
difference across the motor and simultaneously a current flows through the circuit which rotates
the motor shaft, lets say, in the clockwise (CW) direction.
Similarly, in Fig.3 switches S1 and S4 are open and S2 and S3 are closed which rotates the motor
in anti-clockwise direction.
These switches can be replaced with transistors as shown in fig. below
-
7/29/2019 Robotics Guide(Technogenious Solutions)
15/48
Page15www.technogenious.com [email protected]
When A is 1 and B is 0, T1 and T4 are on and T2 and T3 are off so the motor rotates in
clockwise direction and if A is 0 and B is 1, the motor rotates in anticlockwise direction.
Remember never make both A and B 1 because if you do so, all the transistors will be ON andhence there will be a short circuit.
L293D dual HBridge IC
One IC exists in market that contains two hbridges in it and can be used most of the times.
Bidirectional Motion using Relays
-
7/29/2019 Robotics Guide(Technogenious Solutions)
16/48
Page16www.technogenious.com [email protected]
The circuir for each relay includes transistor as shown before. When Relay1 is ON and Relay2 is
OFF there is a potential difference across its two terminals so it rotates in one direction. When
Relay2 is ON and Relay1 is OFF there is a potential difference across its two terminals but thistime its in opposite direction so it rotates in other direction. In this way we can use relays to
control bidirectional motion of motors.
Hbridge vs Relays
The difference is in speed. The relay operates at much lower speeds than transistors, so it can not
be used in high speed applications. The other side is for the same current rating, relays are much
cheaper than the transistors of the same current rating. So what you choose depends on the kind
of application.
Simple DC Motors
This motor uses the same driving circuits as DC Geared motors but the only difference is even
after removing the potential difference across them , they continue to rotate for some time(1
second or more) they dont stop at the precise moment just like DC Geared motors do.
Stepper Motors
A stepper motor is a brushless electric motor that can divide a full rotation into a large number of
steps.Stepper motors are very different from a regular DC motors. Instead of spinning like DC
motors do, stepper motor steps at a specific resolution for each pulse.The motor that I will be
discussing needs48 steps / pulses just to complete a single revolution.
Another advantage of stepper motors is the fact that their speed of rotation can be achieved
almost instantly even if you change the spinning direction.
Stepper motor consists of a rotor - the permanent magnet that rotates inside, and stator - four
coils (north, east, south, west) that are part of the case, and which don't move. Rotor can be
moved by sequentially applying a pulsed DC voltage to one or two coils at a time.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
17/48
Page17www.technogenious.com [email protected]
Stepper Motor Inner Construction
Identification of wires
Stepper motors either have five or six wires...out of which one and two are for power
respectively. But how to identify which one is that. Here it is..
Isolate the Common Power wire(s) by using an multimeter to check the resistances between pairs
of wires. The Common Power wire will be the one with only half as much resistance between it
and all the others. This is because the Common Power wire only has one coil between it and each
other wire, whereas each of the other wires have two coils between them. Hence half the
resistance.
Now you need to identify in which sequence coils should be activated so that you can rotate the
motor in the direction you want.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
18/48
Page18www.technogenious.com [email protected]
1. Identify the wires to the coils by supplying a voltage on the Common Power wire(s) andkeeping one of the other wires grounded while grounding each of the remaining three
wires in turn and observing the results. Select one wire and ground it .Assume it'sconnected to coil 4.
2. Keeping it grounded, ground each of the other three wires one by one. Grounding onewire should make the rotor turn a little clockwise .That'll be the wire connected to Coil 3.
3. Grounding one wire should make the rotor turn a little anticlockwise . That'll be the wireconnected to Coil 1.
4. Grounding one wire should do nothing .That'll be the wire connected to Coil 2.Note:
The numbering of the coils as above is purely arbitrary - it's the order they are in that's
important.
Stepping modes
Since each coil can be programatically controlled, you can experiment with different types of
stepping modes.
1. Single Stepping - the simplest mode turns one coil ON at a time. 48 pulses are needed to
complete one revolution. Each pulse moves rotor by 7.5 degrees. The following sequence has to
be repeated 12 times for motor to complete one revolution.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
19/48
Page19www.technogenious.com [email protected]
PulseCoil 1Coil 2Coil 3Coil 4
1 ON
2 ON
3 ON
4 ON
This sequence rotates the motor in anticlockwise direction . To rotate the motor in clockwise
direction we have to reverse the sequence in which pulses are applied to various coils.
2. High Torque Stepping - high power / precision mode turns ON two coils on at a time. 48
pulses are needed to complete one revolution. Each pulse moves rotor by 7.5 degrees. The
following sequence has to be repeated 12 times for motor to complete one revolution.
PulseCoil 1Coil 2Coil 3Coil 4
1 ON ON
2 ON ON
3 ON ON
4 ON ON
-
7/29/2019 Robotics Guide(Technogenious Solutions)
20/48
Page20www.technogenious.com [email protected]
Again this sequence rotates the motor in anticlockwise direction . To rotate the motor in
clockwise direction we have to reverse the sequence in which pulses are applied to various coils.
3. Half Stepping - stepping is doubled and motor needs 96 pulses to complete one revolution.Each pulse moves rotor by approximately 3.75 degrees. Notice the mix of single stepping mode
(lighter green) and high torque mode (darker green).
PulseCoil 1Coil 2Coil 3Coil 4
1 ON
2 ON ON
3 ON
4 ON ON
5 ON
6 ON ON
7 ON
8 ON ON
-
7/29/2019 Robotics Guide(Technogenious Solutions)
21/48
Page21www.technogenious.com [email protected]
Circuit Diagram
The circuit diagram used to interface the stepper motor to the microcontroller is given below
ULN 2003 IC is a 16 pin IC and is simply used as an earth switch.The function of ULN 2003 IC
is to ground huge amount of current. If HIGH signal is applied to 1,2,3 or 4 no. pin of the IC then
the windings connected to 16,15,14 or 13 no. pin get grounded respectively.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
22/48
Page22www.technogenious.com [email protected]
Servo Motors
Servos are the DC motors with built in gearing and feedback control loop circuitry and no motordrivers are required. They are also used for precise positioning but unlike stepper motors they
can rotate by some angle(usually in the range 0 to 180 degrees) in one step. However, servos are
unable to continually rotate, meaning they can't be used for driving wheels (unless modified), but
their precision positioning makes them ideal for robot arms,RC planes etc.
Servos usually have three wires
1. Black/Brown is for Ground2. Red is for power(usually 4.8 to 6V)3. Yellow/Orange/White is the signal wire(3-5V)
The duration of the pulse on the signal wire determines by what angle the servo will rotate. This
duration is different for different motors. So you better check datasheet of that motor before
using any. But still there is a standard that is given below
-
7/29/2019 Robotics Guide(Technogenious Solutions)
23/48
Page23www.technogenious.com [email protected]
-
7/29/2019 Robotics Guide(Technogenious Solutions)
24/48
Page24www.technogenious.com [email protected]
Chapter 4: Power Sources
Introduction
In case of robotic systems you mostly need two voltages
1. +5V for the microcontroller and may be other logic devices2. Higher voltages generally +12V for motors and some other devices.
All you need is a DC supply whether it be +5 or +12V. So you have two options for the supply
AC to DC conversion:
If your systems base is stationary then you can plug your system into AC socket to receive
power and convert AC to DC using bridge rectifier as shown below.
In the diagrams below, when the input connected to the left corner of the diamond is positive,
and the input connected to the right corner is negative, current flows from the upper supply
terminal to the right along the red (positive) path to the output, and returns to the lower supply
terminal via the blue (negative) path.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
25/48
Page25www.technogenious.com [email protected]
When the input connected to the left corner is negative, and the input connected to
the right corner is positive, current flows from the lowersupply terminal to the right alongthe red (positive) path to the output, and returns to the upper supply terminal via
the blue (negative) path.[3]
In each case, the upper right output remains positive and lower right output negative.
The output waveforms generated are shown in fig. The voltage coming from AC outlet is 230 V
AC which is converted to 12 V AC by the step down transformer and then in converted to
unidirectional voltage as shown in second part of fig which then by the use of the capacitor is
converted to almost pure DC.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
26/48
Page26www.technogenious.com [email protected]
DC power source:
There are a number of DC power sources available in market as given below
1. 9V radio battery : 9V radio batteries are easily available in market and they come in twomain varieties : rechargable and non-rechargable.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
27/48
Page27www.technogenious.com [email protected]
Whatever it be they can be used only in low current applications because generally they
are rated at 250mAh. For high current application either you can connect them in
parallel or switch to other alternatives.
2. Li-ion Batteries : Other alternative is Li-ion batteries available in market. They aregenerally rechargeable and are very light weight. So they are really appropriate for
robotic applications and their current rating is also usually high as 2000mAh. They are
mostly used as mobile phone batteries.
3. Ni-Mh Batteries : Other alternative is Ni-Mh batteries available in market. They are alsogenerally rechargeable and are light weight. So they are also appropriate for robotic
applications and their current rating is also usually high as 2000mAh. They mostly come
in the form of 1.2 V cells and so a series of them is needed to get higher voltages.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
28/48
Page28www.technogenious.com [email protected]
How to get +5V
Everything discussed till now says how to obtain +12V and +9V but microcontroller usuallyworks at +5V . So how to get that voltage. For that we need to use a voltage regulator as shown
below.
The current capacity of this regulator is 1A . If you need more current than that either use a
number of them in parallel or switch to another voltage regulator whose current capacity is
more.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
29/48
Page29www.technogenious.com [email protected]
Chapter 5: Microcontrollers(AVR family)
Introduction
Microcontroller is the brain of your robot.This is where you embed the instructions for the robot
to follow and the intelligence of the robot depends on you. As intelligent the program written by
you is, as intelligent the robot will be. So it all depends on your skills how intelligent you can
make your robot.
Microcontroller families
Mainly three types of families exist
1. 8051 fmaily2. AVR family3. PIC family
Every family has different features. 8051 family is the oldest one. So has very few features as
compared to others. I personally find AVR family easies to work with.
AVR familyAVR stands for Advanced Virtual RISC. RISC means reduced instruction set computer. On the
other side there is a CISC architecture which stands for complex instruction set computer. In
RISC there are small number of simple instructions only that can be executed within a single
clock cycle whereas in CISC there are large number of complex instructions that generally take
more than one clock cycle. Microcontroller in this family may be 8bit or 16 bit . We will be
-
7/29/2019 Robotics Guide(Technogenious Solutions)
30/48
Page30www.technogenious.com [email protected]
discussing only 8 bit microcontrollers. 8 bit means they can process only 8 bits of data at a time.
Some examples of 8 bit microcontrollers are ATmega8,Atmega16,Atmega32 etc.
Atmega8
It is a microcontroller of AVR family with
8 KB of flash memory 512 bytes EEPROM 1 KB of internal SRAM
The flash memory is used to store the program that provides the intelligence to the system.
EEPROM is used to store the data values that may need to be changed by the program written by
us but we want that to be stored permanently.
Internal SRAM is used to store the values of various variables that are not required to be stored
permanently.
Besides these some other features of this microcontroller are
Two 8 bit timer/counters One 16 bit timer/counter 6 built in ADCs Internal calibrated crystal oscillator(1,2,4 and 8 MHz) Programmable serial USART etc.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
31/48
Page31www.technogenious.com [email protected]
Pinout Of Atmega8
It is a 28 pin IC and its pinout is shown in fig below
VCC : It is the supply voltage for the microcontroller and for two versions of atmega8 it iso 2.7 - 5.5V (ATmega8L)o 4.5 - 5.5V (ATmega8)
Gnd : This is the ground pin for the microcontroller.
PORTB(PB0-PB7) : These are eight general purpose I/O pins with both high current and highsink capacity. Each pin has maximum current capacity of 40 milli amperes.
PORTD(PD0-PD7) : These are eight general purpose I/O pins with both high current and high
sink capacity. Each pin has maximum current capacity of 40 milli amperes.
PORTC(PC0-PC6) : These are seven general purpose I/O pins with both high current and highsink capacity. Each pin has maximum current capacity of 40 milli amperes. The pin PC0 can notbe normally used for input. ( except when RSTDISBL fuse is programmed but beware if youprogram this bit you normally wont be able to reprogram it except when you use specialprogrammers)
-
7/29/2019 Robotics Guide(Technogenious Solutions)
32/48
Page32www.technogenious.com [email protected]
RXD & TXD : These two pins stand for receiver and transmitter and are used for serialcommunication using USART.
INT0 & INT1 : These are the external interrupt pins and cause the program execution to shift toa fixed point when they are activated.
XTAL 1 & XTAL2 : These are used to connect to an external crystal oscillator . When thefrequencies provided by the built in crystal oscillator are not suffiecient for you, you may need toconnect an external crytal oscillator.
SCK,MISO & MOSI : These pins are used for programming. They stand for clock, Master inslave out and master out slave in. These pins enable the transfer of program from computer to themicrocontroller.
ADC0-ADC5 : These are the input pins for the built in analog to digital converters.
AVCC : This is the supply voltage for the built in ADCs
AREF : This is the reference voltage for the built in ADCs
RESET : This pin is used to reset the microcontroller. A low on this pin resets the controller.
I think this much details are enough for you guys for the beginning. So now lets proceed to the
programming part.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
33/48
Page33www.technogenious.com [email protected]
Chapter 6: Making your first program(AVR Studio & WinAVR)
Introduction
Ok lets start with your first program : Blinking an LED. The complete procedure for what you
are to do is shown in fig below.
This is what you normally do when you write a program in C . Isnt it ?
The procedure for microcontroller is only little different as shown below. In the above case you
got an exe file and executed that on your PC but here you get a hex file and transfer that to
microcontroller and then the program is run in that microcontroller.
Compiler and IDE :
The compiler that we are gonna use is WinAVR and the IDE is AVR Studio.First install
WinAVR and then AVR Studio and follow following steps.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
34/48
Page34www.technogenious.com [email protected]
STEP 1: Start AVR Studio 4. Go to START>All Programs>Atmel AVR Tools>AVR Studio 4.
STEP 2: On welcome screen click on New Project
STEP 3: On next screen choose AVR GCC on project type, and give project name and path
make sure create folder is checked and click on next.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
35/48
Page35www.technogenious.com [email protected]
STEP 4: Choose AVR Simulator as debug platform and ATmega8 as device in device list and
click on finish.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
36/48
Page36www.technogenious.com [email protected]
STEP 5: Now you are ready to write the program. The following screen will appear.
STEP 6: Now write this code in center code window
-
7/29/2019 Robotics Guide(Technogenious Solutions)
37/48
Page37www.technogenious.com [email protected]
STEP 7: Compile the program by clicking on build.
STEP 8: You should get this on build window if u did everything CORRECT.
STEP 9: Now go to your project folder. You will find a default folder inside it. Open it, you will
see a blinkled.hex file. This is the file that you will later transfer to your microcontroller.
Program Explanation:
#define F_CPU 1000000ULThis define the clock speed. It means at what speed the microcontroller is operating. 1 MHz is
the default c lock of atmega microcontrollers. It tells the duration of one clock cycle and hence in
wat time microcontroller can process some instruction.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
38/48
Page38www.technogenious.com [email protected]
#include
#include
These are the header files- one for input output and the other for the delay function.
int main(void)This is the main function from where the execution starts.
DDRD=0xFF;It is used for defining whether the pins of port will be used for input or output. A pin is used as
input if its cooresponding bit in the DDR(data definition register) is 0 and it is used as output if
its cooresponding bit in the DDR(data definition register) is 1. If we connect 8 LEDs onPORTD, set it as output and send data on these pins as 1, all LEDs will glow.
DDRD is an 8 bit register for setting data direction line of PORTD. Similarly we have DDRA,
DDRB and DDRC.
Now there is an infinite loop for continued blinking. Most of the programs for robotic systems
will contain an infinite loop like this and all the code that does actual function will go inside it.
After that we have just send the data on PORTD as high on all 8 pins by command
PORTD=0xFF; Similarly we can send data 0 on all 8 pins by command PORTD=0x00; and
need to put some delay between these two commands so that we can see the blinking LEDs
otherwise they will blink very rapidly and our eyes cannot see these fast blinking LEDs.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
39/48
Page39www.technogenious.com [email protected]
Chapter 6: Burning the hex file(AVRDude)
Introduction
Now the time to transfer the hex file to your microcontroller(flash memory). For this you need
two things
Burner Hardware Burner software
Burner hardware is the hardware that you use to connect your microcontroller to your PC. It actsas an intermediary between your PC and microcontroller. Burner software is the software that
you use as an interface to burn the hex file into the microcontroller.
Burner Hardware
Burner hardware that I personally use for AVR microcontrollers is USBasp. It is really cheap and
easy to make. USBasp that we provide is shown below.
It has a 6 pin header at the right end which contains following pins from top to bottom
MOSI MISO SCL RESET VCC
-
7/29/2019 Robotics Guide(Technogenious Solutions)
40/48
Page40www.technogenious.com [email protected]
GROUNDConnect these pins to corresponding pins of the microcontroller. If you remember we alreadydiscussed these pins in chapter on microcontrollers and now you are ready to burn the hex file.
Burner Software
The burner software that I prefer is AVRDude. It is an open source program but one limitation is
that it has a command line interface but dont worry there are a number of GUIs for it. So you
can easily use it.
1. First select the target device.2.
Then select Intel Hex as file format. Whether you want to verify after programming ornot depends on you
3. Then select the hex file you want to burn. The hex file will go into flash4. The click program and you will be done.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
41/48
Page41www.technogenious.com [email protected]
Chapter 7: Making a line follower
Introduction
A line follower as it name signifies is a robot that follows a line. The line is in contrast with its
background. Here we will be discussing how to make a simple line follower that can follow a
black line on a white surface.
Logic
We use two IR sensors to detect the colour beneath the sensor and we keep the distance between
the sensors to be greater than the width of the line. The following conditions can arise
Both the sensors are on white. In this case we should keep on going straight. The left sensor is on white and right sensor is on black. We should make our robot turn to
the right.
The left sensor is on black and right sensor is on white. In that case we should move ourrobot to the left
Last condition is both the sensors are on black. What should we do in this case dependson the requirements but generally a high width black part is placed at the end of the trackand our robot should stop there. So we should stop our bot in such condition.
Example
Both the sensors are on whiteas shown in fig below. What we should do then? Weshould keep on going straight.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
42/48
Page42www.technogenious.com [email protected]
In the above fig if we kept on going straight the following condition as shown in figbelow will arise i.e. left sensor is on white and right sensor is on black. Now we
should make our robot turn to the right. Isnt it?
Now when we turn our robot to the right we will have the condition as shown below.
Again both the sensors will be on white and we will move our robot forward.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
43/48
Page43www.technogenious.com [email protected]
In this way the robot is able to follow the line.
Program
The code for our line follower is shown below.
#define F_CPU 8000000UL
#include #include int main(){
int left,right;
DDRB=0b11111111; //define PORTB as outputDDRC=0b0000000; //define PORTC as input
/* connect your left sensor to PC4 and right sensor to PC5. Connect your left motorhbridge terminals to PB2 & PB3 and right motor hbridge terminals to PB0 & PB1 */
while(1){
-
7/29/2019 Robotics Guide(Technogenious Solutions)
44/48
Page44www.technogenious.com [email protected]
left =PINC & 0b0010000; //mask to get status of only PC4right =PINC & 0b0100000; //mask to get status of only PC5
if(left ==0b0010000 && right ==0b0100000) //both on white{
PORTB =0b00001001; //move forward
}else if(left ==0b0010000 && right ==0b0000000) //only left on white{
PORTB =0b00001000; //move right
}
else if(left ==0b0000000 && right ==0b0100000) //only right on white{PORTB =0b00000001; //move left
}else //both on black{
PORTB =0b00000000; //stop}
}}
-
7/29/2019 Robotics Guide(Technogenious Solutions)
45/48
Page45www.technogenious.com [email protected]
Chapter 8: Making a cell phone controlled robot
Introduction
In many robotic application there is a need to control a machine using cell phone like starting or
activating it by cell phone or deactivating it by cell phone. So in this chapter we will see how to
design such kind of system which can be controlled by cell phone.
DTMF(Dual Tone Multi Frequency)
It is the technique for transmitting information over telecommunication lines. The DTMF system
uses eight different frequency signals transmitted in pairs to represent sixteen different numbers,symbols and letters as shown below.
So to control our robot through a cell phone what we need to do is to decode these frequencies
and find out what particular button was pressed and we are done then. To detect these
frequencies we make use of DTMF decoders ICs. There are a number of these available in
market but I will show you one that is most commonly used.
-
7/29/2019 Robotics Guide(Technogenious Solutions)
46/48
Page46www.technogenious.com [email protected]
DTMF Decoder(HT9170)
The circuit diagram used for HT9170 is shown below
What happens is we give the one input from the headphone to the point termed DTMF and
connect other input from the headphone to ground. What this circuit does is provide us the digital
value of the key presses e.g.
when 1 is pressed we have D3 D2 D1 D0 =0001
when 2 is pressed we have D3 D2 D1 D0 =0010 and so on.
Connections with microcontroller
We connect these four pins termed D3 D2 D1 D0 to 4 pins of out microcontroller port which we
configure as inputs. Suppose we have connected these pins as given below
-
7/29/2019 Robotics Guide(Technogenious Solutions)
47/48
Page47www.technogenious.com [email protected]
D3 ->PC.3 D2->PC.2 D1->PC.1 D0->PC.0
Now we take input from these four pins and depending upon the data present on these pins we
instruct our bot to do something.
Remember :The ICs output is sticky i.e. once you press 1 on your mobile the o/p will remain
0001 unless you press some other key.
Program
The code for cell controlled robot is given below.
/* connect D3-D0 of HT9170 to PC3-PC0 and Connect your left motor hbridge terminals to PB2& PB3 and right motor hbridge terminals to PB0 & PB1 */
#define F_CPU 8000000UL
#include int main(){
int DTMF;
DDRB=0b11111111;DDRC=0b0000000;
while(1){
DTMF =PINC & 0b0001111; //mask PD4-PD7
if(DTMF==2){
PORTB =0b00001001; //forward}
else if(DTMF==4){
PORTB =0b00000001; //left
}else if(DTMF==5){
PORTB =0b00000000; //stop
-
7/29/2019 Robotics Guide(Technogenious Solutions)
48/48
}
else if(DTMF==6){PORTB =0b00001000; //right
}else if(DTMF==8){
PORTB =0b00000110; //backward
}
}}
The code must be clear to you all is you have read the earlier part of this book.