Design and Implementation of Microcontroller Based Controller For Direction and Speed of A Robot
Design and Implementation of Microcontroller Based Controller For Direction and Speed of A Robot
N de srie : .
MASTER ACADEMIQUE
In Commande Electrique
By
Title
Design and implementation of microcontroller
based controller for direction and speed of a
robot
Defended on May 25th, 2016. Before the jury:
Mr. Hima Abdelkader.
Maitre de confrences
Persident
Maitre de confrences
Supervisor
Maitre de confrences
Member
Maitre de confrences
Invited
Acknowledgement
We would like to take this opportunity to express our gratitude to our respected
supervisor Doctor Tir Zoheir associated professor at the university for the inspired guidance,
insight, continuous encouragement, timely suggestions that he has provided throughout the
duration of this work. The present work, being successfully completed due to his sincere
monitoring and vital inputs.
We would also thank all our friends, faculty and staff members of the Department of
Electrical Department for their support and all kinds
Duty cycle
DC
Direct current
emf= Eb
Ia
Curent armature
IR
Infra Red
IC
Integrated Circuit
GND
Ground
Kp
proportional gain
Ki
Integral gain
Kd
derivative gain
LDR
LED
no of pole pairs
PWM
Ra
Armature resistance
Vavg
Average signal
List of figures
Part I:
Fig 2.1
Fig 2.2
Fig 2.3
Fig 2.4
Fig 2.5
Fig 2.6
Fig 2.7
Fig 2.8
Fig 3.1
06
07
08
10
12
14
14
15
20
Part II:
Fig 4.1
Fig 4.2
Fig 4.3
Fig 4.4
Fig 4.5a
Fig 4.5b
Fig 4.6
Fig 4.7
Fig 4.8
Fig 4.9
Fig 4.10
Fig 4.11
Fig 4.12
Fig 4.13
Fig 4.14
Fig 4.15a
Fig 4.15b
Fig 4.13
Tab 4.1
Tab 4.2
30
30
31
31
32
32
33
35
36
37
39
41
42
50
51
51
52
53
40
43
TABLE OF CONTENTS
Acknowledgements
Dedication
Nomenclature
List of Figures
Table of contents
Abstract
Thesis organization
..
..
..
..
..
..
.
Part I :
THEORETICAL BACKGROUND
Chapter 1 :
Introduction to robotic
1. Introduction..
2. Characteristics of robot....
3. Types of robots.
3.1. Mobile robots ....
3.2. Industrial robots......
3.3. Autonomous robots.
3.4. Remote-controlled robots...
3.5. Virtual robots..
4. Applications of robot
5. Applications of line follower robot..
6. Conclusion ..........
Chapter 2 :
i
ii
iii
iv
v
vi
vii
01
02
02
03
03
03
03
04
04
05
05
Control of DC motors
1. Introduction..
2. Control system theory...
2.1. Open loop control...
2.1.1. Open loop characteristics..
2.2. Closed loop control....
2.2.1 Closed loop characteristics
2.3. Difference between open loop and closed loop operation of DC motor.
3. DC motor .
3.1. Factors controlling motor speed ....
3.1.1. Applied voltage control..
3.1.2 Armature rheostat control...
3.1.3. Flux control
4. Characteristics.
5. DC motor types
6. Controlling the speed of brushed DC motor
7. DC motor speed controller (PWM of ARDUINO).
8. Duty cycle (D).
9. PWM generator
10. Conclusion.
06
06
07
07
08
08
09
09
10
10
11
11
11
11
13
13
14
16
16
Chapter 3 :
Microcontroller (Arduino)
1. Introduction..
17
2. History of ARDUINO......................................................................................
3. Types of Arduino
4. The Arduino uno
5. Technical specification
6.
The 2
board..
0
6.1.
2
Power..
1
6.2. The
2
memory................................................................................................
1
6.3. Input and output. 2
1
6.4. Communication...
2
3
6.5. USB Over current protection..
2
3
6.6. Automatic (software) reset. 2
3
7. Interface
2
architecture
3
8-Microcontroller programs. 2
4
9. Background-information for the Arduino
2
software..
5
10. Software. 2
6
11. Language reference 2
6
12. Conclusion. 2
8
17
17
19
19
Part II
Chapte
r4
2
3
3
3
3
3
4
3
4
3
4
3
5
3
5
3
7
3
9
3
9
4
0
4
0
4
0
4
1
4
2
4
2
4
3
4
1
4
3
4
6
4
8
4
9
4
9
4
9
5
4.4 Summary..
Conclusion
..
Reference
Annexe
1. Datasheet of the L298N
2. Datasheet of the 7805
3. Datasheet of the 1N4007
0
5
3
5
4
5
5
ABSTRACT
Today we find most robots working for people in industries, factories, warehouses, and
laboratories. Robots are useful in many ways. For instance, it boosts economy because
businesses need to be efficient to keep up with the industry competition.
Line Following is one of the most important aspects of robotics. This project aims to
design and implement a closed loop control system by algorithm using feedback mechanism
to control the movement of the robot by the use of three pair of photo sensors, comprising of
one IR transmitter and a photo diode in each. It guides the robot by giving appropriate signal
to the microcontroller to follow a line that is drawn on the floor. The path consists of a black
line on a white surface (or it may be reverse of that). Two DC motors are used interfaced to
the microcontroller through a motor driver IC. Input signals given to the microcontroller from
the sensors and then the controller takes the appropriate action according to the program
written in it and drives motors as desired.
Thesis Organization:
This thesis is a documentary delivering the ideas generated, concepts applied, activities
done and finally the final year project. It contains four chapters in two main parts. The
following is a description of information in this thesis.
Chapter 1
Provides a general overview of the project and the use and importance of different kinds of
industrial robot, such that the autonomous robots in the world.
Chapter 2
Describes the control systems used in the industrial process such that the open and the closed
loop system which we are used in this project by using an algorithm as a feedback control to
minimize the error occurred between the desired value and the output given by the motion of
the robot. We give also an overview on the DC motors used, and the PWM generated by the
microcontroller.
Chapter 3
We deal in this chapter on the brain of the robot which is the microcontroller (the ARDUINO
UNO), its characteristics, the essential pins, and their connections with the other devices used
in the implementation of the robot such that the driver L298N.
Chapter 4
Describe the hardware development unit in line following robot. This chapter describes about
sensor arrays, microcontroller, motor driving system. It also describes the project
methodology and explains hardware development for the design of the robot. Simulation with
the PROTEUS has also been covered in this chapter. Also it contains all the results obtained
from the software experiments that include the algorithm implemented in a program.
Finally, chapter 4 will summarize the final year project. The conclusion, suggestions or
recommendations for improvements that can be implemented in future are discussed within
this chapter.
1. Introduction:
A Robot has been defined by the Robot Institute of America as:
A robot is a reprogrammable, multifunction, manipulator designed for moving materials,
tools, parts etc. through various programmed motions to perform a variety of tasks . A Robot
has been defined by Webster dictionary as:
A robot is an automatic device that performs functions normally ascribed to humans or a
machine in the form of a human.
A Robot is any machine which is completely automatic, i.e. it starts on its own, decides its
own way of work and stops on its own. It is actually a replica of human being, which has been
designed to ease human burden. It can be controlled pneumatically or using hydraulic ways or
using the simple electronic control ways. The first industrial robot was Unimates built by
George
Devol
and
Joe
Engelberger
in
the
late
50s
and
early
60s.
Generally robots have three main parts which include processor, sensor and motor
control system. Robot sensors represent eyes while actuators act as legs and controller acts as
the brain of a human.
Robots can be fixed robots or mobile robots. Mobile Robots are robots with a mobile base
which makes the robot move freely in the environment. One of the advanced mobile robots is
the Line Follower Robot. It is basically a robot which follows a particular path or trajectory
and decides its own course of action which interacts with obstacle. The path can be a black
line on the white floor (visible) or a magnetic field (invisible). Its applications start from basic
domestic uses to industrial uses, etc. The present condition in industry is they are carrying the
parcels or materials one place to another place using the crane system. Sometimes lifting of
big weights at that time may cause the breakage of lifting materials and will be cause damage
to the parcels also. The line following robots is commonly used for carry children through
shopping malls, homes, entertainment places, industries. The use of line following robotic
vehicle is transport the materials from one place to another place in the industries. This robot
movement completely depends on the track. The robot can do anything you set them to do.
Like in factories all they have to do with making their products is make the robot. [8]
2. Characteristics of robot:
As strange as it might seem, there really is no standard definition for a robot. However, there
are some essential characteristics that a robot must have:
Sensing First of all your robot would have to be able to sense its surroundings. It
would do this in ways that are not similar to the way that you sense your surroundings.
Giving your robot sensors: light sensors (eyes), touch and pressure sensors (hands),
chemical sensors (nose), hearing and sonar sensors (ears), and taste sensors (tongue)
will give your robot awareness of its environment.
Movement A robot needs to be able to move around its environment. Whether rolling
on wheels, walking on legs or propelling by thrusters a robot needs to be able to move.
To count as a robot either the whole robot moves, like the Sojourner or just parts of
the robot moves, like the Canada Arm.
Energy A robot needs to be able to power itself. A robot might be solar powered,
electrically powered, battery powered. The way your robot gets its energy will depend
on what your robot needs to do.
Intelligence A robot needs some kind of "smarts." This is where programming enters
the pictures. A programmer is the person who gives the robot its 'smarts.' The robot
will have to have some way to receive the program so that it knows what it is to do.
[6]
3. Types of robots:
The types of robots are:
1) Mobile robots.
2) Industrial robots
3) Autonomous robots
4) Remote-controlled robots.
5) Virtual robots.
repeating task. Search engines use such kind of robots. They search the World Wide Web and
send the information to the search engines. [7]
4. Applications of a robot:
Robot can replace humans job because robots can perform faster than humans. Robots
need not to drink, to be paid or rest as compared to humans. They can do repetitive work with
high accuracy and will not stop or slow until the task is finished while humans get bored.
Robot can be applied in military to reducing the number of casualties which occur during
military actions has been already been prioritized. The military also uses robots for locating
and destroying mines on land and in water, spying on enemies and entering enemy bases for
gathering information.
Nowadays a doctor can use robots while performing surgery. A human would not be able
to make a whole exactly one 100th of an inch wide and long. When making medicines, robots
can perform their job much faster and much accurately and delicate in comparison to humans.
Doctors and engineers sometimes are developing prosthetic limbs by using robotic
mechanisms.
Individual stationary sensors have limited ranges and applications. Watchdogs and humans
can lose their level of alertness during shift and be injured by intruders. Autonomous robot
systems are the tools that combine the precision of sensors with the mobility and intelligence
of humans.
Robotic site of security sentries are able to work for long hours at consistency high level
of vigilance and precision. People are interested in places full of danger like outer space or
under seas. They cannot go themselves there so they use robots which are used for
exploration.
The robots can carry cameras and other instruments through which they can collect
information and send back for processing to their human operators. The continuous
development of autonomous robots increases our ability to explore universe. [8]
5. Applications of line follower robot:
Automobile applications: These robots can also be used as automatic cars running on
roads with embedded magnets.
Domestic applications: These can also be used at homes for domestic purposes like
floor cleaning etc.
Guidance applications: These can be used in public places like shopping malls,
museums etc to provide path guidance. [8]
6. Conclusion:
A robot is a system that contains sensors, control systems, manipulators, power supplies and
software all working together to perform a task. Designing, building, programming and
testing a robot is a combination of physics, mechanical engineering, electrical engineering,
structural engineering, mathematics and computing. In some cases biology, medicine,
chemistry might also be involved. A study of robotics means that students are actively
engaged with all of these disciplines in a deeply problem-posing problem-solving
environment. [6]
1. Introduction:
DC Motor plays a crucial role in research and laboratory experiments because of their
simplicity and low cost. The speed of the motor can be controlled by three methods namely
terminal voltage control, armature rheostat control method and flux control method. Here in
this project terminal voltage control method is employed.
A control system is an interconnection of components forming a system configuration
that will provide a desired system response. A controlled DC-motor was developed allowing
ARDUINO hardware acts as the interface between the computer and the outside world. It
primarily functions as a device that digitizes incoming analog signals so that the computer can
interpret them. The user interface was developed in an ARDUINO environment. [5]
Fig
2.1:
Process under control [12]
Plant: The plant is also known as the process and it is the physical system to be
controlled.
Output or the Controlled Variable: It is the signal or the plant output which we need to
control. In our case the speed of the DC Motor is the controlled variable which is to be
control.
Reference: It is the desired value that we want to see at the output. In this thesis set
point or reference is the desired speed of the DC Motor.
There are basically two types of control system: the open loop system and the closed loop
system. They can both be represented by block diagrams.
Feedback can be divided into positive feedback and negative feedback. Positive feedback
causes the new output to deviate from the present command status. Negative feedback directs
the new output towards the present command status, so as to allow more sophisticated control.
Most modern appliances and machinery are equipped with closed loop control systems.
Examples include air conditioners, refrigerators, etc[12]
3. DC motor:
A DC motor is a machine that converts electrical energy into mechanical energy. The
operation is based on simple electromagnetism, when a current carrying conductor is placed
in an external magnetic field it experiences a force which is proportional to the current and the
external magnetic field. A torque is generated by the magnetic reaction and the armature
revolves and this induces a voltage in the armature windings which is opposite in direction to
the outside voltage applied to the armature, when current is passed through the armature of
the DC motor, and hence is called back voltage or counter e.m.f. The back voltage rises till it
becomes equal to the applied voltage as the motor rotates faster,
The speed at which the DC motor rotates depends on two factors - the armature current as
well as the strength of the magnetic field acting on the armature. The stronger the field, the
slower is the rotation rate required to produce a back voltage huge enough to counteract the
applied voltage. Hence, the speed of the DC motor can be controlled by varying the field
current.
Every DC motor consists of six parts: axle, stator, rotor, commutator, field magnet and
brushes. [15]
Where
4. Characteristics: [5]
Nearly constant speed
Torque varies nearly as the current
Medium starting torque (twice full load torque with twice full load current at start)
Continuous speed range 4:1 maximum
5. DC motor types:
There are two main types of DC motors: brushed DC motors and brushless DC motors.
Brushed DC motors generate mechanical power by placing a rotatable armature with coils
inside of a stationary magnetic field. Brushes and commutators are used to make the current
reverse direction multiple times (depending on the number of poles) each cycle. This causes
the motor to rotate, creating mechanical power. On the other hand, brushless DC motors do
not have brushes or commutators, and generate mechanical power by synchronizing the
voltages applied to the driving coils. Figure below shows the basic structure of a simple 2
pole brushed DC motor and a brushless DC motor. [10]
The DC motor speed in general is directly proportional to the supply voltage, so if reduce
the voltage from 12 volts to 6 volts then our speed become half of what it originally had. But
in practice, for changing the speed of a DC motor we cannot go on changing the supply
voltage all the time. So how to change the speed of the motor with input voltage fixed led to
the development of systems known as speed controllers. [15]
The speed controller for a DC motor works by varying the average voltage supplied to the
motor (PWM is one such speed controller were we can get varying voltage according to the
duty cycle of the PWM output signal). Rather than simply adjusting the voltage sent to the
motor, we can switch the motor supply on and off where switching is done so much fast that
the motor only notices the average effect. [15]
The time it takes a motor to speed up slow down under switching conditions depends on
the inertia of the motor. The graph below shows the speed of a motor that is switched on and
off fairly slowly. If switching is done fast enough the motor does not have time to change
spee
d
and
it
give
s an
alm
ost
cons
tant
speed. Thus the speed is set by Pulse Width Modulation (PWM). [15]
8. Duty-cycle (D):
Duty cycle (the width of the signal) is defined as the percentage ratio of the pulse
HIGH to pulse HIGH + LOW during a PWM period. or it is a percentage measurement of how
long the signal stays on.
Duty Cycle
On Time
100%
Period
9. PWM generator:
Pulse width modulation is a technique to provide a logic0 and logic 1 for a controlled
period of time. Analog voltages and current can be used to control processes directly but as
simple it seems its not always practical and economical to do so because analog circuits tend
to drift over time and can therefore be very difficult to tune.
Controlling an analog
circuit digitally can greatly reduce cost as well as power consumption. PWM is a powerful
technique for controlling analog circuits digitally.[15]
PWM is a way of digitally encoding analog signal levels. The duty cycle of a square
wave can be modulated to encode a specific analog signal level. However the PWM signals
are always digitals because at any instant the DC supply is either fully on or fully off. Voltage
or current sources are applied to the analog load by means of repeating series of on and off
pulses. [15]
The on-time is the time during which DC supply is given to load while the off-time is the
time during which it is switched off. Given a sufficient bandwidth, an analog value can be
encoded with PWM. [15]
10. Conclusion
In real PWM speeds control of DC. Motors, the output is switched on and off in a period
typically in the range of 50 to 200 microseconds. This extremely fast switching means that the
average power applied to the motor can be controlled. The switching happens so fast that the
motor does not get sufficient time to slow down to stop during the off (space) times. Instead
the motor speed varies depending on the average amount of power applied to it.
1. Introduction:
Arduino is an open source- single board microcontroller, which provides an easy access
to programming, microcontrollers and project platforms for interactive objects for artists,
designer, hobbyists and others.
The Arduino-platform has been based on an Atmels ATmega168 or ATmega328
microcontroller. The system provides users with digital I/O-ports and analog input channels,
which allow the Arduino-system to receive and respond to signals from the environment.
The Arduino system applies a powerful Atmel ATmega328P single chip, providing an
8-bit microcontroller at 16 MHz with 32K bytes In-system programmable flash. The power
supply voltage has been designed quite versatile in the range DC7-12V, providing stabilized
and protected operating conditions for the chip and isolated power lines up to 2A for motor
circuitry.
A microcontroller (sometimes abbreviated C, uC or MCU) is a small computer on a
single integrated circuit containing a processor core, memory, and programmable input/output
peripherals. Program memory and a small amount of data memory (RAM) is also often
included on chip.
Microcontrollers are used in automatically controlled products and devices, such as
automobile engine control systems, implantable medical devices, remote controls, office
machines, appliances, power tools, and toys. By reducing the size and cost compared to a
design that uses a separate microprocessor, memory, and input/output devices,
microcontrollers make it economical to digitally control even more devices and processes. [1]
2. History of arduino:
Originally the Arduino project started 2005 in Ivrea, Italy. The concept aimed to support
students in projects, in which the prototyping should be cheaper and more efficient as in most
standard methods.
The developer group under Massimo Banzi and David Cuartielles decided to name the
project after a historical character named Arduin of Ivrea. Arduino is the Italian version of
the name, meaning strong friend. The English version of the name is Hardwin.
The system has been equipped with a compiler for a standardized programming language
and a boot-loader. The programming language has been based on Wiring- language, which
corresponds to C++. [1]
3. Types of Arduino:
Fifteen versions of the Arduino hardware have been commercially produced to date
1. The Serial Arduino, programmed with a DE-9 serial connection and using an
ATmega8
2. The Arduino Extreme, with a USB interface for programming and using an ATmega8
3. The Arduino Mini, a miniature version of the Arduino using a surface-mounted
ATmega168
4. The Arduino Nano, an even smaller, USB powered version of the Arduino using a
surface-mounted ATmega168 (ATmega328 for newer version)
5. The LilyPad Arduino, a minimalist design for wearable application using a surfacemounted ATmega168
6. The Arduino NG, with a USB interface for programming and using an ATmega8
7. The Arduino NG plus, with a USB interface for programming and using an
ATmega168
8. The Arduino Bluetooth, with a Bluetooth interface for programming using an
ATmega168
9. The Arduino Diecimila, with a USB interface and utilizes an ATmega168 in a DIL28
package (pictured)
10. The Arduino Duemilanove ("2009"), using the ATmega168 (ATmega328 for newer
version) and powered via USB/DC power, switching automatically
11. The Arduino Mega, using a surface-mounted ATmega1280 for additional I/O and
memory.
12. The Arduino Uno uses the same ATmega328 as late-model Duemilanove, but whereas
the Duemilanove used an FTDI chipset for USB, the Uno uses an ATmega8U2
programmed as a serial converter.
13. The Arduino Mega2560, uses a surface-mounted ATmega2560, bringing the total
memory to 256 kb. It also incorporates the new ATmega8U2 (ATmega16U2 in
revision 3) USB chipset.
14. The Arduino Leonardo, with an ATmega32U4 chip that eliminates the need for USB
connection and can be used as a virtual keyboard or mouse. It was released at the
Maker Faire Bay Area 2012.
15. The Arduino Esplora, resembling a video game controller, with a joystick and built-in
sensors for sound, light, temperature, and acceleration.
5. Technical specification:
Microcontroller
ATmega328
Operating Voltage
5V
6-20V
40 mA
50 mA
Flash Memory
SRAM
2 KB
EEPROM
1 KB
Clock Speed
16 MHz
6.The board:
6.1.Power:
The Arduino Uno can be powered via the USB connection or with an external power
supply. The power source is selected automatically.
External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery.
The adapter can be connected by plugging a 2.1mm center-positive plug into the board's
power jack. Leads from a battery can be inserted in the GND and Vin pin headers of the
POWER connector.
The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V,
however, the 5V pin may supply less than five volts and the board may be unstable. If using
more than 12V, the voltage regulator may over heat and damage the board. The recommended
range is 7 to 12 volts.[2] .[3]
The power pins are as follows:
VIN. The input voltage to the Arduino board when it's using an external power source
(as opposed to 5 volts from the USB connection or other regulated power source). You
can supply voltage through this pin, or, if supplying voltage via the power jack, access
it through this pin.
5V. The regulated power supply used to power the microcontroller and other
components on the board. This can come either from VIN via an on-board regulator,
or be supplied by USB or another regulated 5V supply.
3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw is
50 mA.
GND. Grounds pins.
6.2. Memory:
The Atmega328 has 32 KB of flash memory for storing code (of which 0,5 KB is used for
the boot loader); It has also 2 KB of SRAM and 1 KB of EEPROM (which can be read and
written with the EEPROM library).[2]
HIGH or LOW.
6.4.Communication:
The Arduino Uno has a number of facilities for communicating with a computer, another
Arduino, or other microcontrollers. The ATmega328 provides UART TTL (5V) serial
communication, which is available on digital pins 0 (RX) and 1 (TX). An ATmega8U2 on the
board channels this serial communication over USB and appears as a virtual com port to
software on the computer. The '8U2 firmware uses the standard USB COM drivers, and no
external driver is needed. However, on Windows, an *.inf file is required.
The Arduino software includes a serial monitor which allows simple textual data to be sent to
and from the Arduino board. The RX and TX LEDs on the board will flash when data is being
transmitted via the USB-to serial chip and USB connection to the computer (but not for serial
communication on pins 0 and 1).[2]
7. Interface architecture:
Microcontrollers usually contain from several to dozens of general purpose input/output
pins (GPIO). GPIO pins are software configurable to either an input or an output state. When
GPIO pins are configured to an input state, they are often used to read sensors or external
signals. Configured to the output state, GPIO pins can drive external devices such as LEDs or
motors.
Many embedded systems need to read sensors that produce analog signals. This is the purpose
of the analog-to-digital converter (ADC).
Since processors are built to interpret and process digital data, i.e. 1s and 0s, they are not able
to do anything with the analog signals that may be sent to it by a device. So the analog to
digital converter is used to convert the incoming data into a form that the processor can
recognize. A less common feature on some microcontrollers is a digital-to-analog converter
(DAC) that allows the processor to output analog signals or voltage levels.
In addition to the converters, many embedded microprocessors include a variety of
timers as well. One of the most common types of timers is the Programmable Interval Timer
(PIT). A PIT just counts down from some value to zero. Once it reaches zero, it sends an
interrupt to the processor indicating that it has finished counting.
This is useful for devices such as thermostats, which periodically test the temperature around
them to see if they need to turn the air conditioner on, the heater on, etc.
8.Microcontroller programs:
Microcontroller programs must fit in the available on-chip program memory, since it
would be costly to provide a system with external, expandable, memory. Compilers and
assemblers are used to convert high-level language and assembler language codes into a
compact machine code for storage in the microcontrollers memory.
Depending on the device, the program memory may be permanent, read-only memory that
can only be programmed at the factory, or program memory may be field-alterable flash or
erasable read-only memory.
Microcontrollers were originally programmed only in assembly language, but various highlevel programming languages are now also in common use to target microcontrollers. These
languages are either designed especially for the purpose, or versions of general purpose
languages such as the C programming language. Microcontroller vendors often make tools
freely available to make it easier to adopt their hardware.
The Arduino system provides us with approximately 32K bytes of flash-memory for sketches
programs, which may be programmed in C programming language. [2]
The basic Arduino-concept supplies us with libraries filled with extra functionality. A library
defines a number of predefined functions, which for recurrent programming sections may be
reused at no extra cost for development.
Basically an Arduino-program may be structured in three sections:
structure,
definitions (for variables and constants respectively)
Functions.
An Arduino-structure consists of a setup and a loop-function. The setup is used to initialize
variables, pin-definitions (Pin-Modes) and libraries-definitions.
The Loop function will be repeated in an endless loop, which allows the program to react
permanently, until the system is switched off.
The program uses variable -definitions to store and handle a programs modifiable data
whereas constants are used to define fixed values such as pin-definitions for input- or outputfunctionality and to define fixed voltage levels at pin-connections.
10- Software:
The Arduino IDE is a cross-platform application written in Java, and is derived from the
IDE for the Processing programming language and the Wiring project. It is designed to
introduce programming to artists and other newcomers unfamiliar with software development.
It includes a code editor with features such as syntax highlighting, brace matching, and
automatic indentation, and is also capable of compiling and uploading programs to the board
with a single click. There is typically no need to edit make files or run programs on a
command-line interface. Although building on command-line is possible if required with
some third-party tools such as Ino. The Arduino IDE comes with a C/C++ library called
"Wiring" (from the project of the same name), which makes many common input/output
operations much easier. Arduino programs are written in C/C++, although users only need
define two functions to make a runnable program:
Control Structures
if
if...else
for
switch case
while
do... while
break
continue
return
goto
Variables
Constants
HIGH / LOW
INPUT/
OUTPUT|INPUT_PULLUP
true / false
integer constants
floating point constants
Data Types
void
Boolean
char
unsigned char
byte
int
unsigned int
word
long
unsigned long
short
float
double
string - char array
Functions
Digital I/O
pinMode()
digitalWrite()
digitalRead()
Analog I/O
analogReference()
analogRead()
analogWrite() - PWM
Further Syntax
; (semicolon)
{} (curly braces)
// (single line comment)
/* */ (multi-line comment)
#define
#include
Arithmetic Operators
= (assignment operator)
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
% (modulo)
String - object
array
Conversion
char()
byte()
int()
word()
long()
float()
Due only
analogReadResolution()
analogWriteResolution()
Advanced I/O
variable scope
static
volatile
const
tone()
noTone()
shiftOut()
shiftIn()
pulseIn()
Comparison Operators
Random Numbers
== (equal to)
!= (not equal to)
randomSeed()
< (less than)
random()
> (greater than)
<= (less than or equal to)
>= (greater than or equal
to)
Time
millis()
micros()
delay()
delayMicroseconds()
Boolean Operators
&& (and)
|| (or)
! (not)
Math
min()
max()
abs()
constrain()
map()
pow()
sqrt()
Pointer
Access Operators
* dereference operator
& reference operator
Bitwise Operators
& (bitwise and)| (bitwise
or)
Trigonometry
sin()
cos()
tan()
bitClear()
bit()
External Interrupts
attachInterrupt()
detachInterrupt()
noInterrupts()
12. Conclusion :
We conclude that the Arduino:
It comes with an open source hardware feature which enables users to develop their
own kit using already available one as a reference source.
The Arduino software is compatible with all types of operating systems like Windows,
Linux, and Macintosh etc.
It also comes with open source software feature which enables experienced software
developers to use the Arduino code to merge with the existing programming language
libraries and can be extended and modified.
We can develop an Arduino based project which can be completely stand alone or
projects which involve direct communication with the software loaded in the
computer.
It comes with an easy provision of connecting with the CPU of the computer using
serial communication over USB as it contains built in power and reset circuitry.
1. Introduction:
Today we find most robots working for people in industries, factories, warehouses, and
laboratories. Robots are useful in many ways. For instance, it boosts economy because
businesses need to be efficient to keep up with the industry competition. Therefore, having
robots helps business owners to be competitive, because robots can do jobs better and faster
than humans can, e.g. robot can built, assemble a car. Yet robots cannot perform every job;
today robots roles include assisting research and industry. Finally, as the technology
improves, there will be new ways to use robots which will bring new hopes and new
potentials.[9]
The design process is changing rapidly as the demand increases. So in this chapter we will
describe the robotics design, block diagram, Algorithm and its components description,
implementation and the simulation.
INPUT SYSTEM
PROCESSING SYSTEM
OUTPUT SYSTEM
The way an LDR works is that they are made of many semi-conductive materials with high
resistance. The reason they have a high resistance is that are very few electrons that are free
and able to move because they are held in a crystal lattice and are unable to move. When light
falls on the semi conductive material it absorbs the light photons and the energy is transferred
to the electrons, which allow them to break free from the crystal lattice and conduct electricity
and lower the resistance of the LDR.[13]
An analog signal is obtained in output, depends on the amount of light reflected back, which
is provided to the comparator to produce 0s and 1s which are then fed to the microcontroller.
2.3.2. Comparator:
Comparator is a device, which compares two input voltages and gives output high or low.
In circuit diagram it is normally represented by a triangle having-Inverting (negative) Input,
Non-Inverting (positive) Input (+), Vcc, Ground, Output.
If V+ > V- then Vo= Vcc (Digital High Output is 1), If V+< V- then Vo= 0 (Digital Low Output
is 0).
Sample calculation:
Let V+ = 3.587V
With light: (on white surface)
V- = 2.500v Thus V+ < V- and Vo = 5v. Thus we got digital HIGH output.
Without light (on black surface ):
V- = 4.6875v thus V+ < V- and Vo = 0v. Thus we got digital low output.
In the driver stage we may identify the DC-motor M. The preamplifier of the driver circuit is
being simulated by resistor R14. This resistor will pull the base-ports of transistors TR6 and
TR5 to 0V, which results in a condition in which only the right-sided branch is conducting a
significant current.
Transistors TR8, TR5 and TR9 are conducting and the other transistors are blocked. As soon
as we switch R14 to a positive voltage the right-sided branch will be blocked and the motor
current will be reversed.
The 3V-power supply is an ideal condition for a robot with a battery pack of only 2 cells. The
PNP-transistors however cannot easily be integrated in an IC such as the L293D. An IC
however has other advantages such as reliability, protection against bad circuitry and reduced
PCB-area and low weight.
For this reason a L293D-chip with a dual H-bridge circuitry have been used to
simultaneously control two DC-motors.
1. Pin1 and Pin9 are "Enable" pins. They should be connected to +5V for the drivers to
function. If they pulled low (GND), then the outputs will be turned off regardless of
the input states, stopping the motors. If you have two spare pins in your
To identify the leads of the 7805, you have to keep the lead downward (Fig 4.11a) and the
writing to the side. The heat sink can be seen above the voltage regulator (1-input, 2-gnd, 3output).
Fig 4.11b shows how- to use 7805 voltage regulator. Coupling capacitors are good for
regulation.
There is no requirement for it in normal case. If 7805 used in analog circuit capacitor one
should use, else the noise in the output voltage will be high. These are the mainly available
78xx ICs which are 7805, 7809,7812,7815,7824, high sensitive.
(a)
(b)
Fig 4.11: (a) the 7805 IC, (b) connection the 7805 IC
2.6. Summary:
In this section we have described design of the project and various components description
which has been used in the project.
3. Implementation:
3.1. Introduction:
In this section we will describe about circuit connections and its working procedure,
navigation and microcontroller programming.
connect D10
Fig 4.12: The connection circuitry of the ARDUINO,L298N with 2 DC Motors
The motor direction is controlled by sending a HIGH or LOW signal to the drive for each
motor (or channel). For example for motor one, a HIGH to IN1 and a LOW to IN2 will cause
it to turn in one direction, and a LOW and HIGH will cause it to turn in the other direction.
However the motors will not turn until a HIGH is set to the enable pin (6 for motor one, 11
for motor two). And they can be turned off with a LOW to the same pin(s). However if you
need to control the speed of the motors, the PWM signal from the digital pin connected to the
enable pin can take care of it.
The pin 1 and 15 must be connected through a resistor to limit the reverse current goes from
the load to the L298 to the GND rather than the pin 8.
The right and the left DC motor should be connected to the pin 2-3 and 13-14 respectively.
The logic voltage (5V) entered from the voltage regulator or the power pin of the Arduino to
the pin 9 through a capacitor to eliminate the noise to the circuit, also the pin 4 should be
powered from the voltage source that we have chosen and it will be between 6 to 45V.
3.4. Navigation:
Using two motors independently allows for the robot to move in many ways. Table below
shows how the robot will move with the given input.
Left Motor Voltage
Zero
Negative
Positive
Positive
Negative
Forward
Zero
Robot movement
Stopped
Counter Clockwise spin
Clockwise spin
Forward
Reverse
Circular turn right
Circular turn left
Three integers are declared that will hold the offset values for the
three sensors calculated in the calibration routine
Define the pins that will control the speed and direction of the
two motors
Two integer are created to hold the initial speed of the motors and
the speed offset for each wheel that we add or subtract to make
the robot rotate
Turn the LEDs OFF (for 1 Sec) after 1 Sec from obtaining the
new offset values
Divide each of the running totals by 10; these give the average for
the three sensors and then calculate the left and right offset by
deducing them from the center one
Setup the pin SPEED 1 and 2 and the DIRECTION 1 and 2 for the
two motors and pin 9 as output by [pinMode] command
If
Lv Yr+Th
No
The robot is always in the forward
direction and the center sensor is in
the middle
Yes
The black line has shifted from the
center line and is too far to the right
No
Rv Yr+Th
Yes
2. Then another three integers are declared that will hold the offset values for the three sensors
calculated in the calibration routine.
3. Next, we define the pins that will control the speed and direction of the two motors
4. Then two integers are created to hold the initial speed of the motors and the speed offset for
each wheel that we add or subtract to make the robot rotate
The default speed is set to 70, which is around 27% duty cycle. We may need to adjust this
value to suit our own robot. Too high a value will make the robot overshoot the line and too
low will prevent the motors from turning fast enough to turn the wheels to overcome friction.
5. The rotate value is how much you will speed up or slow down the wheels to cause the
robot to turn. In our case, the required value is 30. So when turning left, for example, the right
wheel spins at speed 100 and the left wheel at a speed of 40 (70+30 and 70-30). The rotate
value is another setting you may need to adjust for our own setup.
6. Another integer is created to hold the sensor threshold
This is the difference in values required between the center sensor and the left or right sensors
before the robot decides to turn. In my case, a setting of 5 works well. This means that the left
and right sensors would need to detect a value greater than the value read from the center
sensor plus the threshold value before action is taken. In other words, if the center sensor is
reading a value of 600 and the left sensor is reading 603, then the robot will keep going
straight. However, a left sensor value of 612 (which is higher than the center value plus
threshold) means that the left sensor is detecting the back line, indicating that the robot is too
far over to the left. So the motors would adjust to make the robot turn to the right to
compensate.
7. The final set of variables will store the speed values for the left and right motors.
After the variables are all declared and initialized, we come to our first and only function,
which is the calibration routine
First, it obtains an average value from each of the three sensors over a sequence of ten
reads.
Second, it flashes the lights 10 times (while reading values from the three sensors) to
show that the robot is calibrating and nearly ready to run.
The sensors require calibration, as each one will read different values to the next one. Every
LDR will give a slightly different reading and this will be affected by manufacturing
tolerances, the tolerance of the voltage divider resistors used, and the resistance in the wires.
We want all three sensors to read (roughly) the same value, so we take ten readings from
each, average them out, and calculate the difference that the left and right sensors are from the
center sensor (which is used as the baseline).
8. The LEDs attached to Pin 9 are turned on, followed by a delay of 100 milliseconds:
9. Now we take those values and add them to the leftOffset, center, and rightOffset
variables.
These variables start off at zero, so after ten iterations they will contain a running total of all
ten values read from the sensors.
Then we wait 100 milliseconds, turn the light off, wait another 100 milliseconds, and then
repeat the process.
10. After this process has repeated ten times, we exit the for loop and then divide each of the
running totals by ten. This gives us an average sensor reading for each of the three LDRs.
We then calculate what the offset will be by deducting the left and right sensor values by the
centre one. These values will be added to the sensor readings from the left and right sensors
so that all three sensors will be giving approximately the same readings.
11. Next, we have the setup routine, which starts off by setting the pin for the LEDs and the
pins for the motor speed and direction to OUTPUT:
The calibration routine is now run to ensure all three sensors issue similar readings, followed
by a delay of three seconds. After the LEDs flash ten times during the calibration routine; we
have three seconds to place the robot on the line.
The lights are turned on, followed by a brief delay. The direction of both motors is set to
forward and the speeds are set to the values stored in the right and left variables (initially set
to the value stored in startSpeed.
12. Now we move onto the main loop of the program. This starts off by setting the speed of
the left and right motors to the value in startSpeed.
The motor speed is reset to these values at the start of each loop so that the robot is always
going forward, unless the values are changed later in the loop to make the robot turn.
We now read the sensor values from each of the three LDRs and store the values in the LDR1,
LDR2, and LDR3 integers. The offsets calculated for the left and right sensors are added to
the value so that when all three sensors are looking at the same surface they will read
approximately the same values.
13. Now we need to check those sensor values and see if the black line has moved to far from
the center. You do this by checking the left and right sensors and seeing if the values read are
greater than the value read from the center LDR plus the threshold offset. If the value from
the left sensor is greater than the reading-plus-threshold-offset, then the black line has shifted
from the centerline and is too far to the right. The motor speeds are then adjusted so that the
left wheel spins faster than the right, thus turning the robot to the right which will bring the
black line back to the centre.
The same is done for the right hand sensor, this time turning the robot to the left.
3.6. Summary:
This Flowchart shows how to create a line follower application and run it on Arduino Robot.
The whole process is repeated over and over many times per second and forms a feedback
loop which makes the robot follow the line.
The sensitivity of the LDRs can be adjusted by changing the value in the threshold variable.
Play around with these values until you get the robot to follow the line successfully.
4.Simulation:
4.1. Introduction to proteus:
Proteus ISIS is the best simulation software in the world for various designs with
electronics & microcontroller. It is mainly popular because of availability of almost all
microcontrollers in it.
Proteus (PROcessor for TExt Easy to USe) is a fully functional, procedural
programming language created in 1998 by Simone Zanella. Proteus incorporates many
functions derived from several other languages: C, BASIC, Assembly, Clipper/dBase; it is
especially versatile in dealing with strings, having hundreds of dedicated functions; this
makes it one of the richest languages for text manipulation.
ISIS Schematic Capture - easy to use but it is an extremely powerful tool to enter
your projects.
ARES PCB Layout - system for high-performance PCB design with automatic
component placement, rip-up and self-routing and verification of interactive design
rule.
VSM - Virtual System Modelling to simulate embedded software for popular microcontrollers alongside your design of hardware.
Using simulation in the Proteus software, instead of real physics devices, we have some
advantages .
Advantages:
Since Proteus have a extensive library of components, you can try several different
components that you do not have on hand.
The integrated package with common user interface and the context-sensible help can
make the learning process more quick and easy.
Virtual prototype with Proteus VSM reduce the time and cost of software and
hardware development.
Faster and easier to connect the components; not losing in tangles of wires.
Do not burn the components, such as LEDs; so common in the learning process.
ENA
(5V)
ENB(5V)
Fig 4.15a: One of the two LDR become closer to the black line
When the left or the right sensor become closer to the black line, the analog value goes from
this sensor to the analog pin of the ARDUINO becomes less than the values in which the
sensor totally above the white surface and by consequence the microcontroller gives a signal
to the driver (the L298N) to slow down (by giving less voltage to Motor A terminals), and to
speed up the other Motor (by giving more voltage to Motor B). Thus the speed of the two
motors will be not the same (figure below show the deferent speed) and the robot try to follow
the black line.
The amount of
the current
consumed by the
Motor A
51.7 rpm
The amount of
the current
consumed by the
Motor B
Fig 4.15b: the deference in the speed between the two DC Motors
Fig 4.16: the voltage applied between the two terminals of the DC Motors
The figure above shows the graph of the two amount of the voltage applied to the two DC
motors.
The ENB goes LOW (the bottom line), the voltage applied between the terminals of motor B
(the second line from the top) goes down to 0V, but the voltage across the motor A (the first
line on the top) ripple for instance of time because of the instantaneous current to 5V and goes
back to 10V (each row represent 5V).
4.4. Summary:
Proteus is very popular circuit simulation software and it is possible simulate Arduino with
Isis by Proteus.
We conclude for line following algorithm that:
If line is centered in front of robot, go forward
If line is left of center, turn left
If line is right of center, turn right
If no line is detected, circle until line is found
Conclusion
In the project, we studied, simulated and designed an autonomous robot which is a
robot have the ability to detect a trajectory with a color defers from the white color and the
implementation of a closed loop controller.
After construction of the robot we programmed it to follow the line without the PID control
algorithm. The method that was used was to check the sensor condition and according to that
move the robot in the appropriate direction such that the robot tries to centre itself over the
line, this was repeated by the microcontroller hundreds of times a second. This was the
implementation of a direct mapping of the sensor condition to the motion of the robot. The
code was written so that the robot follows a black line on a white background.
The result of this was that the robot followed the line. Due to limitations in the hardware
(Motor and Sensors), the deviations observed were immense. In certain cases the line sensors
would all be off the line. This confused the robot since it did not correspond to any condition
of the robot. The robot would continue in its last motion. This problem was solved by figuring
out which direction the robot was moving when it moved off the line. This helped put it back
on track.
Future Work:
Future Scope of this project involves the use of PID controller by the implementation of
proximity sensors with the two wheels to provide medium- or low-resolution sensing,
depending on the number of pulses measured per revolution.
This implementation takes more hardware and more time to do it and especially complicated
software to get the PID algorithm because in this design we dial with three constants which
are the Kp, Kd, and Ki in order to give to our robot a smooth and precision tracking of the
black line.