chapter 1 introduction - civimi“live”. a true robotic kit would make us closer to the...
Post on 31-Dec-2020
1 Views
Preview:
TRANSCRIPT
1
CHAPTER 1
INTRODUCTION
1.1 Final Project Background
For centuries the car toys species is always improvised and make people curious to have it. In
my child age I always happy to move the car toys that I have, but I ever to imagine if there is
such a car toy who can move by themselves without having problem to collide with things. My
project is a robot that could move in the open space without collide with things, moreover it
could escape from the maze or labyrinth, this robot just like a car toy but smarter and not make
the user bored. Of course this project could be improved to be a smart robot which can make a
map in the dangerous area or a SAR robot. This project is also inspired by a mice or turtle that
could escape from a house when they are out of their boxes and that often because of our little
sister or brother. This robot could be an alternative for our little sister and brother to make them
still happy.
Figure 1.1 The Turmice robot
1.2 Problem Statement
Until these days, car toys still be a favorite toys for children. A lot of us even imagine how
spectacular if we could be in that car toys. But, many of toys such as moving-robots (car toys,
2
dino toys, etc) just can move forward until it stuck to the wall. The children only could feel
upset and play it with a lower imagination when the toys has been stuck to the wall. It is actually
not physically stuck (except the tank robot) because it’s motor still working. Here we could
make the imagination better for children to play with a simple-robot that can sense that accident
using microcontroller and sensor.
The microcontroller function is a brain in the robot, it is could make some logic to the robot.
The logic in this case should consist how to detect obstacle (such as wall), then the robot could
move smoothly to avoid the obstacle. The sensors here are for sensing the obstacles, it is just
like our eyes, because the robot need to see to make the action that are controlled in the
microcontroller.
Here, the robot could solved the stuck-problem without having the children feel upset again.
Figure 1.2 Robot encounter obstacle
1.3 Objective of the Project
The purpose of this project is to modify the current car toys to make the children more have
freedom to imagination and feel excited. It is to make the car toys could sense the thing that
could make them stuck. Then we give the toys sensor (Infra-Red Proximity sensor) that could
see that thing, a brain (microcontroller Arduino UNO) that could decide how to react after it see
the thing that could make it stuck, and two DC Servo Motors to run the robot in the open space.
3
This final project focus on controlling the auto-robot that could dodge to stuck in the wall.
Moreover it can escaping on the simple maze in the open space. Which could be achieved by
make the robot following one of the wall (right-side or left-side). This project uses the sensor in
the right and front of the robot to make the robot could only follow the right-side of the wall.
The number of motors that used in this project is 2 (two) and separated to make it could turn
into one direction, and being controlled by motor driver and the microcontroller. The robot also
must have the logic to survive from the obstacles, which are:
a. Measure the distance to obstacle/wall, front and right
b. If the obstacle/wall is too close, the robot must turn left
c. If the wall is acceptably close, keep going forward and
d. If the wall is too far away, turn right
Here the example of how the robot could escape from a maze:
Figure 1.3 Robot escape the maze
4
1.4 Scope and Limitation
In the making of this project, there are several limitations and scope that have to be applied.
Here are the scope and limitations for this project:
Scope:
The project is built in scale of laboratorium/home experiment.
Limitation:
Source code for this project is compiled using ATmega328 on Arduino UNO.
The sensor that used is DIY-Analog-Infrared Sensor, which is could only measure 0-15
cm distance (to white object), it also just have the number of decimal logic between 35-
750 (not 0-1024), even with this range we could still fulfill the objective in this project.
The intensity of light in the room must set to 9 lux.
The servo motors that used are 5VDC Motor.
The motor driver module, Arduino Motor Shield, is compatible directly with Arduino
UNO.
The maze is made of the Styrofoam-Rubber Carpet, which is the calibration is precisely
set on this matter.
1.5 Final Project Outline
The final project report consists of five chapters and is outlined as follows:
Chapter 1: Introduction. This chapter consists of problem background, Final Project statement,
Final Project objective, Final Project scope and limitation, and Final Project outline.
Chapter 2: Literature Study. This chapter describes about the component that will be used in
this final project. The description includes characteristic, work mechanism, etc. The
components consist of microcontroller ATmega 328 on Arduino UNO, Infra-Red Proximity
sensor, the 5VDC Servo Motors, Arduino Motor Shield, and LCD. Theory that will be used in
this final project also will be explained in this chapter.
5
Chapter 3: Design and Implementation. This chapter delivers conceptual design and real
implementation for software and hardware. This chapter also will explain for circuitry design
and programming.
Chapter 4: Project Result and Analysis. This chapter consists of the analysis of the hardware
and software. Simulation results are examined to finally conclude the strengths and weakness
of the proposed system according to objectives in previous chapter.
Chapter 5: Conclusions and Recommendations. This chapter consists of conclusions obtained
throughout this project and recommendations for future projects.
6
CHAPTER 2
LITERATURE STUDY
2.1 Preliminary Remarks
This chapter elaborates main idea and knowledge that required in the research and writing of
this final year project. All of the knowledge regarding to this project will be explain in this
chapter with objective to help reader understand the concept of this project and its supporting
elements. The objective of this project is to control the motors of the robot based on Infra-Red
Proximity Sensor reading and all of the information related to it.
The main hardware that required for this project are microcontroller ATmega328 on Arduino
UNO, Infra-Red Proximity Sensor module, 5VDC servo motor, and Arduino Motor Shield as
the motor driver`s module. The reason behind components choosing is based on availability,
ease of interfacing, and low cost price.
Section 2.2 will explains about understanding robot theory, section 2.3 will mainly explains
about the microcontroller and its features, section 2.4 is about sensor, section 2.5 explains about
the motor, section 2.6 will explains motor driver`s module Arduino Motorshield L293, and final
section; 2.7 explains about LCD LMB162AFC
2.2 Robot
Robotic is an interesting area for a lot of people, it can apply our thinking about organisms
nature to react of the world action. It pulls out our imagination to create something that nearly
“live”. A true robotic kit would make us closer to the understanding how the living-things senses
work, and how many memory (programming) can be used for specific tasks. These are the
differences between robot and a toys, the nearly living-thing with just the thing.
There are a lot of robot-things that actually do not have the robotic skills. We see a lot of robot-
shape-made of the LEGO and the others, but actually we just see the normal toys which could
not react to the specific things, it is not “live”. Things can be a robot with three characteristics:
7
Input (sensor or stored in information)
Intelligent (brains – effected by the presence of a central processing unit or controller)
Actuators (output devices such as motor, application, and the other systems that can
react)
Robot would react to the specific things, this could be happen because the brain effected by the
sensor and give the order to the actuator. The brain could be represented by some controller or
in our case microcontroller. This microcontroller could control which act should be done by the
actuator if it is given some specific input of the sensor.
A robot reacts to input by judging its state with its intelligence, and passes commands to its
actuators. For example, a robot can judge where an obstacle is touching it with sensor; the input
is recorded when the sensor is tripped by the obstacle, and passed to the robot`s intelligent
processing system, which decides that hitting an obstacle is a bad idea, and moves the robot by
passing the command to the actuators.
Figure 2.1 Basic control system
2.3 Microcontroller Arduino UNO with ATmega 328
The microcontroller that used in this project is Arduino UNO within the ATmega 328, it has
function as the brain of the device. All the logic and programming is controlled on this hardware,
while it would reacts to some input and output from the others hardware. In this section we
would see how the Arduino UNO works.
8
2.3.1 Arduino UNO
Figure 2.2 Arduino UNO R3 front & back
Arduino Uno is a microcontroller board based on the ATmega 328 which has 14 digital
input/output pins (6 can be used as PWM outputs), 6 analog inputs, 16 MHz ceramic resonator,
a USB connection, a power jack, an ICSP header, and a reset button. It contains everything
needed to support the microcontroller. The Arduino UNO is the latest in a series of USB Arduino
boards and the reference model for Arduino platform, then if we use this hardware we would be
has some advantages due to the up-to-date information to help we develop some devices.
Here is the features that Arduino UNO has:
Table 2.1 Arduino Features Table
Microcontroller ATmega 328 Operating Voltage 5 V
Input Voltage (recommended) 7-12 V
Input Voltage (limits) 6-20 V
Digital I/O Pins 14 (6 provide PWM output) Analog Input Pins 6
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 32 KB (ATmega 328) of which 0.5 KB used by bootloader SRAM 2 KB (ATmega 328)
EEPROM 1 KB (ATmega 328)
Clock Speed 16 MHz
9
2.3.1.1 Power sources
The power source of Arduino UNO could come through USB connection or an external power
supply, it is selected automatically. The external power supply could come from AC-to-DC
adapter or battery, the adapter could be connected by plugging a 2.1mm center –positive plug
into the board`s power jack and the battery could be connected by insert in the Gnd and Vin pin
headers of the power connector. The board can operate on an external power supply of 6 to 20
volts. If supplied less than 7V the board might be unstable, and if supplied more than 12V the
voltage regulator would overheat and could damage the board. It is recommended to use the
power sources range from 7 to 12 volts.
The power pins are as follows:
VIN the input voltage to the Arduino UNO board when it`s using an external power
source. We could supply voltage through this pin, or, if supplying voltage via the power
jack, access it through this pin.
5V this pin outputs a regulated 5V from the regulator on the board. The board could
be supplied with power either from the DC power jack (7-12V), the USB connector (5V),
or the VIN pin of the board (7-12V).
3V3 a 3.3V supply generated by the on-board regulator, maximum current draw is
50mA.
GND ground pins.
IOREF this pin on the Arduino board provides the voltage reference with which
microcontroller operates. A properly configured shield can read the IOREF pin voltage
and select the right power source or enable voltage translators on the outputs for working
with 5V or 3.3V.
2.3.1.2 Memory
The Arduino UNO board uses ATmega 328 microcontroller, it has 32 KB (with 0.5 KB used
for bootloader). It also has 2 KB of SRAM and 1 KB of EEPROM (which could be read and
written with the EEPROM library).
10
Figure 2.3 Memorize size
2.3.1.3 Input and output
All of the digital pins on the board could be used as an input or output, using pinMode(),
digitalWrite(), and digitalRead() functions. They operate at 5V. Each pin could provide or
receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of
20-50 kOhms. Some pins have specialized functions:
Serial: 0 (RX) and 1 (TX) used to receive (RX) and transmit (TX) TTL serial data.
These pins are connected to the corresponding pins of the ATmega8U2 USB-to-TTL
Serial chip.
External Interrupts: 2 and 3 these pins could be configured to trigger an interrupt
on a low value.
PWM: 3, 5, 6, 9, 10, and 11 provide 8-bit PWM output with the analogWrite()
function.
SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK) these pins support SPI
communication using the SPI library.
LED: 13 there is a built-in LED connected to digital pin 13. When the pin is HIGH
value, the LED is on, when the pin is LOW, it`s off.
The Arduino UNO board has 6 analog inputs, labeled A0 through A5, each of which
provide 10 bits resolution (i.e. 1024 different values). By default they measure from
ground to 5 volts, through is it possible to change the upper end of their range using the
AREF pin and the analogReference() function. Additionally, some pins have specialized
functionality:
TWI/I2C: A4 (SDA) and A5 (SCL) support TWI communication using the Wire
library.
11
There are a couple of pins on the Arduino UNO board:
AREF reference voltage for the analog inputs, could be used with analogReference().
Reset bring this line LOW to reset the microcontroller.
2.3.1.4 Communication
The Arduino UNO has some of facilities to communicate with a computer, another Arduino, or
other microcontroller. The ATmega 328 has a UART TTL (5V) serial communication, which is
available on the digital pin 0 (RX) and 1 (TX). ATmega 328 on the Arduino UNO board
channels this serial communication over USB and appears as a virtual com port to the software
on the computer. The `16U2 firmware uses the standard USB COM drivers, and no external
driver is needed (even in the Windows a .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 through USB-to-serial
chip and USB connection to the computer (but not for serial communication on pins 0 and 1).
A SoftwareSerial library allows for serial communication on any of the Arduino UNO`s digital
pins.
The ATmega 328 also supports I2C (TWI) and SPI communication, the Arduino software
includes a Wire library to simplify communication via I2C bus and SPI library for SPI
communication.
2.3.1.5 Programming
The Arduino UNO board could be programmed with the Arduino software. The ATmega 328
on the Arduino UNO board comes pre-burned with a boot-loader that allows us to upload new
code without the use of an external hardware programmer, it communicates using the original
STK500 protocol. The Arduino UNO could also bypass the boot-loader and program the
microcontroller through the ICSP (In-Circuit Serial Programming) header.
12
Figure 2.4 Example of programming the Arduino UNO with Arduino software
2.3.2 ATmega 328
Atmega328 is a single chip micro-controller created by Atmel and belongs to megaAVR series.
The ATmega 328 on Arduino UNO Board is a low power CMOS 8-bit microcontroller based
on the AVR enhanced RISC architecture, it could execute the powerful instructions in a single
clock cycle. ATmega 328 also could achieves throughputs approaching 1MIPS per MHz which
could allow the system-designer to optimize power consumption versus processing speed.
The packaging of ATmega 328 that used in this project is 28-lead PDIP, it is become the main
microcontroller of Arduino UNO, and the pin mapping of the function is as shown in figure
below.
13
Figure 2.5 Arduino UNO & ATmega328 pin mapping
Which Atmega328 pin alternative function are listed in this figure below.
14
Figure 2.6 ATmega328’s alternative function
The features of ATmega328 are shown in the table below.
ATmega328P Features
Feature Value
Flash 32k
EEPROM 1k
RAM 2k
I/O Pins 23
Interrupts 26
USARTS 1
USI 0
SPI 1
ADC Channels 6
Timers (8-bit) 2
Timers (16-bit) 1
PWM (8-bit) 4
15
PWM (16-bit) 2
Characteristic Value
Power Consumption (approximate) 0.6mA/MHz
Maximum I/O Current (per pin) 40mA
Maximum I/O Current (all ports) 100mA(low)/150mA(high)
Maximum I/O Current (total) 200mA (PDIP)
Maximum I/O Current (total) 400mA (PDIP/QFP/MLF)
Figure 2.7 ATmega328’s features
2.4 Sensor
Sensor on robot is functioning to sense the environment within it, just like a living-thing, sensor
would give the first information to be received by the brains to determine how it should react.
Sensor on robot should be the first thing that determine as the input to the controller and one of
the important thing in the control system of the robot. To achieve the objective of traveling in
the open space first, the robot needs to sense of sight or touch, depending on the sensor
technology that we used. The robot need a sensor that could sense the distance to an obstacle, it
could be achieved by Infrared (IR) or Ultrasonic (Sonar) sensors.
Infrared sensors are type of light sensor which could sense the infrared light-level to measure it
as a distance which could be determined by given the light of infrared to the obstacle and receive
it again. Ultrasonic sensors are type of sound sensor which could sense the ultrasonic sound-
level to measure it as a distance which could be determined by given the ultrasonic sound to the
obstacle and receive it again. This phenomena is called proximity or distance detection.
Proximity sensors only detect whether or not an object is within a predetermined range from the
robot, while the distance sensors determine the actual distance between the object and the robot.
In this project the robot would use the Infrared sensors, not the Ultrasonic sensors. The Infrared
sensors much cheaper than the Ultrasonic sensors, the objective of this project also could be
achieved by the Infrared sensors only without using the Ultrasonic sensors or both. Then, on the
next explanation, we just explain about the Infrared sensors.
16
2.4.1 Infrared (IR) sensors
Infrared sensor should consist of an infrared transmitter to sends out an invisible beam light into
the environment and an infrared receiver that absorbs the beam of light that is reflected back.
The angle of the reflected beam indicates the proximity of the infrared receiver to the object that
is reflecting the light. The microcontroller of the robot uses the changes in angle to measure/react
the distance of the robot from object ahead. The process of the sensors is drawed in the figure
below.
Figure 2.8 Infrared sensor`s process
2.4.1.1 IR emitter TSAL6100
TSAL6100 is an infrared 940nm emitting diode in GaAlAs/GaAs technology with high radiant
power molded in a plastic package. In this project, the IR Emitter is functioning as the
transmitter in the infrared sensor system. It would transmit the signal with certain wavelength
to be received by the IR Receiver.
17
Figure 2.9 IR Transmitter in symbol
Figure 2.10 IR Transmitter in hardware
Based on its datasheet, here is the main specification of TSAL6100:
Table 2.2 TSAL6100 Main Specification
*Note: - Ie is radiant intensity - φ is angle of half intensity
- λp is peak wavelength - tr is rise time
Which the test condition under 25 °C make the characteristic such as:
COMPONENT Ie (mW/sr) φ (deg) λp (nm) tr (ns)
TSAL6100 130 ±10 940 800
18
Table 2.3 TSAL6100 Basic Characteristics
PARAMETER TEST
CONDITION
SYMBOL MIN. TYP. MAX. UNIT
Forward
voltage
IF= 100 mA, tp= 20
ms
VF 1.35 1.6 V
IF= 1 A, tp= 100 μs VF 2.6 3 V
Temperature
coefficient of
VF
IF= 1 mA TKVF - 1.8 mV/K
Reverse current VR= 5 V IR 10 μA
Junction
capacitance
VR= 0 V, f = 1 MHz,
E = 0
Cj 25 pF
Radiant
intensity
IF= 100 mA, tp= 20
ms
Ie 80 130 400 mW/sr
IF= 100 mA, tp= 20
ms
Ie 650 1000 mW/sr
Radiant power IF= 100 mA, tp= 20
ms
Фe 35 mW
Temperature
coefficient of
Фe
IF= 20 mA TK Фe - 0.6 %/K
Angle of half
intensity
Φ ± 10 deg
Peak
wavelength
IF= 100 mA λp 940 nm
Spectral
bandwidth
IF= 100 mA ∆λ 50 nm
Temperature
coefficient of λp
IF= 100 mA TK λp 0.2 nm/K
Rise time IF= 100 mA tr 800 ns
Fall time IF= 100 mA tf 800 ns
Virtual source
diameter
Method: 63 %
encircled energy
D 3.7 mm
19
Figure 2.11 Relative Radiant Power vs. Wavelength
The sensor has the characteristic of relative radiant power with its wavelength like in the
figure, which has peak wavelenght at 940nm.
2.4.1.2 IR receiver/phototransistor HPTB5-14D-B
HPTB5-14D-B is an infrared receiver/phototransistor, it has sensitivity wavelength between
760-1000nm. In this project, the phototransistor is functioning as the receiver in the infrared
sensor system. It would receive the signal with certain wavelength that transmitted by the IR
Emitter.
Figure 2.12 IR Receiver in hardware
20
Figure 2.13 IR Receiver in symbol
Based on its datasheet, here is the main specification of HPTB5-14D-B:
Table 2.4 HPTB5-14D-B Main Specification
*Note: - λ is sensitivity wavelength - φ is angle of half intensity
- λp is peak wavelength - tr is rise time
Which the test condition under 25 °C make the characteristic such as:
Table 2.5 HPTB5-14D-B Basic Characteristics
PARAMETER SYMBOL TEST
CONDITION
MIN TYP MAX UNIT
Angle of Half
Sensitive
Φ 30 deg
Collector-
Emitter
Voltage
Vceo Ic=1mA,
Ee=0mw/cm2
30 V
Emitter-
Collector
Voltage
Veco Ic=100μA,
Ee=0mw/cm2
5 V
COMPONENT LENS
COLOR
φ (deg) λ(nm) λp (nm) tr (μs)
HPTB5-14D-B Black 30 760-1000 940 15
21
Collector-
Emitter
Saturation
Voltage
Vces Ic=0.5mA,
Ib=100μA
0.4 V
Collector
Current
(Saturation)
Ic Vce=5V,
Ee=0.5mw/cm2
0.8 3.0 12 mA
Collector
Dark Current
Iceo Vce=20V,
Ee=0mw/cm2
100 nA
Rise Time Tr Vce=5V,
Ic=1mA,
RL=1000Ω
15 μS
Fall Time Tf 15 μS
Peak
Wavelength
Λp 940 nm
Sensitivity
Wavelength
Λ 760 1000 nm
Figure 2.14 Relative sensitive vs. wavelength
22
The sensor has the characteristic of relative sensitive with its wavelength like in the figure,
which has range effectiveness between 760-1000nm
2.5 Motor
Two important mechanism things of a mobile robot are its motors and motor controllers. The
process of choosing a motor of a robot is a significant undertaking because the motor
ultimately selected has an impact on many other aspects of the robot. This project uses DC
Motor, which the specifications are listed as follows:
Table 2.6 5VDC Motor Specification
Voltage Ratio Current (max) Speed (max) Torque
5VDC 287:1 100mA 62rpm 3kg.cm
2.6 Arduino Motorshield L293
The motors must have “neuron” to deliver order from the microcontroller, we call this neuron
as motor driver. In this project Arduino Motorshield L293 is a package of neuron that we
need, it is a motor driver’s module that could connect directly into our microcontroller
(Arduino UNO).
Figure 2.15 Arduino Motorshield L293
23
This module allows Arduino to drive two channel DC motors. It uses L293B chip which
deliveries output current up to 1A each channel. The speed control is achieved through
conventional PWM which can be obtained from Arduino’s PWM output Pin 5 and 6. The
enable/disable function of the motor control is signaled by Arduino Digital Pin 4 and 7. The
module is powered directly from Arduino.
Table 2.7 Arduino Motorshield Pin Use
Pin Function
Digital 4 Motor 2 Direction control
Digital 5 Motor 2 PWM control
Digital 6 Motor 1 PWM control
Digital 7 Motor 1 Direction control
2.6.1 L293B chip
Arduino Motorshield 293 uses L293B chip as the main driver, it is quad push-pull drivers that
capable of delivering output curents to1A per channel. Each channel is controlled by a TTL-
compatible logic input and each pair of drivers (a full bridge) is equipped with an inhibit input
which turns off all four transistors. L293B is package in 16-pin plastic DIP.
24
Figure 2.16 L293B Chip
The absolute maximum ratings of L293B listed as below:
Table 2.8 Absolute Maximum Ratings of L293B
Symbol Parameter Value Unit
Vs Supply Voltage 36 V
Vss Logic Supply Voltage 36 V
Vi Input Voltage 7 V
Vinh Inhibit Voltage 7 V
Iout Peak Output Current (non-repetitive t = 5ms) 2 A
Ptot Total Power Dissipation at Tground-pins = 80 ̊C 5 W
Tstg. Tj Storage and Junction Temperature -40 to +150 ̊C
The electrical characteristics for each channel, Vs = 24V, Vss = 5V, Tamb = 25 ̊ C, unless
otherwise specified:
25
Table 2.9 Electrical Characteristics of L293B
Symbol Parameter Test Conditions Min. Typ. Max. Unit
Vs Supply Voltage Vss 36 V
Vss Logic Supply Voltage 4.5 36 V
Is Total Quiescent Supply Current
Vi = L Io = 0 Vinh = H
2 6
mA Vi = H Io = 0 Vinh =
H 16 24
Vinh = L
4
Iss Total Quiescent Logic Supply
Current
Vi = L Io = 0 Vinh = H
44 60
mA Vi = H Io = 0 Vinh =
H 16 22
Vinh = L
16 24
VIL Input Low Voltage -0.3 1.5 V
VIH Input High Voltage Vss < = 7V 2.3
Vss
V Vss > 7V 2.3 7
IIL Low Voltage Input Current VIL = 1.5V -10 µA
IIH High Voltage Input Current 2.3V 30 100 µA
VinhL Inhibit Low Voltage -0.3 1.5 V
VinhH Inhibit High Voltage Vss < = 7V 2.3
Vss
V Vss > 7V 2.3 7
IinhL Low Voltage Inhibit Current VinhL = 1.5V -30 -100 µA
IinhH High Voltage Inhibit Current 2.3V < = VinhH < = Vss – 0.6V ±10 µA
VCEsatH Source Output Saturation Voltage Io = -1A 1.4 1.8 V
VCEsatL Sink Output Saturation Voltage Io = 1A 1.2 1.8 V
tr Rise Time 0.1 to 0.9 Vo (*) 250 ns
tf Fall Time 0.9 to 0.1 Vo (*) 250 ns
ton Turn-on Delat 0.5 Vi to 0.5 Vo (*) 750 ns
toff Turn-off Delay 0.5 Vi to 0.5 Vo (*) 200 ns
Note: (*) See Figure 2.17
26
Figure 2.17 Switching Timers
2.7 LCD LMB162AFC
LCD LMB 162AFC means it has 16 characters length and 2 rows. The LCD used in this project
is LMB 162AFC manufactured by TOPWAY. RS is high when it requires to send text data that
should be displayed on LCD, e.g printing a word; it is low for commanding instruction data,
such as clear screen, move cursor, and etc. E line is high, which tells it to receive data; first it
sets to low, then decide the value of RW and RS, after that bring E high logic to tells it that data
is sent, then give low logic again to E.
Here is the block diagram:
Figure 2.18 LCD Block Diagram
27
This LCD consist of 16 pins which are:
Table 2.10 LCD Pin Description
Pin No. Pin name I/O Description
1 VSS Power Ground
2 VDD Power Positive power supply
3 V0 Power LCD contrast reference supply
4 RS Input Register Select
RS=HIGH: transferring display data
RS=LOW: transferring instruction data
5 R/W Input Read/Write Control bus
R/W=HIGH: read mode selected
R/W=LOW: write mode selected
6 E Input Data enable
7 DB0
I/O
Bi-directional tri-state Data bus
In 8-bit mode, DB0 ~ DB7 are in use
In 4-bit mode, DB4 ~ DB7 are in use, DB0 ~ DB3 leave open
: :
14 DB7
15 BLA Power Backlight positive supply
16 BLK Power Backlight negative supply
There are also commonly used commands and instructions for LCD, such as:
28
Table 2.11 LCD Instructions
No. Instructions
Code
Function
RS
R/W
DB
7
DB
6
DB
5
DB
4
DB
3
DB
2
DB
1
DB
0
1 Clear Display 0 0 0 0 0 0 0 0 0 1 Write “20h” to DDRAM and set
DDRAM Address (AC) to “00h”
2 Return Home 0 0 0 0 0 0 0 0 1 X
Set DDRAM Address (AC) to “00h” and
return cursor to its original position if
shifted (DDRAM content are not change)
3 Entry Mode
Set 0 0 0 0 0 0 0 1 I/D S
Set cursor moving direction and specify
display shift, during data read and write
of DDRAM and CGRAM
4 Display
ON/OFF 0 0 0 0 0 0 1 D C B
D=1, display on; D=0, display off
C=1, cursor on; C=1, cursor off
B=1, cursor blinking on; B=0, cursor
blinking off
5 Cursor or
Display Shift 0 0 0 0 0 1 S/C R/L X X Move the cursor or shift the display
6 Function Set 0 0 0 0 1 DL N F X X
DL=1, 8-bit; DL=0, 4-bit
N=1, 2-line; N=0, 1-line
F=1, 5x11 dots; F=0, 5x8 dots
7 Set CGRAM
Address 0 0 0 1 AC5 AC4 AC3 AC2 AC1 AC0 Set CGRAM Address in address counter
8 Set DDRAM
Address 0 0 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0 Set DDRAM Address in address counter
9
Read Busy
Flag &
Address
0 1 BF AC6 AC5 AC4 AC3 AC2 AC1 AC0
Check the system status and get the
address counter content (AC6 ~ AC0).
BF=1, busy; BF=0, ready
10 Write data to
RAM 1 0 D7 D6 D5 D4 D3 D2 D1 D0
Write the data into internal RAM, where
the address counter pointing at.
11 Read data
from RAM 1 1 D7 D6 D5 D4 D3 D2 D1 D0
Read the data from internal RAM, where
the address counter pointing at.
29
CHAPTER 3
DESIGN AND IMPLEMENTATION
3.1 Preliminary Remarks
These chapters will mainly talks about implementation and design of the desired project. All of
the designs written in this chapter are based on theories and knowledge that been gathered by
the author. The designs that will be elaborated in this chapter are circuitries of motor driver’s
module (Arduino Motorshield L293), sensors, and LCD to the microcontroller.
3.2 Hardware Design
The main hardware consisting of microcontroller unit, motor driver’s module, sensor, LCD, and
motor. The overall of the project is pictured in figure below.
Figure 3.1 Final project block diagram
Microcontroller acts as processor that will compile the inputs and give outputs regarding to
several perimeters set for this project.
30
Firstly 9V battery is converted into 5Vdc by the Arduino, then 5Vdc powers the entire hardware
(sensors, driver motor’s module, motors and LCD). The arduino also convert the analog signal
from sensors into the digital signal (like ADC), so it can be read in the microcontroller. Since
Arduino UNO have internal ADC, then external ADC is not required to fulfill the purpose of
the project. By converting the analog signal becomes digital, LCD can display the sensor
measurement through ADC. The value of this ADC later on will be divided into few ranges to
determine different motor’s speed with respect to sensor reading.
The ADC value would be processed in the program of the arduino regarding to sensor reading;
in certain value range, the arduino and driver motor’s module will response whether to makes
the motor working on full, half, or less power. The robot working is done by software/ program
that will be explained in this chapter.
3.2.1 Infrared-sensor`s module
Infrared-sensor`s module is a circuitry that will read and write signal to the microcontroller so
the microcontroller could choose the action in the programs. This project use a pair (two)
Infrared-sensor`s module to fulfill the objective, the sensors location are in the right-side and
front-side of the robot. This sensor has 3 pins; Vcc, Gnd, and Vout pins, where the Vcc and Gnd
are connected to the Vcc and Gnd pins of microcontroller, and Vout pin is connected to the
analog input pins (0, 1) in the microcontroller.
Figure 3.2 Infrared-sensor`s module circuitry
31
The IR Emitter TSAL 6100 (D1) transmit the signal to the wall/obstacles, the wall/obstacles
reflect the signal back and the signal is received by IR Receiver/Phototransistor HPTB5-14D-
B (T1). The IR Emitter has the characteristic of relative radiant intensity with angular
displacement like in the figure, which has the most effective radiance at 0° (perpendicular),
while the IR Receiver sensor has the characteristic of relative radiant sensitivity with angular
displacement like in the figure, which has the most sensitive radiance at -15° until 15°
(30deg).
.
Figure 3.3 Relative Radiant Intensity vs. Angular Displacement IR Transmitter & Receiver
After the IR Receiver receives the analog signal, the signal is converted to digital in the Arduino
UNO, so it could be read and processed in the microcontroller.
3.2.2 Arduino Motorshield L293
Arduino Motorshield L293 consist the L293B chip, the driver means it is working to drive the
current to control the movement of the motors, it consist H-Bridge circuit as the basic circuit.
The speed control is achieved through conventional PWM which can be obtained from
Arduino’s PWM output Pin 5 and 6. The enable/disable function of the motor control is signalled
32
by Arduino Digital Pin 4 and 7. The driver receive the command from Arduino to react as the
program written. The code/program would be explained in the software session.
Figure 3.4 L293B Block Diagram
3.2.2.1 H-Bridge circuit
The H-Bridge circuit is commonly used to control DC Motors, the idea is that five electrical
The L293B works as the figure and table below:
Figure 3.5 DC motor controls
33
Table 3.1 DC Motor Controls Description
Inputs Function
Vinh = H C = H; D = L Turn Right
C = L; D = H Turn Left
C = D Fast Motor Stop
Vinh = L C = X; D = X Free Running Motor Stop
*Note: H = High, L = Low, X = Don’t Care
3.2.3 LCD LMB162AFC
This project use LCD LMB162AFC, it is in 4-bit mode, because the characters that the author
used just alphabet and numerical. The LCD has 16X2 characters to displays value of ADC
relating to sensor reading. It is useful to provide that information, since the controller works at
certain ranges of ADC value. By displaying it, it will make the observation easier.
The connection of the LCD is assembled this way:
Table 3.2 LCD Pin Description
LCD Pins Arduino Pins Potentiometer Pins Function
1 Gnd Gnd Logic
2 Vcc Vcc
3 Vout Contrast
4 8
Register Select (RS) *Microcontroller tells the LCD whether it wants to display the data
5 Gnd Not used
6 13
Enable (E) *Microcontroller tells the LCD when data is ready for reading
11 9 DB4
12 10 DB5 Data Pins
13 11 DB6
14 12 DB7
15 Vcc Backlight
16 Gnd
34
3.3 Software Design
For programming purpose, this project use Arduino language, which has the C language as the
basic. The Arduino language compiler that’s used is Arduino IDE. This sub-chapter will
explains the usage of the software to utilize components, such as imported library, declaration
of variable, setting up of the variable, and the looping programs that required to fulfill the
objective of this project.
3.3.1 Imported library
The library is used quite common when creating Arduino based device. It is usually used to
make it easier to develop the program. The library that used in this project is LiquidCrystal, the
function is to make it easier to connect the LCD to Arduino board, the imported library is written
this way:
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(13, 8, 9, 10, 11, 12);
This part of program means pins 8, 9, 10, 11, 12, and 13 of the LCD are used to connect to the
Arduino board.
3.3.2 Declaration of variable
This part of program means pins 4, 5, 6, and 7 of the Arduino are used to connect to the Arduino
Motorshield L293. This part used int as the declaration, because the variable consists of
numerical data, the declaration is written this way:
int motorright = 6; // the PWM pin
int motorleft = 5; // the PWM pin
int arahmotorleft = 4; //direction control pin
35
int arahmotorright = 7; //direction control pin
The pin 5 and 6 are PWM pins, it means the Arduino board receive the analog signal (numerical)
in these pins. The signal that’s received by Arduino board is used to control the speed of the
motors; which pin 5 is connected to right-side motor, and pin 6 is connected to the left-side
motor. The pin 4 and 7 are digital pins, it means the Arduino board receive the digital signal in
these pins. The signal that’s received by Arduino board is used to control the direction of the
motors (H-bridge circuit); which pin 4 controls the left-side motor, and pin 7 controls the right-
side motor.
3.3.3 Setting-up the variables
This part is used to set up the variables, so the program could identify the variables that are used.
To enables this set up there must be a function (main) called void setup, the set-up is written as:
void setup() {
// initialize the Arduino Motorshield L293 pin as an output:
pinMode(motorleft, OUTPUT);
pinMode(motorright, OUTPUT);
pinMode(arahmotorleft, OUTPUT);
pinMode(arahmotorright, OUTPUT);
}
The pinMode is a function to set the variables in the current pin as inputs or outputs, where
OUTPUT is a declaration to the program that the variable is set as an output.
3.3.4 The looping/main programs
This looping part in the program is signed by void loop, the function means that the program is
always looping until it is stopped (by power or program).
void loop(){
36
// read the state of the pushbutton value:
PrintLCD();
Fuzzy();
delay(100);
}
The function above will be called in the main program. Before command and data function can
be use, the following initialization for command and data should be done like that. PrintLCD
and Fuzzy are the variables that will looping in this program. The delay function is to limit the
looping (not too fast and slow), which is set to 100ms.
3.3.4.1 PrintLCD program
This part of looping is to set the display in the LCD based on the sensor signals that received by
the Arduino board. The basic is to set void to PrintLCD, which means the LCD start to printing.
The program should be done as:
void PrintLCD(){
// lcd printing
String stringfront = String (analogRead(0));
String stringright = String (analogRead(1));
lcd.begin (16, 2); //initiate the LCD 16×2
lcd.print ("SENSOR F = " + stringfront);
lcd.setCursor (0, 1); //change the cursor line
lcd.print ("SENSOR R = " + stringright);
delay(100);
}
37
String is a function to declare an array of type char and null-terminate it, this function also could
print the data into the LCD, but it could not consist the variables that would be used as equation
(for example: m*n). The method that used by this function is reading subsequent bytes of
memory continuously, string+x would be a formula in this function. The analogRead function
is to read the analog signal input in the Arduino board, which are given by analog pin 0 and 1
and has a value from 0-1023 (ADC). The algorithm of LCD in this project is:
Set the PrintLCD as a part of looping program
Select the variable that’s used in String function.
Select the analog signal input in the String function , in this case is analog pin 0 and 1.
Initiate the LCD 16X2, signed by lcd.begin (16, 2);
Read the value of analog signal in pin 0 and 1 in analog pin so it could printed in the
LCD, the function is analogRead.
Print the value of sensor front (analog pin 0) continuously in the first line (0), signed by
lcd.print ("SENSOR F = " + stringfront);
Change the cursor line from (0) to (1) to print the next variable, signed by lcd.setCursor
(0, 1);
Print the value of sensor right (analog pin 1) continuously in the second line (1), signed
by lcd.print ("SENSOR R = " + stringright);
Wait 100ms to response to the next signal value, signed by delay(100);.
The value range of this ADC that printed in the LCD is from 0-1024 (0-15cm).
3.3.4.2 Fuzzy program
The other looping variable is fuzzy, which is signed by void Fuzzy. In this part the program
would set and give logic in the Arduino board to the Arduino Motorshield and motors. The
program consist the code of fuzzy logic to fulfill the objective in this project, which are how to
avoid the obstacle and always move smoothly in the right-side. This code also require the analog
signal from the sensors as the input in the Arduino board. The code is written as follows,
void Fuzzy(){
int sensorStatefront = analogRead(0); // variable for reading the pushbutton status
38
int sensorStateright = analogRead(1);
digitalWrite(arahmotorleft, HIGH);
digitalWrite(arahmotorright, HIGH);
}
if (sensorStatefront > 700){ //undetect, turn to the right-side
if (sensorStateright > 680){
analogWrite(motorright, 30);
analogWrite(motorleft, 90);
}
if (sensorStateright < 650){
analogWrite(motorright, 40);
analogWrite(motorleft, 80);
}
if (sensorStateright < 600){
analogWrite(motorright, 50);
analogWrite(motorleft, 70);
}
if (sensorStateright < 490){
analogWrite(motorright, 70);
analogWrite(motorleft, 70);
}
if (sensorStateright < 380){
analogWrite(motorright, 80);
analogWrite(motorleft, 60);
}
}
if (sensorStatefront < 750){ //obstacle on the front, turn left
analogWrite(motorright, 80);
39
analogWrite(motorleft, 30);
}
if (sensorStatefront < 730){
analogWrite(motorright, 70);
analogWrite(motorleft, 15);
}
if (sensorStatefront < 680){
analogWrite(motorright, 75);
analogWrite(motorleft, 0);
}
}
}
This part uses the int function as a declaration that the input variable is numerical and should be
read in the analog pin 0 and 1 (automatically convert to digital, like ADC), signed by analogRead
function. This function could consist an equation variables (for example: m*n). The variables
are sensorStatefront (0) and sensorStateright (1). This part of program also consist the
digitalWrite to command that the variables should be written in any state; HIGH and LOW,
while the HIGH state means the output would has 5V voltage. The algorithm of this part of
programs should be:
Set the Fuzzy variable as a part of looping program.
Declare the variables that are used in this Fuzzy part, it get the inputs from analog pin 0
and 1, signed by int sensorStatefront = analogRead(0); and int sensorStateright =
analogRead(1);
Set the variables digitally of arahmotorleft and arahmotorright into HIGH, signed by
digitalWrite(arahmotorleft, HIGH); and digitalWrite(arahmotorright, HIGH);
Set the condition and command in the program using if function as the condition and
analogWrite as the command to set the speed of motors.
The if function is read the condition from the input of signals (ADC) that are read by
sensors (sensorStatefront & sensorStateright), the range of ADC is from 0 to 1023
40
because the ADC has 10-bit resolution (based on the ATMega328 datasheet), it represent
the distance to the object (0-15cm).
The analogWrite function is commanding the right-side and left-side motors depends on
the condition the robot is faced, the range of speed value in the program is 0-255 because
the Arduino Motorshield use PWM pin and the PWM output of the Arduino UNO is 8-
bit and has a 980Hz frequency (pin 5 and 6), it represent the speed of the motor (stop,
slow, fast).
The code that is used to fulfill the objective of this project is written as:
if (sensorStatefront > 700){ //undetect, turn to the right-side
if (sensorStateright > 680){
analogWrite(motorright, 30);
analogWrite(motorleft, 90);
}
if (sensorStateright < 650){
analogWrite(motorright, 40);
analogWrite(motorleft, 80);
}
if (sensorStateright < 600){
analogWrite(motorright, 50);
analogWrite(motorleft, 70);
}
if (sensorStateright < 490){
analogWrite(motorright, 70);
analogWrite(motorleft, 70);
}
if (sensorStateright < 380){
analogWrite(motorright, 80);
analogWrite(motorleft, 60);
}
}
41
if (sensorStatefront < 750){ //obstacle on the front, turn left
analogWrite(motorright, 80);
analogWrite(motorleft, 30);
}
if (sensorStatefront < 730){
analogWrite(motorright, 70);
analogWrite(motorleft, 15);
}
if (sensorStatefront < 680){
analogWrite(motorright, 75);
analogWrite(motorleft, 0);
}
}
}
The code above is get by research on the commanding function based on the trial-error.
This program works in certain condition such as the intensity of the light (it effecting
much), the color and basic material of the obstacle (in this project author uses light-green
Semi-Styrofoam carpet), and stale power supply (full charge 9V battery rechargeable).
42
3.3.5 Project algorithm
Here is the flow chart of project algorithm:
Figure 3.6 Flow chart of the project
Firstly, initialization is done by software as explained above. Then the sensors send the data to
microcontroller, the analog signal is converted into digital in the microcontroller automatically.
43
After that the LCD would show the value of ADC on the front-side and right-side of the sensors.
Function void loop(), always loop the Fuzzy and PrintLCD variables, while PrintLCD and
Fuzzy always processed linearly. The Fuzzy program is the main program to control the motors
through motor driver, it would check the condition by the if function and give the command
based on the condition by the analogWrite function. The objective in this program is to make
the robot follow the right-side of the maze and escape it. The end of the process is when the
robot made a move by the program, then the process is returned to check and converting ADC
value again.
44
CHAPTER 4
PROJECT RESULT AND ANALYSIS
4.1 Preliminary Remarks
This chapter contains final result of the project, and analysis from author’s point of view during
working on this project.
4.2 Project Result
The figures shown below are the appearance of the device.
Figure 4.1 The right-side of the device part 1
45
Figure 4.2 The right-side of the device part 2
Figure 4.3 The up-side of the device
46
Figure 4.4 The Infrared sensors
Figure 4.5 LCD shows ADC value
47
Figure 4.6 Arduino Motorshield as the motor driver’s module
Figure 4.7 The simple maze
48
The project is tested in the room that has 9 lux light intensity, because the infrared sensor is very
sensitive to the change of light, the author should tested it in the space that has stable lightness.
The light intensity is measured by an application called CPU-Z, it is one of the android
application that reads the sensors on the smartphone Sony Xperia V.
Figure 4.8 Light intensity test
The LCD would read the ADC data in the sensors, it makes the author easier to read and observes
to make sure the project is fulfill the objective. The ADC data that author`s tested are limited at
0 to 15 cm (min-max) and in the room that has 9 lux light intensity. Theoretically, the ADC
values versus distance would make a linear graph, but the author has facing a differences of
value while tested and here are the result:
Table 4.1 ADC of Front-Side Sensor
Distance (cm) ADC Tested ADC Theoretically
0 35 0
1 45 68.2
2 55 136.4
3 175 204.6
4 435 272.8
5 550 341
6 625 409.2
7 665 477.4
8 705 545.6
49
9 735 613.8
10 750 682
11 755 750.2
12 775 818.4
13 780 886.6
14 785 954.8
15 790 1023
From table above, the following graph can be obtained:
Figure 4.9 Front-side sensor`s ADC comparison
The right-side sensor has different result as follows:
Table 4.2 ADC of Right-Side Sensor
Distance (cm) ADC Tested ADC Theoretically
0 35 0
1 45 68.2
2 50 136.4
3 210 204.6
4 440 272.8
5 545 341
6 590 409.2
50
7 645 477.4
8 660 545.6
9 690 613.8
10 700 682
11 710 750.2
12 720 818.4
13 725 886.6
14 730 954.8
15 740 1023
The graph also has different result:
Figure 4.10 Right-side sensor’s ADC comparison
The value of ADC could be obtained theoretically from this calculation:
��� = ��������(��)
�� �� × ���� (���. ����� �� ���) (4.1)
51
The voltage in the sensors are the input of ADC, the voltage data that author`s tested are limited
at 0 to 15 cm (min-max) and in the room that has 9 lux light intensity. Theoretically, the voltage
values versus distance would make a linear graph, but the author has facing a differences of
value while tested and here are the result:
Table 4.3 Front-Side Sensor’s Voltage
Distance (cm) Voltage Tested (Voltage) Voltage Theoretically (Voltage)
0 0.17 0.00
1 0.22 0.33
2 0.27 0.67
3 0.86 1.00
4 2.13 1.33
5 2.69 1.67
6 3.05 2.00
7 3.25 2.33
8 3.45 2.67
9 3.59 3.00
10 3.67 3.33
11 3.69 3.67
12 3.79 4.00
13 3.81 4.33
14 3.84 4.67
15 3.86 5.00
From table above, the following graph can be obtained:
52
Figure 4.11 Front-side sensor`s voltage comparison
The right-side sensor has different result as follows:
Table 4.4 Right-Side Sensor’s Voltage
Distance (cm) Voltage Tested (Volt) Voltage Theoretically (Volt)
0 0.17 0.00
1 0.22 0.33
2 0.24 0.67
3 1.03 1.00
4 2.15 1.33
5 2.66 1.67
6 2.88 2.00
7 3.15 2.33
8 3.23 2.67
9 3.37 3.00
10 3.42 3.33
11 3.47 3.67
12 3.52 4.00
13 3.54 4.33
14 3.57 4.67
53
15 3.62 5.00
The graph also has different result:
Figure 4.12 Right-side sensor’s voltage comparison
The voltage values could be obtained theoretically from this calculation:
� = ���(������)
����(��� ���. �����) × �� (4.2)
After the ADC is read by the microcontroller, it would trigger the command to PWM to control
the movement of the device. The PWM (Pulse-width modulation) controls the speed of the
motors, which could cause the device to move straight forward, turn right, and turn left. Briefly,
a PWM signal is a digital square wave, where the frequency is constant, but that fraction of the
time of the signal is on (duty cycle) can be varied between 0 and 100% depends on the PWM
signal that is written on the motor driver. The PWM signal’s range in the Arduino IDE is
between 0 and 255, it is linearly to the duty cycle of its PWM. Here is the data that collected
during the test:
0.00
1.00
2.00
3.00
4.00
5.00
6.00
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Vo
ltag
e
Distance (cm)
Data Comparison
Voltage (tested) Voltage (theoretically)
54
Figure 4.13 PWM read in oscilloscope
The PWM test using oscilloscope in the channel 1 with 0.1ms time/division and 5 volts/division.
After collecting some data of PWM, the duty cycle could be read from the oscilloscope. The
way to read it is seeing the width of HIGH pulse then divided it by 10 (the full duty cycle in this
PWM read) and multiply it by 100%.
Table 4.5 Duty Cycle Data
ADC PWM Duty Cycle Tested (%) Duty Cycle Theoretically (%)
Front Right Left Right Left Right Left Right
0-679 X 0 75 0 30 0.00 29.41
680-729 X 15 70 3 25 5.88 27.45
730-749 X 30 80 11 30 11.76 31.37
>750
0-379 60 80 22 26 23.53 31.37
380-489 70 70 25 25 27.45 27.45
490-559 70 50 26 18 27.45 19.61
600-649 80 40 29 14 31.37 15.69
>650 90 30 32 12 35.29 11.76
The table above shows all of the data that connected with PWM data (ADC as the input, then
the PWM, and duty cycle of the PWM itself). There is such differences results while the author’s
tested with the results by calculation. The differences could see in the figure below:
55
Figure 4.14 Left-side motor`s duty cycle comparison
Figure 4.15 Right-side motor`s duty cycle comparison
The duty cycle could be measured from reading the wave in the oscilloscope, but theoretically
the duty cycle values could be obtained from this calculation:
���� ����� =��� ���
��� (��� ���) × ���% (4.3)
56
The differences could be showed like in the table below:
Table 4.6 Differences of the Duty Cycles on the Left Motor (Pin 5)
Duty Cycle Left Tested Duty Cycle Left Theoretically Differences (%)
0 0.00 0.00
3 5.88 49.00
11 11.76 6.50
22 23.53 6.50
25 27.45 8.93
26 27.45 5.29
29 31.37 7.56
32 35.29 9.33
Table 4.7 Differences of the Duty Cycles on the Right Motor (Pin6)
Duty Cycle Right Tested Duty Cycle Right Theoretically Differences
(%)
30 29.41 2.00
25 27.45 8.93
30 31.37 4.38
26 31.37 17.13
25 27.45 8.93
18 19.61 8.20
14 15.69 10.75
12 11.76 2.00
The data above is come from below equation:
����������� = ����� ����� ������������� − ���� ����� ��������
���� ����� �������������� × ���% (4.4)
The fuzzy-part of the program contain delay, the delay has an effect to the success rate of the
results. The part of the program is written as:
57
void loop(){ // the function to loop the variables in the program
PrintLCD();
Fuzzy();
delay(100); // the looping delay that effecting Fuzzy and PrintLCD function
}
This part of the program is set the variables that would looping, one of the variable is Fuzzy
function which is contain the command to set PWM to the motor driver based on the ADC
condition. In the end of this part of the program, there is delay function, it has function to give
a break between the looping code/program. The number of the delay above is 100 which means
there will be a 100ms delay time before the looping program is starting again. In fact, the delay
value is give such an effect to the success rate of the result while on the site. By testing each of
delay for 9 times, here are the average of result:
Table 4.8 Fuzzy Delay vs Success Rate
Fuzzy Delay (ms) Result Success Rate (%) Note
100 √ 100 Stable & Success
200 √ 100 Stable & Success
300 √ 66.66 Unstable & Success
400 × 33.33 Unstable & Fail
500 × 0 Fail
600 × 0 Fail
700 × 0 Fail
The device could fulfill the objective with stable movement at 100 and 200 millisecond delay,
at 300 millisecond it still success but not stable (above 50%), while at the point of 400
millisecond the device start to fail, it means the success rate is below 50%.
From the above table, the graph could be obtained:
58
Figure 4.16 Fuzzy delay and success rate graph
4.3 Analysis
As can be seen in data above, slight differences can occur and possible because of several
aspects:
Changes of the light intensity
Misreading the measurement devices (oscilloscope).
Error tollerance from measurement devices, and electrical components itself.
Several approaches are done during the making of this project.
Number correction.
4.4 Discussion
When working on this project, author find several problems. To overcome the problems, author
seek aid from final project supervisor, and also other reliable references. The major problems
that faced by author will be elaborated below.
Infrared sensors are produce different ADC value in the meantime, it possibly because the light
intensity of the room is changing while the author tested it. Since the environment on the tested
59
site just has a stable light intensity in the night, then the author should tested it after 6 pm. Even
though sometimes the problem still occur but not as intense as in the noon.
The ADC shows different value while tested with the calculation. It shows 35 when it must be
0 at 0 centimeters (minimal value), it also shows 740 and 790 when it must be 1023 at 15
centimeters (maximal value). It means the sensors has a little voltage at minimum distance and
less than expected voltage at maximum distance, like in the Figure 4.7 until 4.10.
The duty cycle of PWM reading on the oscilloscope also shows little differences with the
theoretical calculation results. It shows the differences is below 10 percent except 3 values, it
could be caused by misreading of the oscilloscope or the device itself.
The oscillator the author`s used is an analog one, it is could cause misreading because there is
no numerical value on the display (not like the digital one). It also old and not calibrated yet
(said the lab assistant), because the lab would calibrate it in the next week or month. Then the
reading process of the oscilloscope could cause some differences value than the author`s
expected.
The power supply (9V battery rechargeable) is run out quickly. It is could give some effect to
the device since the current and voltage could not stable while it is running out, the effect is the
motor’s speed is decreased much and the sensors also has unstable output.
60
CHAPTER 5
CONCLUSION AND RECOMMENDATIONS
5.1 Conclusion
This project provides a robot that could escape a simple maze in the open space by read and
follows the right-side of the maze`s wall. The inputs are come from ADC value of Infrared
Proximity sensors which is set on the right-side and front-side of the robot. The sensors could
give a stable output (ADC) where the space has stable light, the light also must has 9 lux light
intensity. The result of this project is showing that the car toys could be modified into an
automatic robot, not just by remote control. This project could be improved a lot to make a SAR
robot, or map making robot by adding some sensors and function again.
5.2 Recommendations
This project is met its objective, which is escape the simple maze in the open space. However,
this project can be improved and expanded further by:
Replace the sensors to the ultrasonic/sonar sensors to make the ADC is more stable and
not effected by the light intensity.
Adding several sensors to get more function.
Replace the power supply or in this case battery that is not running out quickly.
Replace all of the wiring into full PCB or at least always minimize wire usage, to avoid
project malfunctioning caused by defected cable/wire.
That are some of the possible suggestions to make this project better.
61
REFERENCES
[1] Saul Ribai A.P., “Wall Following Robot,” Bachelor of Electrical Engineering. Project
report, Dept. Elect. Eng., Kolej Univ. Tek. Kebangsaan Malaysia. 2006.
[2] R.E. Kalman., On The General Theory of Control Systems, 1960, pp. 481-492.
[3] F. Schubert. Arduino UNO. [Online]. Available: www.googledocs.com [Oct 10, 2012].
[4] Wikipedia.com. “Control Theory” Available :
http://www.wikipedia.com/control-theory.htm, 2000 [December 2013]
[5] Robotwiki.com. “Arduino Motorshield L293” Available :
http://www.robotwiki.com/arduino-motor-shield-l293.htm, 2009 [December 2013]
[6] Adafruit.com. “Overview Character LCD” Available :
http://www.adafruit.com/overview-character-lcd.htm. 2009 [Desember 2013]
[7] Arduino.cc. “Arduino UNO Schematic” Available :
http://arduino.cc/en/arduino-uno-schematic.php, [January 2012]
[8] Atmel.com. “ATMega328 data sheet” Available :
http://atmel.com/datasheet/ATMega328.pdf, 2009 [January 2013]
[9] Vishay.com. “TSAL6100 data sheet” Available :
http://vishay.com/datasheet/TSAL6100.pdf, [October 2012]
[10] Hueyjann.com. “HPTB5-14D-B data sheet” Available :
http://hueyjann.com/datasheet/hptb5-14d-b.pdf, 2010 [February 2013]
[11] Sgsthomson.com. “L239B data sheet” Available :
http://sgsthomson.com/microelectronics/L293B.pdf, 1994 [January 2013]
[12] Topwaysz.com. “LMB162AFC Manual Rev0.1.” Available :
http://topwaysz.com/manual/LMB162AFC-manual-rev.pdf, 2002 [December 2012]
[13] Digiware.com. “TOPWAY 16x2 LCD data sheet.” Available :
https://docs.google.com/file/d/0BzkNNhuEnaF-
MjYxMTIxNzYtNmQ2Yi00MzM4LWJhNGUtNzNjOWRlY2FiZGI5/edit?pli=1&hl=
en#, [January 2013]
[14] Arduino.cc. “AnalogRead” Available :
http://arduino.cc/learn/function/analog-read.htm, 2010 [March 2013]
62
[15] Arduino.cc. “AnalogWrite” Available :
http://arduino.cc/learn/function/analog-write.htm, 2010 [March 2013]
[16] Arduino.cc. “DigitalWrite” Available :
http://arduino.cc/learn/function/digital-write.htm, 2010 [March 2013]
[17] Arduino.cc. “LiquidCrystalBegin” Available :
http://arduino.cc/learn/function/liquid-crystal-begin.htm, 2010 [March 2013]
[18] Arduino.cc. “LiquidCrystalSetCursor” Available :
http://arduino.cc/learn/liquid-crystal-set-cursor.htm, 2010 [March 2013]
[19] Arduino.cc. “PWM” Available :
http://arduino.cc/learn/function/PWM.htm, 2010 [March 2013]
[20] Arduino.cc. “SecretsOfArduinoPWM” Available :
http://arduino.cc/learn/function/secrets-of-arduino-pwm.htm, 2010 [March 2013]
[21] Arduino.cc. “String” Available :
http://arduino.cc/learn/function/String.htm, 2010 [March 2013]
[22] Wikipedia.com. “H-Bridge” Available :
http://wikipedia.com/h-bridge.htm, 2012 [March 2013]
63
APPENDIX A
SOURCE CODE
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(13, 8, 9, 10, 11, 12);
int motorright = 6; // the PWM pin
int motorleft = 5; // the PWM pin
int arahmotorleft = 4; //direction control pin
int arahmotorright = 7; //direction control pin
void setup() {
// initialize the Arduino Motorshield L293 pin as an output:
pinMode(motorleft, OUTPUT);
pinMode(motorright, OUTPUT);
pinMode(arahmotorleft, OUTPUT);
Appendix A: Source code
64
pinMode(arahmotorright, OUTPUT);
}
void loop(){
// read the state of the pushbutton value:
PrintLCD();
Fuzzy();
delay(100);
}
void PrintLCD(){
// lcd printing
String stringfront = String (analogRead(0));
String stringright = String (analogRead(1));
lcd.begin (16, 2); //inisialisasi LCD 16×2
lcd.print ("SENSOR F = " + stringfront);
65
lcd.setCursor (0, 1); //pindah kursor
lcd.print ("SENSOR R = " + stringright);
delay(100);
}
void Fuzzy(){
int sensorStatefront = analogRead(0); // variable for reading the pushbutton status
int sensorStateright = analogRead(1);
digitalWrite(arahmotorleft, HIGH);
digitalWrite(arahmotorright, HIGH);
if (sensorStatefront > 700){ //undetect, turn to the right-side
if (sensorStateright > 680){
analogWrite(motorright, 30);
analogWrite(motorleft, 90);
}
if (sensorStateright < 650){
analogWrite(motorright, 40);
66
analogWrite(motorleft, 80);
}
if (sensorStateright < 600){
analogWrite(motorright, 50);
analogWrite(motorleft, 70);
}
if (sensorStateright < 490){
analogWrite(motorright, 70);
analogWrite(motorleft, 70);
}
if (sensorStateright < 380){
analogWrite(motorright, 80);
analogWrite(motorleft, 60);
}
}
if (sensorStatefront < 750){
analogWrite(motorright, 80);
analogWrite(motorleft, 30);
67
}
if (sensorStatefront < 730){
analogWrite(motorright, 70);
analogWrite(motorleft, 15);
}
if (sensorStatefront < 680){
analogWrite(motorright, 75);
analogWrite(motorleft, 0);
}
}
68
APPENDIX B
DATA COLLECTION
Table B.1 Data collection after 9 times observation
Fuzzy
Delay (ms)
Result Success
Rate (%) Note
1st 2nd 3rd 4th 5th 6th 7th 8th 9th
100 √ √ √ √ √ √ √ √ √ 100 Stable & Success
200 √ √ √ √ √ √ √ √ √ 100 Stable & Success
300 √ √ √ √ √ √ × × × 66.66 Unstable & Success
400 √ √ √ × × × × × × 33.33 Unstable & Fail
500 × × × × × × × × × 0 Fail
600 × × × × × × × × × 0 Fail
700 × × × × × × × × × 0 Fail
Figure B.1 Motor left (5) PWM read (0-679, X)
Appendix B: Data collection
69
Figure B.2 Motor right (6) PWM read (0-679, X)
Figure B.3 Motor left (5) PWM read (680-729, X)
70
Figure B.4 Motor right (6) PWM read (680-729, X)
Figure B.5 Motor left (5) PWM read (730-749, X)
71
Figure B.6 Motor right (6) PWM read (730-749, X)
Figure B.7 Motor left (5) PWM read (>700, 0-379)
72
Figure B.8 Motor right (6) PWM read (>700, 0-379)
Figure B.9 Motor left (5) PWM read (>700, 380-489)
73
Figure B.10 Motor right (6) PWM read (>700, 380-489)
Figure B.11 Motor left (5) PWM read (>700, 490-599)
74
Figure B.12 Motor right (6) PWM read (>700, 490-599)
Figure B.13 Motor left (5) PWM read (>700, 600-649)
75
Figure B.14 Motor right (6) PWM read (>700, 600-649)
Figure B.15 Motor left (5) PWM read (>700, >650)
Figure B.16 Motor right (6) PWM read (>700, >650)
top related