2009 - Smart Helmet
2009 - Smart Helmet
by
JANUARY 2009
SMART HELMET
by
Approved:
Project Supervisor
JANUARY 2009
11
CERTIFICATION OF ORIGINALITY
This is to certiry that I am responsible for the work submitted in this project, that the
and that the original work contained herein have not been undertaken or done by
Ill
ABSTRACT
This report is written for the purpose of highlighting the background of the research
project for the SMART HELMET, the scope of the study, research method and the
literature review.
SMART HELMET is a system which aims to make all motorcyclists in Malaysia aware
and compulsory to wear helmet whether the travel distance is in I 00 meter radius or long
distance. The system will use ~ee technology which will connect from the
transmitter at helmet to the receiver at motorcycle. Many type of switches being used
such as temperature heat switch, clipped switch, and signal as a switch to make sure the
motorcyclist not cheating to their self. If the system identified that the riders or user not
wearing their helmet properly (clipped), the signal won't be send to the receiver at
motorcycle which will cause the motorcycle can not start and being ride by motorcyclist.
The scope of the study will be using others studies and statistics from Malaysia
government agencies in term of Road Safety; fatal motorcyclist accident causes and focus
on the helmet wearing attitude and behavior. The scope also will cover on research of
overview XJ3~e_ l Technology applications, behavior, characteristics as well as
advantages and disadvantages of X.Bee_ . Technology. Then will cover on
implementation of the system in real daily life.
IV
ACKNOWLEDGEMENTS
The author wishes to take the opportunity to express _his· utmost gratitude to the
individual that have taken the time and effort to assist the author in completing the
project. Without the cooperation of these individuals, no doubt the author would have
faced some minor complications through out the course.
First and foremost the author's utmost gratitude goes to almighty Allah SWT without his
blessing this project cannot be done fluent and successfully. To the author's parent, Mr
Mohd Yusofbin Abd Jalal and Mrs. Zahrah Mohd Radzi who is able to heard and listen
all the problems that occur and also supporting author in various type of support. Without
them, who will be the author. To the author's supervisor, Dr. Halabi Hasbullah. Without
his guidance and patience, the author would not be succeeded to complete the project. To
the Final Year Project Coordinator, Ms. Savitha Sugathan and other CIS Department
Final Year Project committees for providing his ,with all the initial information required
to begin the project.
To all CIS lecturers who have been willing to give appropriate help, support and
guidance in completing his- research.
Last but not least, to all individuals that has helped the author in any way, but whose
name is not mentioned here, the author thank you all.
v
4.2 Framework of Smart Helmet (Helmet) ................. 28
4.3 Framework of Smart helmet (Motorcycle) ........... 30
4.4 Outcome from Testing ........................................... 31
4.5 Continuous Connection Testing ............................ 34
4.6 Devices attached on helmet ................................... 37
4. 7 Devices attached on motorcycle ............................ 38
vii
LIST OF FIGURES
Figure 13.0: Print screen on detecting Xbee module using X-CTU software ................. 32
Figure 14.0: Print screen of writing the address for XBee modules using X-CTU ......... 33
Figure 16.0: output of the early stage of the continuously connection test.. ....................... 35
viii
LIST OF TABLES
Table 2.0: Road Fatality Statistics for 2007 and 2008 (Jan-Dec) .................................... 4
Table 4.0: Fatality Comparison of Motorcycle Rider and Pillion between States
IX
LIST OF ABBREVIATIONS
v Volt
RF Radio Frequency
Hz Hertz
DIY Do It Yourself
SK Start-Up Kit
m meter
X
CHAPTER I
INTRODUCTION
Smart Helmet Project is a project is a project on how to make the proper helmet wearing
can be compulsory implemented to all Malaysia citizen by developing a connection
between the motorcycle helmet and the motorcycle. This project consist of study of fatal
road accident and causes which involving motorcyclist, study on creating connection
between motorcycle and helmet by using RF module, and developing a prototype on
Smart Helmet itself. Helmet been created for the daily use when riding motorcycle in
order to protect human or user head from seriously injured when accident happen. A
quality helmets are made of a combination of fibers, glass and carbon on the outer shell
and special polystyrene foam with fire-retardant lining on the inside to help absorb
impact and prevent burns [I). Before a quality helmet being sold to the motorcyclist, this
helmet will be going for various types of inspections to make sure it is very safe and
comfort to be used by the end user.
This Smart Helmet project was initiated especially to focus on connecting the helmet
with the motorcycle by using a connection device or in specifically by using an RF
module. This project is design to uncompromising the proper helmet usage among the
motorcyclist. As we know, the improper helmet usage will cause a serious bad injury to
the head of motorcyclist when an accident happens to them. It show that the
motorcyclists as a focus group have the highest fatality and serious injury when the
proper helmet wearing not implemented because their head will directly expose to the
hazard when the helmet pull out from their head. With this Smart Helmet, the user will
not be able to start their motorcycle if they are not wearing helmet tidily. The system of
the smart helmet itself been computerized to make sure that the helmet must be neatly
clipped before the user can start the ignition of their motorcycle.
1
The Smart Helmet also works as a medium or tool to make the motorcycle safe from
being stolen by motorcycle thieves. This is because, by having the uniquely connection
between motorcycle and helmet, the helmet will be created specifically unique to the
owner of the motorcycle and specific motorcycle only can be use by user who have the
specifically connected helmet. By having this function, the motorcycle owner can happily
do their other job by reducing their mind on thinking of their motorcycle security.
This Smart Helmet is being connected to motorcycle by using RF module which is the
Xbee RF module. This type ofRF module is created to meet IEEE 802.15.4 standards
and support the unique needs of low-cost, low-power wireless sensor networks. The
modules require minimal power and provide reliable delivery of data between devices
[2]. The module can be connected uniquely by giving a unique 8 bits address and support
over 65000 unique addresses. This module operates within the ISM 2.4 GHz frequency
band and is pin-for-pin compatible with each other [2]. This RF module was controlled
by a PIC18 microcontroller which can configure the figuration of the XBee address,
controlling the data in and out from the RF module as well as controlling the entire circuit
being attached to the both helmet and motorcycle.
The main problem in Malaysia and especially in rural areas is motorcyclists are most
vulnerable to fatal road accident. One of the main reasons is because of failure to wear
helmet in a proper way. This is actually caused by the attitude of the motorcyclists
themselves who has the opinion that wearing helmet is unnecessary if the destination is
just a stone-throw away or wearing helmet is enough as long as they just wear it without
clipping the helmet's lock. When an accident happen, the improper helmet will push out
from rider's head and the risk to have bad or serious head injury also increase which may
cause to fatality.
2
1.2.1 Problem Identification
The problems identified are based on the common problems that happen among the
motorcyclist while riding motorcycle and wearing helmet. The problems that the
motorcyclist usually faces are:
It is an attitude issues involve about the usage of the motorcycle helmet. The main
attitude problem of motorcyclist nowadays is attitude that wearing helmet is not
necessary when riding motorcycle. In Malaysia, we can see most of the rural area
motorcyclist not wearing the helmet while riding their motorcycle at the open road. This
kind of attitude leads the increment on the fatal road accident in the rural site of Malaysia
caused by seriously injury of the motorcyclist head. In the statistic provided by the Polis
DiRaja Malaysia, PDRM below (table 1.0); 49.2% motorcyclist fatality is caused by the
badly injured of the motorcyclist head for the year 1997 in Malaysia [3]. this statistic
show that, it is slightly 50% of the rider or motorcyclist have the attitude that wearing a
helmet is not one of the important element in riding motorcycle.
Other attitude that occurs to the motorcyclist is about not wearing helmet in the
appropriate way or improperly. This kind of attitude can be described by wearing a
helmet without the strip or the strip not being fastened correctly. When this kind of
attitude happen among Malaysia citizen, when there is accident occur involving them, the
helmet which not properly tied will pull out from the rider head and will lead the high
exposure of the hazard directly to their head. The consequences of this situation, the
motorcyclist head can be hit and can cause the serious damage for his or her head as well
as lead to the motorcyclist fatality.
3
MotorcycGst fatalitie~ by Part of Body Injured
Part of Body Fatalities Percentage (Ofol
Heed 1766 49.2
Neck 95 2.6
Chest 256 7.1
Arms i7 0.5
Back 14 011
Hips 23 0.6
legs 50 14
Multiple 1371 38 2
Total 3S92 100
(Source: PDRJ.A, 1997)
CONSUMER CATEGORY
Passenger/Driver Car
2007
1228
.
19.3
2007
JAN-DEC
1228
2008
JAN-DEC
1335
DIFFEREI\ICE
11]7
"
8,7
(OTHERS CONSUMER)
Table 2.0: Road Fatality Statistics for 2007 and 2008 (Jan-Dec) [4]
For this problem, the problem being referred to the statistic which have been produced by
the Polis DiRaja Malaysia above (table 2.0) [4]. The table shows the road fatality statistic
in Malaysia for year 2007 and 2008 from month of January to the December in both year.
Based on the table, the motorcycle pillion and rider contribute 58.7% of fatal road
accident in 2007 and the value increase by 6.9% for the next year, 2008. it show that,
4
eventhough the government taking the serious action among the motorcyclist policies in
term of campaigns and summon distribution, still the number of motorcyclist fatality
increase year by year. What we can evaluate here is, it come back to the attitude problem
of the motorcyclist again.
For this time, it is about attitude problem among the motorcyclist which not aware to the
campaigns that have been produced by Malaysia government. Sometime, the motorcyclist
see this kind of programs and campaign not necessary for them and take it as the simple
thing and some of them even forgot what is the campaigns all about after attending it.
Other attitude that occurs here is about the attitude that the police summon can be pay
easily. It is not about the summons been produce not in the large quantity or the police
not take it seriously, but it is about the money value nowadays. The motorcyclist think
that if they being summon because not wearing helmet or wearing helmet improperly,
they still have ability to pay that summon even their summon already cumulated over a
year. This both kind of attitude should be solve immediately and one of the way by
producing some enforcement in wearing helmet or make the helmet compulsory to be
wear while riding motorcycle.
By using Xbee technology, it will be possible to connect the helmet to cooperate with the
motorcycle which makes them dependent to each other. This project also will be able to
configure the RF module by using a microcontroller which can control the addresses, data
send and receive and also the flow of the circuit which attached to both helmet and
motorcycle. It can be related to the safety because of the XBee RF module is used in
order make the connection between helmet and motorcycle to increase safety for
motorcyclist.
5
1.3.2 To ensure maximum adherence of motorcyclist towards roads safety
regulation in the aspect of helmet-wearing
Other objective if this project is about ensuring the maximum adherence of motorcyclist
toward road safety. By creating dependencies between both helmet and motorcycle,
motorcyclist will need helmet to ride the motorcycle in any circumstances. It will directly
decrease their risk of head injury when accident happens while riding on road while
ensuring that they adhere to the roads' safety regulations.
The last but not least objective of this project is about increasing motorcyclist focus while
riding motorcycle. The focus can be related with the motorcyclist way of thinking and
what appear in their mind while riding motorcycle. When this project already developed
and implemented, the motorcyclist mind will be clear from the unnecessary thing of
thinking such as thinking about proper helmet wearing related things, way of avoiding
policeman in any circumstances and also problem which will appear if the policeman
summon them caused by not wearing helmet. All these thinking matter can be solve when
the motorcyclist only and can only used motorcycle after wearing helmet properly.
This study will include research on the latest Xbee technology, function, security and also
threat. It also will include other futures on microcontroller in handling the circuit, flow of
data transmitted and received from RF modules and also in producing unique entity
which can differentiate this project with others same project. After researches have been
made, blueprint of the entire system will be developed and also the compatibility of the
system with the hardware and tools required. After the system generation level complete,
the study will continue with the application placement which will be suitable to use and
also some modification ofXBee RF module in to helmet and motorcycle. After
6
modification is made, it is time to compiling both software and hardware and also test the
entire system on the real-life to make sure its work properly and efficiently implemented.
7
CHAPTER2
LITERATURE REVIEW
To gain a better understanding and to study future on what is Xbee, additional readings
are essential in order to make a research in the Xbee technology area. From this reading,
it enables and gives more clarification of the Xbee RF module concept, structure and also
to gather more ideas on hoe to enhance this Xbee module in order to meet the user
requirement especially to the motorcyclist. Other than that, a research on the area of road
safety also has been done in order to get an overview of how to relate the theory of road
safety and regulation with this Smart Helmet. The research also will cover the study on
the Microcontroller technology which will be used through out this project and also get
some clear review on what is microcontroller, microcontroller function and how its
works. Throughout the research and overview among the journal and related medium of
research, there are some new knowledge, idea as well as technologies that have been
found which really help and can be used in the process of Smart Helmet development.
8
Broadcast ,/Single Peer---,,
(0•
'
•0 '':
'' '
-------
Being used
0 802.15.4 Devices
The advantages of using Xbee RF module as the main data receiver and transmitter are it
is the latest wireless technology in Malaysia nowadays, it can be differentiate with
another Xbee by producing own unique serial number, it is low cost, low power
consuming in wireless sensor network and most of it, it is ease to be used by the
developer.
In term of ease to be used, the Xbee module not needs any configuration for out-ofbox
radio frequency communication. It is because all the configuration can be set up by using
9
the X-XTU Software which applicable in testing and configure the XBee RF module.
(Figure 2.0)
~ - ~ h --«• ~-· • ~ > -- ~ • - - ·- -
It is also easy when it com for command mode, because it is a wireless communication
module, this Xbee RF module supporting both AT and API Command modes for the
module parameters configuration as shown below(Figure 3.0)[5].
10
"AT" ASCII Space Parameter Carriage
Prefix + Command + (Optional) + (Optional, HEX) + Return
''
Example: ATDL lf<CR>
When it come for the latest wireless technology advantage in Malaysia, choosing Xbee
RF module for this project will create great advantages in term of promoting this
technology and also differentiate this wireless technology with others matured technology
such as Bluetooth technology. When it is different, it may lead for competitive
advantages of this project or product when it entering the market.
In term of low cost and low power advantage, operation the Xbee module only using
3.3V of power [1] and it cost only RM200 for this kind of modules. When the power
consuming only 3.3V, it is possible to run it by using 9V battery which is small, relevant
and compatible to be attach inside helmet and also motorcycle. For more specification
detail, refer to table 3.0 below:
11
SPKification XBoo XBoo-I'RO
;sctt~;;re ;ee~~~:
"i;f C:·::a·f.~=
I
I.
.
:.::;er~:i·~~ f"&•J:1t::·
......
~l.;r"!D!!r JfC~:l'li!EIS
:scf:'.'.'Jr~ *E-::'...1J .;.:
...
Because this Smart Helmet project is a project involving helmet and motorcycle and also
targeting the motorcyclist as the targeted end user, it is automatically related to the road
safety towards the helmet wearing policies. The main idea of this project also related to
the road safety which the helmet need to be warn properly [4] before the user can run the
motorcycle on the road. The study on the road safety has been focused on the helmet
wearing policies in Malaysia for motorcyclist. The studies also includes the statistic that
12
have been produced by PDRM (Table 4.0)[4] and also the campaign research on
motorcycle safety in term of proper usage of the safety helmet advertisement as shown
below(Figure 4.0).
. ; . ~! : •• 1
.;,--,_., ', ::i:_c,'l(:;Ci"l :};:c; :;c ~·::: (_ .
STATE
PERLIS
2007
JAN-JULY
22
2008
JAN-JULY DIFFERENCE
15
.
63.2
K.LUMPUR 78 82 4 5.1
MELAKA 83 82 .J -1.2
TERENGGANU
SABAH
129
97
42
• -,7
93
60
.
-2
lS
-1.5
-4.1
+2.9
SARAWAK 76 84 8 20.5
TOTAL 2050 2239 1B9 9.2
So-urce
' PORM
Table 4.0: Fatality Comparison of Motorcycle Rider and Pillion between State 2007 and 2008 (Jan-
July) [4]
On the proper usage of the safety helmet advertisement on television and billboard
campaign, there is quite impressive result have been found which are over 78% of the
750 respondents were able to recall the advertisement slogan, 97% respondent agree with
13
the message and 90% respondent claims do follow the campaign proposition[6]. But,
when this project already developed, from 78% who recall the slogan can be change to
100% not only recall but applying the slogan and from 90% do follow the campaign
proposition changes to 100% do follow the rules due to compulsory procedure of wearing
helmet properly before riding motorcycle.
According to Tim Wilmshurst [7] PIC microcontroller is a family that consists of various
types of microcontrollers and the architecture is base on a modified Harvard RISC
(Reduced Instruction Set Computer) instruction set with dual-bus architecture, providing
fast and flexible design with an easy migration path from only 6 pins to 80 pins, and from
384 bytes to 128 kilobytes of program memory. PIC microcontroller also available with
many different specification depending on memory type, input-output (1/0) pin count,
memory size and other special features including CAN, USB, LCD, motor control, and
radio frequency. For this Smart Helmet project, the PIC 16F877A microcontroller will be
used which is a 40 pins PIC consist of program memory, data memory, 1/0 ports, and
timers for developing this project.
The advantages of PIC microcontroller for the developer are varies and one of the key
issue is compatible. According to Tim Wilmsmhurst [7], although there are many models
ofmicrocontrollers in the PIC family, they all share some common features, such as
program memory, data memory, 1/0 ports, and timers. Some devices have additional
features such as AID converters, USARTs and so on. Because of these common features,
we can look at these attributes and cover the operation of most devices in the PIC family.
For this Smart Helmet Project, the advantage of using PIC microcontroller is easy to
developing the project and it is ease to configure the microcontroller for the short time
14
basis project. Because PIC16F877A microcontroller also shares the common feature with
other microcontrollers, it is also one of the advantages in using this kind of
microcontroller for this Smart Helmet project.
In order to make further study ofXbee RF module, study on the example ofXbee
program is needed. For this time, one of the Cytron Technology [8] DIY projects has
been choose which the title of the project is "Multifunction Mobile Robot". Even though
it is a robotic project, but the usage of the Xbee RF module is available and it is one of
the main program in make the robot functional. For instance, this project is about a robot
which can be operating in 3 different ways such as line following robot with optional add
on gadget and capable ofline following, distance measure, and control wirelessly [8]. But
in evaluating and analyzing this robot, not all the function will be mea~ured. Because one
of the function is using Xbee RF module and it controlled by PIC16F877 A, so the author
choose to analyze only for this two functions and the major study of this product is base
on it microcontroller codification.
15
Figure 5.0: XBee RF Module attached to the robot circuit !8)
As shown at the figure 5.0 above, the robot can be control wirelessly by using Xbee RF
Module. To control this robot, the keyboard Num pad 8 is used move the robot forward,
Num pad 4 for move to the left, Num pad 6 for move to the right and Num pad 2 for
moving backward[8]. In order to make this Num pad can control the robot, some data
will transmit from the Xbee module on the computer to be received by another Xbee on
the Robot and controlled by a PIC microcontroller on the robot. For make it functionally,
some codification on the microcontroller have taken place which all the information will
be shown on the Appendix A.
Basically, the microcontroller need to control all the data which been transmitted from
the computer Xbee module, interpret it and give some instruction to the robot by turn on
and offthe motor inside the robot. For example, if the Num pad 8 been push, the
microcontroller will execute this following code:
lcd_goto(20);
16
if (RCREG '8')
II if character '8' is detected, the robot move forward
{
forward();
send_string("FORWARD ");
Then, the microcontroller will find the forward () function and execute this following
code:
void forward ( )
motor ra = 0;
-
motor- rb 1;
motor 1a = 0;
-
motor 1b = 1;
After execute this code, the microcontroller will send a string "FORWARD" to the LCD
of the robot to display it until the Num pad 8 being relea.<>e. For Smart Helmet, the study
of these codification can help as a reference in codify the microcontroller code. But
before microcontroller can execute all the data transmitted and received. The
microcontroller needs to be configuring its input and output pins and also UART setup
for XBee RF module in the beginning ofthe codification.
17
CHAPTER3
METHODOLOGY
Project Research
.-------------------··---E:J
'
:
~·------··-· -----------+~---~---'------
~---
w __
'
I ~
Project
Project Implementation
I
Requirement
I' Analysis -------
Project
Developing
II
• Project Testing ------
·-----
J
Figure 6.0: The Throwaway Prototyping Model
18
In general, the development phase of smart helmet project followed by seven sub phases
shown in the model. The flow will be start at the research phases, followed by project
planning phase, then through the project planning phases and next been followed by
project developing and project testing phase. When finish this five phases, a prototype of
the project been produced and project implementation been take part.
Specifically, the project life cycle of the Smart Helmet followed the Throwaway
Prototyping Model which is explained below:
In gather information on connection technology, the very large library in the world which
is internet been used. All the articles and also manuals in applying this technology in
Smart Helmet project been studied in this phase (as shown as in the literature review).
Some discussion also being made here with the appropriate personal through the web and
online discussion and also some interview with the data communication and networking
lecturers also happen at this stage. In this stage also, initial research with the RF modules
and devices been done for the planning stage.
The planning stage objective is to make sure the technology compatible with the system
to be developed, or in the other word, to identifY the devices to be used and the need in
designing the blueprint of the entire Smart Helmet development. In order to do that,
further discussion been done with the project supervisor time by time. Other than
discussion, opinions and idea also has been gathered from they personal who have
knowledge in repairing and also modifYing motorcycles especially the fabricators for the
Smart Helmet blueprint on the motorcycle.
19
3.1.3 Application programming- research on the suitable language and
developing blueprint of Smart Helmet (Analyzing)
For this analyzing stage, after designing the blueprint of the project, the appropriate
research and choose of the language will be analyzed. To do so, further discussion with
supervisor and research been done on the language available in programming the RF
module have been selected. Because the Smart Helmet is using a microcontroller to run
the module, the languages that available and been analyzed are C language and Assembly
language. Some example of the developed RF module codes also been analyzed and
tested here at this stage. All the example codes have been referred and been get from the
others RF project which available to download from the internet.
On prototype development, the research must be practically done. Which mean, some of
the practical work have been done. Some modification on the RF module and also
motorcycles will occur in this developing stage. By referring to the project blueprint, the
modification and attachment of the RF module have been done smoothly. This stage also
has been done by some help from the experts in both field RF module and motorcycle
modification. Codification on the microcontroller also been done in this stage which been
refer with the other related example project have been gather before.
In testing the prototype, it is done by testing the circuit and codes with the appropriate
simulation software before attach the device to the helmet and motorcycle. At this stage,
MPLAB software and PIC Simulation software been used supervised by supervisor and
with help from some experts. As brief explanation, the bad result and outcome have been
throwing away here until the final prototype been produced and all the result and
outcome of the testing will be deeply discuss later on the result and discussion in chapter
four.
20
3.1.6 Producing End Product (Prototvping)
At this stage, the tested prototyping system which been produced before will be attached
to the both helmet and motorcycle. In this stage also, the suitable hardware modification
have been done to the both and being tested again and again until the final product being
produced. The test include the appropriate places that possible for the circuit being placed
in helmet based on the project blueprint which been developed in the plarming stage
before and also same goes to the motorcycle. Outcome of this stage is the final product
that will be used for the next stage (implementation).
For this implementation stage, the final product which is attached RF module Helmet and
motorcycle tested in real-life helmet wearing. The test sets will be produced which are
testing the product without wearing helmet, testing the product with wearing but not
clipped helmet and also testing product with proper wearing helmet. These tests been
made to make sure that this ended product can be implemented in daily used and also
applicable to be consume and implemented by the motorcyclist at the first place.
21
3.2 GANTT CHART OF THE SMART HELMET DEVELOPMENT
- ----~-
I 3
bluetooth technology (Planning)
•
the suitable language (Analyzing)
,114 11111 11118,1125 211 1 218 1211512122 3/1 1 318 1311513122131291 415 1411214119141261 513 15110 1511715124 S/31 I 6/7 16'141 &21 I
1 Prototype Development (Developing) 11112009 311312009 10w2d
' 2 Prototyping testing (implementation) 311012009 61112009 12w
Base of this project, these two equipments are the basic equipment that must be prepare.
The helmet will be connecting to the motorcycle by using connection device (XBee).
By using Xbee technology, this device is use to connect both motorcycle and helmet as
already mention in chapter 2. Some specification detail provided by supplier as shown in
table 5.0 below:
Description: Finally, user may enjoy another simple yet reliable wireless
communication for wireless control and monttoring. XBee OEM RF module has been
used in many robotics applications world wide to offer wireless communication, point
to point and also mesh network. Save the time searching for surrounding device and
, request for connection, it can send data wireless after powering up without any extra
1 configuration. Besides, XBee module can be used as standalone wireless transceiver
i for control and monitoring.
23
3.3.3 Wires
Wires used in order to make the circuit and modification on the device that being used in
this project.
To be function as second switch at helmet and this will detect human body heat
(approximately± 33'C). Then, as switch, it will make the current of the circuit flow to on
the XBee ! device at helmet.
It is device to program the PIC Microcontroller in order to make the Xbee device being
used and functioning well. The SK40 device also can be used as a part of the circuit
board as well without separated the microcontroller from its main circuit. Some
specification detail provided by supplier as shown in table 6.0 below:
Description: SK40B is designed to offer an easy-to-start platform for PIC MCU user. This board comes
with basic components for the user to begin the project development. User is able to utilize the function of
PIC by directly plugging in the components to the SK40B in whatever way that is convenient. With the on·
board UICOOA connector, user can load the program faster and easier using the UICOOA programmer. The
PIC MCU is not included in this kit to provide the freedom for the user to choose PIC MCU.
24
3.3.6 PRll-Temperature detector
This board is a built in board which consist of thermostat, 40pins microcontroller, output
devices and some resistors. This board is programmable and also eases to be
programmed. Some modification is needed. Some specification detail provided by
supplier as shown in table 7.0 below:
; Description: This project utilizes the PIC16F876A to read the temperature feedback from the LM35,
display it on the 16x2 Character LCD and control2 brushless fans. It illustrates the process to configure the
ADC on PIC to measure the analog voltage from the temperature sensor. It can be further modified into a
: temperature monitoring system.
25
CHAPTER4
As the overview of this chapter, this particular chapter will discuss more deeply on the
developing stage of the Smart Helmet. It will include the main flow of the Smart Helmet
System, the blueprint design or frame work for the Smart Helmet, the out come of the
testing, the suggested place to attach the circuit module on both helmet and motorcycle,
and other matter or advancement on the Smart Helmet Project.
In the short and simple word or description, this chapter will touch on the Smart Helmet
project from the planning phase of the methodology model till the implementation phase
of that model for this project.
In this sub topic, the main flow of the Smart Helmet will be shown (Figure 8.0) which
already developed in the Planning Stage of the project cycle Methodology in the chapter
3. Basically, the main idea or flow of the Smart Helmet will be start with the user or
motorcyclist put their head inside the helmet. When it happens, the microcontroller on the
helmet will execute the thermometer circuit on the helmet to get the human temperature
data. When the data interpreted as human temperature, the microcontroller will get some
input from the helmet clip circuit whether the user clipped their helmet or not. If it is yes,
then the microcontroller will tum off the thermometer circuit and tum on the Xbee RF
module which happen after confirming that user already wear their helmet properly.
When the Xbee RF module turned on, the data will be transmitted to the other Xbee
module which attached to the motorcycle and microcontroller there will execute the
connection between these two Xbee modules and allow the user to start up their
motorcycle. For information, the Xbee module at motorcycle will turned on when the
user switch on their motorcycle key switch. All the flow can be simplifY as being shown
in the figure 8.0 below:
26
~ !
-----~!'
'r' -
--
no
Human Tamperature
yes i
no
User clip hetmet
yes'
!
o/
27
4.2 FRAME WORK OF SMART HELMET (HELMET CIRCUIT)
Base on the main flow of the Smart Helmet project, the frame work of the circuit can be
simplified and shown as below (Figure 9.0):
~
- +
28
t'
Thermometer Circuit
Helmet clip
' - - - - - - - - - - - 4 r,_~2'AN7:VP.H·
;; r.;A,J·MJH'R!:F.
~ RMHOC-KI
7 RA!;'AH•I·SSn
15 1-t()Hlr)S.O,'fiCKI
l<l RG1,•!IO.S.IiCCP2
Because the microcontroller that has been used is PIC16F877A, the figure 10.0 above
shows how the thermometer circuit, helmet clip circuit and Xbee module circuit being
connected to the microcontroller. For instance, PORTRBl and PORTRB2 will be execute
as the input and output pin for the thermometer circuit with the microcontroller which
will allow microcontroller to send and receive the data from the temperature sensor
(analog sensor) and run next function. When the helmet clip circuit turn on, thermometer
circuit will be turned off and turn on the Xbee module by the microcontroller which
connected to PORTRC6 and PORTRC7 as transmitter and receiver pin for
microcontroller. Here, microcontrollers will also being executed as Analog to Digital
Converter for both thermometer and Xbee module circuit.
29
4.3 FRAME WORK OF SMART HELMET (MOTORCYCLE CIRCUIT)
1\1/ Ignition
Receiver
Battery
~
u Microcontr )ller PIC18 ~
+
Analog to digital converter
(Xbee device)
LED
(\
~
B ~
Switch
30
4.4 OUTCOME FROM THE TESTING
Testing phase is the phase when the devices being test to find some problem and also to
solving that particular problem. As have been mention in project cycle methodology, this
Smart Helmet project will go through several test before come out with the prototype and
also being implement in real-life environment For the first test, is about testing the Xbee
module by using 2 computers. The objective of this test is to make sure the module can
be connected and the unique address for both modules can be generated.
In this test, the software and tools required are 2 unit computers which can be in
Microsoft Window XP or Vista operating system, 2 unit of SKXBee RF module [9], and
also the X-CTU software which already installed in both computers. First of all, both
SKXBee RF modules must be connected to both computer (I unit SKXBee module for
each computer) as been shown in figurel2.0. Then, run the X-CTU software and detect
the module attach for each computer.
(' OlnJlUtt'l" B
31
After detecting both modules for each computer by using X-CTU software, the output
will be shown as in the figure 13.0. Then, it is time to configure the address for both
Xbee and tried to make connect between these two modules. For set up the ordinary
address, the AT commands can be used in the terminal tab on the X-CTU software. For
this test, SKXBee I will be addressed as Ill! and SKXBee2 as 2222. But, before
implement the command, the baud rate for both modules must be set same as each other
in detecting module stage. All of these processes will be graphically explain in figurel4.0
below:
I
Host Setup j Use1 Com Po1ts Ethe1net Com Pmts l
0 - ~ ~
, API
Com test I Query Modem
1 EnableAPI
Communication with modem.. OK
Modem type= XB24
Modem fi1mwa1e ve1sion = 1OA5
ASCII Hex
Command Cha1acte1 (CC] j+ j2B
Figure 13.0: Print screen on detecting Xbee module using X-CTU software
32
:·xcJU[COM11J . . EJ"oc··xCJUfCOM13J. []··1'5(1
I
PC Settings Range T~MI Te1minal j Modem Configl.l'al:ion J
Line Status- Assert
- - - :'tYfRP Rrs·r-; ·B"rei~kf-
--, Close I Asfiemblell
ComPortJ Pac~ Screen He11
Clear I
Shot."'l
- --------- ---~-1
j
+++OK +++OK
atmyllll atmy2222
,QK OK
atwr atwr
OK OK
atdl2222 atdlllll
OK OK
atwr atwr
OK OK
a ten a ten
'oK OK
+++OK +++OK
·atmy 'atmy
1111 2222
atdl atdl
2222 1111
a ten a ten
OK OK
I
Figure 14.0: Print screen of writing the address for Xbee modules nsing X_CTU software
Note that, the red OK word been generated automatically to make sure the command is
ok and no error occur when execute the command. After this stage, both of the modules,
already connected automatically after the address configured. As can be see in figure 14.0
above, the current address (atmy) for SKXBee 1 is 1111 and its destination low (atdl)
address is 2222 and it is vice versa with the SKXBee 2.
Next, the output from this testing phase will be shown on the figurel5.0 below:
33
SKXBee 1 SKXBee2
Another testing that occurs here is testing the continuous connection among these 2 Xbee
RF modules. The objective for this testing is to make sure that this connection can last
longer for several hours. When the connection established for several hour, it means that
when the module implemented in to the helmet and motorcycle, the end user can travel
used this smart helmet for a long journey which take several hours to reach the
destination. The devices requirement for this testing is same as the testing that have been
tested before and the connection setting also same as the previous test. The only thing
that different here for this test is the output of the test which will show as the figure 16.0
to 18.0 below:
34
i,;o;~ _Q ~~ X·C11JICOM5! c -:.:1 ~
FC $e!tifl')-~ R4"*' Tc--:.1_ j Tt'!mtd i M!Xk-m C~-n!IQ',~di-:>1 i
Pe~~:trl.
--------, P~<:.\!t~
R
100.0 Stop
I A
1000
• •
" '
•' Ad'Y~ot~d }/)
''
'
~-·---------
Te~t • G®d
"""' ,,,
'"'
0 •l r·
-~~~M,.,'ll;" tl!il\tl'r
1\l!,l'ltilf il>IDt!lr
;;l>~l\,1;.~!,' hMt!H'
!~:~:~
lh-anta~
h1111t8t
'!~rM'lti!t l li<Utt-at
·~~:~=~
lhfoll.tOU
hlllltiii'
......
h,6;1'1.t.lll"
'hQ>'It01;' h-tlil>:
;l;.mo;~r
y·~t.;:l.~ hontu
!l __~~~in~-.::;~i;~-
'etlt:l4--96ooa~n -Fl[jl.ilf-~ON( ____ --------------------~ COMS 9$001Hl·l FLO\<f:NOWE
,IL---~----------------------~
Figure 16.0: output of the early stage ofthe continuously connection test (I 1:39pm)
Pm(.oot S~op
--, p,.,!!;-!11\l
1000
1000 I p,
..
'
--------
c~.Ji' s~~!: ''
1\d\'.m:;t:d ;.;.)
-------
Te~l
(
...
'
1
.... '"'
-
(,(Woj
...
-
... .,'
35
r~h·ClU (COM4) !lh-tTU !COM> I
i
f'ICSE!t!'\9~ R~TI!'*t i tmrN Moo:MmCMI\gufahor.! PC S.eft~ li.mg; T1n! i T~Wir~ ~ ;.,ko:;kM CQT'!i~"Aal~l !
PeJceol
Step 100.0
R
"'
''
..-i ... -. . . . T~t-
( i ~""' '
,.-_s~ ~ ~
l
·:bi»l.t;loJ:
ib..nt,u
r~:~---·~-~-
'ih=t"'~
1
b<int-o.r hiM\t~~·
jhiir>t•H jh!lrlt.!lr
hM<t<lrf lhQ!It.llr
~hat'!tliOf 1h&\t.!lr
't•oo<:<""f h6l>tar
-:"~·~ l l'!&l\til.~
1:::~::
!f:>~.;>r
)•=e"'"
lb41'1t,.r lll.a11t11r
'ih .....t.a.t ih11nt•~
;h .... t .. t llbantilllr
jnaa-.l;•r hitnt: ..r
¥ '
i ····~-
]~iR~
COM5 90001HI·1 Fl-C\\V-NQNF
From these 3 figures above, the cormection already established over than I hour 30
minutes and the signal strength base on package transmitted and received still good after
over than 61000 packages received and transmitted between this 2 Xbee modules. So, the
result supports the objective of this continuous cormection test before the test take place.
36
4.6 DEVICES ATTACHED ON HELMET
Helmet
ttery
ennostat
,vitch 2)
lee
nsmitter
Helmet Clip
Wire (switch I)
Base on figure 19.0 above, the entire circuit will be turn on when helmet
clip tight and clipped properly and also the thermostat detecting human heat from
the rider head which basically between 33'C to 37'C. When both switches turn
37
on, the Xbee device or transmitter which powered by battery will turn on too and
transmit signal from helmet to motorcycle receiver as the main switch for the
motorcycle's circuit and ignition.
38
4.7.1Description and procedure
In other side, when the helmet clip closes properly, the transmitter will
transmit Xbee signal from the helmet to the motorcycle receiver. When there is a
signal, automatically the LED circuit will tum off (done by three-state) and tum
on the ignition circuit which allow sparkplug to produce fire spark in order to start
motorcycle.
39
CHAPTERS
CONCLUSION
5.1 RECOMMENDATION
There are many other side problems if this project implemented in future such as related
with the rigidity of the project. Rigidity will occur when rider want to go to shop which
situated 50m from their house and riding their motorcycle within their housing area
which police will not summon them. For this future problem, the best solution is to have
some equipment that can limit their distance traveled without wearing helmet. The basic
idea is, the system can include some device which can limit their motorcycle traveling
more than 1OOm radius. The device can be attaching at motorcycle tire and be
manipulating by an application base on motion of motorcycle wheel. The formula will be
like this:
40
For detecting 1OOm distance or limitation to the motorcycle,
Base on the theory, the limitation will base on the rotation of wheel. Example, if
the circumference is 1.5m, its mean lOOm divide by l.5m equal to 66.67 times or
slightly to 67 times wheel rotated. When it reach to that number, the motorcycle
engine will be program to stop function and stop the motorcycle until the rider
wearing helmet properly again. So base on this calculation, Smart Helmet can
limit the distance of traveling without helmet.
41
CHAPTER6
REFERENCES
[3] S Kulamthayan, Radin Umar, Ahmad Hariza,Mohd Nasir,S Harwan: (March 2000)
"Compliance of Proper Safety Helmet Usage in Motorcyclist"
http :1/ww·w .miros. gov .mvI pub li cations/ Comp lianceOfPro perSafetv He !metU sagelnMotor
cyclists. pdf
[6] R.S Radin Umar: (2006) "Motorcycle safety programmes in Malaysia: how effective
are they?" International Journal oflnjury Control and Safety Promotion, Vol. 13, No. 2.
[7] Tim Wilmsmhurst: (2007) "The PIC Microcontroller Family", Newnes Know It All
Series, Chapter 1.
www.newnespress.com
42
[9] Cytron Technology : (2008) "XBee Starter Kit- SKXBee" , Xbee RF Module
manual. www.cyctron.com.my
43
APPENDIX A- Example codification of Multifunctional Mobile Robot
II========================================·======-
/I Author :CYTRON
II Project :PR23
II Project description :Simple line follow
II Version :vl.4
II
II include
//·====~=========,==========
#include <pic.h>
II configuration
//==================================='
__CONFIG ( Ox3F32 );
II define
//·=============================================-
#define swl REO
#define sw2 REl
#define motor_ra RCO
#define motor rb RC3
#define motor la RC4
#define motor lb RCS
#define rs RB7
#define e RB6
#define led data PORTO
#define b light RBS
#define SPEEDL CCPRlL
#define SPEEDR CCPR2L
II global variable
11---- --
unsigned char data[S] = {0};
44
unsigned char i=O,raw;
II function prototype
II ---===============================================
void init(void);
void delay(unsigned long data);
void send_config(unsigned char data);
void send_char(unsigned char data);
void e~ulse(void);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void send_string(const char *s);
void dis_num(unsigned long data);
void line_follow(void);
void ultrasonic(void);
void analog_sen(void);
void read_adc(char config);
void forward(void);
void stop (void);
void backward (void);
void reverse (void) ;
void left(void);
void right(void);
II interrupt prototype
II =============--======================
static void interrupt isr(void)
(
if (TMROIF)
(
TMROIF = 0;
To +=OxlOO;
}
if(RBIF)
(
RBIF = 0;
if (RB4)
(
TMRO = 0;
To = 0;
}
if(RCIF)
(
45
RCIF = 0;
if (RCREG ='R') data[i=O]= RCREG;
else if (RCREG =
100) data[i=O]= RCREG;
if ( (data[O] = 'R') )data [i++] = RCREG;
if (i>4) i = 4;
}
}
II main function
II '============================================
void main(void)
{
lcd_clr();
send_string("Select mode");
buzzer = 0;
while(l)
{
if( ! swl)
{
while (! swl) ;
m++;
if ( m > 3) m = 0;
}
i f (!sw2)
{
while (! sw2) ;
switch(m)
{
case 0
line_follow();
break;
case 1
ultrasonic() ;
break;
case 2
analog_sen() ;
break;
case 3 :
wireless_xbee();
II mode 4 wireless xbee mode
break;
default
}
)
switch(m)
{
46
case 0 : lcd_goto(20);
send_string("2.Ultrasonic ");
break;
case 2 : lcd_goto(20);
}
}
}
II Initailization
II Description : Initialize the microcontroller
//=---= ==~====
void init()
{
II ADC configuration
ADCON1 = Ob10000100;
RBIE = 1;
PR2 = 255;
T2CON = Ob00000100;
CCP1CON = Ob00001100;
PWM ( for more detail refer datasheet section 'capture/compare/pwm')
CCP2CON = Ob00001100;
PWM
TRISA = ObOOOOOOll;
TRISB = Ob00011111;
TRISC = Ob10000000;
TRISD = ObOOOOOOOO;
TRISE = ObOOOOOOll;
TOCS = 0;
PSA = 0;
PS2 = 1;
PS1 = 1;
PSO = 1;
TMROIE = 1;
TMRO = 0;
II setup UART
SPBRG = Ox81 ; //set baud rate to 9600 for 20Mhz
BRGH = 1; //baud rate high speed option
TXEN = 1; //enable transmission
47
TX9 = 0;
CREN = 1; //enable reception
SPEN = 1; //enable serial port
RX9 = 0;
RCIE =1; I /enable interrupt on eachdata
received
II enable all unmasked interrupt
GIE = 1;
PEIE = 1;
II LCD configuration
send_config(Ob00000001); //clear display at led
send_config(Ob00000010); //Led Return to home
send_config(Ob00000110); //entry mode-cursor increase
1
send_config(Ob00001100); //diplay on, cursor off and
cursor blink off
send_config(Ob00111000); //function
TX_PIN = 1;
b_light = 0;
buzzer = 0;
stop();
I I Mode subroutine
//====================·-=======-=============~====
lcd_clr();
send_string("Position");
while (1)
{
if ((s left--1)&&(s mleft==O)&&(s mright==O)&&(s right==O))
- I I if only sensor left detected black line
{ forward () ;
SPEEDL = 0;
SPEEDR = 255;
memory = PORTB&Ob00001111;
lcd_goto(20);
48
else if
((s_left==l)&&(s_mleft==l)&&(s_mright==O)&&(s_right==O))
{ forward () ;
SPEEDL = 180;
SPEEDR = 255;
memory = PORTB&ObOOOOllll;
lcd_goto(20);
send_string ("m_right2");
else if
((s_left==O)&&(s_mleft--l)&&(s_mright==O)&&(s_right==O))
{ forward() ;
SPEEDL = 200;
SPEEDR = 255;
memory = PORTB&ObOOOOllll;
lcd_goto(20);
send_string ("m_rightl ");
}
else if
((s_left==l)&&(s_mleft==l)&&(s_mright==l)&&(s_right==O))
{ forward() ;
SPEEDL = 200;
SPEEDR = 255;
memory = PORTB&ObOOOOllll;
lcd_goto(20);
send_string ("m_rightl ");
}
else if
((s_left==O)&&(s_mleft==l)&&(s_mright==l)&&(s_right==O))
{ forward() ;
SPEEDL = 255;
SPEEDR = 255;
memory = PORTB&ObOOOOllll;
lcd_goto(20);
send_string ("middle ");
}
else if
((s_left==O)&&(s_mleft==O)&&(s_mright==l)&&(s_right==O))
{ forward() ;
SPEEDL = 255;
SPEEDR = 200;
memory = PORTB&ObOOOOllll;
49
lcd_goto(20);
send_string ("m_leftl ");
}
else if
((s_left==O)&&(s_mleft==l)&&(s_mright==l)&&(s_right==l))
{ forward();
SPEEDL = 255;
SPEEDR = 200;
memory = PORTB&ObOOOOllll;
lcd_goto(20);
send_string ("m_leftl ");
}
else if
((s_left==O)&&(s_mleft==O)&&(s_mright==l)&&(s_right==l))
{ forward() ;
SPEEDL = 255;
SPEEDR = 180;
memory= PORTB&ObOOOOllll;
lcd_goto(20);
send_string ("m_left2 ");
}
else if
((s_left==O)&&(s_mleft==O)&&(s_mright==O)&&(s right--1))
{ forward() ;
SPEEDL = 255;
SPEEDR = 0;
memory= PORTB&ObOOOOllll;
lcd_goto(20);
send_string ("left ");
}
else if
((s_left--O)&&(s_mleft==O)&&(s_mright==O)&&(s_right==O))
{ forward () ;
SPEEDR = 255;
)
else if ((memory== Ob00001000)1 1 (memory==
ObOOOOlOO) I I (memory== ObOOOOllOO) I I (memory== Ob0001110))
{
SPEEDL = 255;
50
SPEEDR = 0;
else if
((s_left==l)&&(s_mleft==l)&&(s_mright l)&&(s right==l))
{
forward();
}
}
}
II Mode 2 : Ultrasonic
//Description: Maintain distance measure using ultrasonic between
obsacle and robot
I I Can choose data acquiring methode between ADC, PWM and UART
II===============================================================
void ultrasonic(void)
{
int distance;
II variable for distance
measuring
char n=l;
II index for indicat mode
lcd_clr ();
II clear led
send_string("Measure mode");
II display string
lcd_goto(20);
II led goto 2nd line
send_string("ADC");
II Display string "ADC"
while (l)
II loop forever unless sw2 is
pressed
{
if ( ! swl)
II if button sl is pressed
while (! swl);
II wait until swl is release
n++;
II increment n
lcd_goto(20);
II goto 2nd line
switch (n)
II check current value of n
{
case 2 send_string("PWM ");
break;
II break out from switch
case 3 send_string ( "UART") ;
51
break;
II break out from switch
default: send string("ADC ");
II if not 2 or 3, set ti back to 1
and display "ADC"
n =1;
}
if (!sw2)
II if button sw2 is pressed
{
while (! sw2) ;
II wait until sw2 is release
break;
II break out form looping
}
}
lcd_clr();
II clear the led
send_string("Distance");
II display string "Distance"
while (1)
I I loop forever
{
1cd_goto(20);
II led goto 2nd line
distance= us_value(n);
II disance variable are equal
to value return from subroutine us .value
dis_num(distance);
II display the value of
distance
if (distance> 40)
II check if distance more
than 40
{
forward();
II then forward with full
speed
SPEEDL = 255;
SPEEDR = 255;
buzzer = 0;
}
else if (distance> 30)
II check if distance more
than 40
{
forward();
II forward with medium speed
SPEEDL = 230;
52
SPEEDR = 230;
buzzer = 0;
}
else if{ distance >20)
II check if distance more
than 40
(
stop{) ;
II then stop
buzzer = 0;
}
else
I I else, distance less than
20
{
backward{) ;
II then backward with medium
speed and on the buzzer
SPEEDL = 230;
SPEEDR = 230;
buzzer= 1;
while {1)
(
lcd_goto{20);
II led goto 2nd line
read_adc{CHANNEL1);
II read adc channel 1
analog distance sensor input)
distance = result;
II assign distance as the
result oft he reading
dis_num{result);
II display the value
if {distance< 200)
II check if distance less
than 200
(
53
backward() ;
II backward with full speed
SPEEDL = 255;
SPEEDR = 255;
buzzer = 0;
}
else if (distance< 250)
// check if distance less than 250
{
backward() ;
//backward with medium speed
SPEEDL = 230;
SPEEDR = 230;
buzzer= 0;
}
else if( distance < 300)
/1 check if distance less than 300
{
stop() ;
II stop
buzzer= 0;
}
else
II else, distance more than 300
{
forward();
//forward with medium speed and on
buzzer
SPEEDL = 230;
SPEEDR = 230;
buzzer= 1;
}
}
}
//Mode 4 : Xbee
//Description : Control the robot using UART ( XBEE or an UART
wireless module.
//=====================================================
void wireless xbee (void)
{
lcd_clr();
II clear the led
while(l)
II looping forever
{
lcd_goto (0);
if (data[O] == 100)
I I check if UART start byte is met
{
send_string(" XBEE CONTROL ");
II display string
SPEEDL = 200;
II set the motor speed
54
SPEEDR = 200;
while(l)
{
lcd_goto(20);
if (RCREG = '8')
II if character '8' is detected,
the robot move forward
{
forward();
send_string ("FORWARD ") ;
}
else
II else then stop the robot
{
stop();
send_string("INVALID COMMAND ");
}
}
}
else send_string("COMMAND");
}
}
II Ultrasonic value
55
II Description : Retrive data from Ultrsonic. Can choose methode
between ADC, PWM and UART
II Parameter : mode 1) using analog
II 2) using pwm
II 3) using uart
II==================================
unsigned int us value (unsigned char mode)
II subroutine for ultrasonic
measurement
{
unsigned int value;
switch (mode)
II retrive value of
measured distane based on the methode selected
{
case 1: read_adc(CHANNELO);
value = result;
II max vslue 2.55v =
2.5515 *1024 - 1 = 522, resolution= lOmVI inch, 10ml5*1024 =~ 2
break;
case 2: value = TH;
II each value=
256*4120mhz = 51.2us, i inch= 147us
break;
II can change using
smaller timer prescale, but resulation fixed 147us I inch
case 3: if ( data [O]=='R') value= (data[l] -
Ox30)*100+ (data[2] - Ox30)*10+ (data[3] - Ox30); II 1 = 1 inch
else
{
lcd_goto(20);
II if stater byte is
not 'R', Display 'not connected'
send_string("not connected");
while(l);
II loop forever
}
default:
}
return value;
}
II read adc
II Description: subroutine for converting analog value to digital with
average 200 samples
II Parameter : config ( select the channel )
II=======================================================
void read_adc(char config)
{
unsigned short i;
unsigned long result_temp=O ;
ADCONO = config;
delay(lOOOO); II delay after changing
configuration
56
for(i=200;i>O;i-=1) //looping 200 times for
getting average value
{
ADGO = 1; I /ADGO is the bit 2 of
the ADCONO register
while(AD=1l; I /ADC start, ADGO=O
after finish ADC progress
result=ADRESH;
result=result<<B; //shift to left for 8 bit
result=resultiADRESL; //10 bit result from ADC
result_temp+=result;
}
result = result_temp/200; //getting average value
ADON = 0; //adc module is shut off
}
void backward ()
{
motor ra = 1;
motor rb = 0;
motor la = 1;
motor lb = 0;
}
void left()
{
motor la = 1;
motor lb = 0;
motor ra = 0;
motor rb 1;
}
void right()
{
motor la = 0;
motor lb = 1;
motor ra = 1;
motor rb = 0;
}
void stop()
{
motor la 1;
motor lb = 1;
57
motor ra = 1;
motor rb = 1;
I
II LCD functions
//-,==============================================
void delay(unsigned long data) //delay function, the delay
time
{
for( ;data>O;data-=1); //depend on the given value
}
delay(400);
e_yulse();
//pulse e to confirm the data
}
void e_yulse(void)
//pulse e to confirm the data
{
e=l;
delay(300);
e=O;
delay(300);
I
void led_go to (unsigned char data) //set the location of the led
cursor
{
if (data<16) //if the given value is (0-
15) the
{
//cursor will be at the upper line
send_config(OxBO+data);
I
else //if the given value is (20-
35) the
{
//cursor will be at the lower line
data=data-20;
//location of the led cursor(2X16):
58
send_config(OxcO+data); II --------
}
II IOOi01102103i04105i06i07108109110111112i13114115i
)
II 120121122123124125126127128i29130i31i32133i34i351
II -----------------------------------------------------
void led clr(void)
I /clear the led
{
send_config(Ox01);
delay(350);
}
59