Beruflich Dokumente
Kultur Dokumente
EMBEDDEDSYSTEMANDHARDWAREDESIGNING
USINGVARIOUSBOARDS
SubmittedinPartialFulfillmentoftheRequirementsoftheDegreeof
BACHELOROFTECHNOLOGYin
ELECTRICALANDELECTRONICSENGINEERING
By
AKHILPRATAP
02813204914
EEE
akhil19pratap@gmail.com
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
ACKNOWLEDGEMENTS
Ihavebeenveryfortunatetostartmythesisworkunderthesupervisionandguidance
ofProf.SanjayShrivastava.HeintroducedmetothefieldofEmbeddedsystems,
educatedmewiththemethodsandprinciplesofresearch,andguidedmethroughthe
detailsofvariousmicrocontrollers.HeisthewholePhilosopherandGuidebehindthis
thesis.Workingwithhim,apersonofvalueshasbeenarewardingexperience.
Iamhighlyindebtedandexpressmydeepsenseofgratitudeforhisinvaluable
guidance,constantinspirationandmotivationwithenormousmoralsupportduring
difficultphasetocompletethework.Iacknowledgehiscontributionsandappreciatethe
effortsputbyhimforhelpingmecompletethisreport.
Iwouldliketotakethisopportunitytothankourseniors,theHeadoftheDepartmentof
IEEEforconductingvariousSIGsondifferentdevelopmentboards.Iamthankfultohim
foralwaysextendingeverykindofsupporttome.
AtthismomentIwouldalsoliketoexpressmygratitudeforthetechnicalstaffofour
laboratories.Theyhavealwayshelpedmeineverywaytheycanduringmy
experimentalphaseofthework.
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
ABSTRACT
Anembeddedsystemisacomputersystemwithadedicatedfunctionwithinalarger
mechanicalorelectricalsystem,oftenwithrealtimecomputingconstraints.Modern
embeddedsystemsareoftenbasedonmicrocontrollers(i.e.CPUswithintegrated
memoryorperipheralinterfaces),butordinarymicroprocessors(usingexternalchipsfor
memoryandperipheralinterfacecircuits)arealsocommon,especiallyinmorecomplex
systems.
EmbeddedsystemsrangefromportabledevicessuchasdigitalwatchesandMP3
players,tolargestationaryinstallationsliketrafficlights,factorycontrollers,andlargely
complexsystemslikehybridvehicles,MRI,andavionics.Complexityvariesfromlow,
withasinglemicrocontrollerchip,toveryhighwithmultipleunits,peripheralsand
networksmountedinsidealargechassisorenclosure
Amicroprocessordevelopmentboardisaprintedcircuitboardcontaininga
microprocessorandtheminimalsupportlogicneededforanengineertobecome
acquaintedwiththemicroprocessorontheboardandtolearntoprogramit.Italso
servedusersofthemicroprocessorasamethodtoprototypeapplicationsinproducts.
Unlikeageneralpurposesystemsuchasahomecomputer,usuallyadevelopment
boardcontainslittleornohardwarededicatedtoauserinterface.Itwillhavesome
provisiontoacceptandrunausersuppliedprogram,suchasdownloadingaprogram
throughaserialporttoflashmemory,orsomeformofprogrammablememoryina
socketinearliersystems.
SomeofthedevelopmentboardsareArduino,AVRdevelopmentboard,TIMSP430
LAUNCHPAD,etc.
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
CONTENTS
1.
2.
3.
4.
5.
Introductiontoembeddedsystemandmicrocontrollers.6
Workingofanembeddedsystem..7
Microcontrollerdevelopmentboards.8
Featuresofdevelopmentboards...9
Variousdevelopmentboards
5.1Arduino
5.1.1ArduinoUNOhardwarespecs.12
5.1.2Software(environmentfordevelopment)..................15
5.1.2.A:Arduinolibraries18
5.1.2.B:Arduinobasicprograms..19
5.2TexasInstrumentsTIMSP430launchpad
5.2.1:Hardwarespecifications..30
5.2.2:IDEforMSP430Launchpad.34
5.3AVRdevelopmentboard
5.3.1:Hardwarespecifications.36
5.3.2:Softwarerequiredforinteraction...40
Projectreport
1.1:IntroductiontoProject...43
1.2:Objectiveoftheproject..44
1.3:Basicprincipleinvolved..45
1.4:Lightspectrumwtrwavelength..46
1.5:ProgramUsed..48
1.6:UsingIRmoduleformeasuringHeartbeat50
1.7:Applications....53
6.BIBLIOGRAPHY54
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
LISTOFFIGURESANDTABLES
Fig1.1Variouscomponentsoftheembeddedsys..6
Fig2.1Arduinodevelopmentboard.8
Fig2.2AVRdevelopmentboard.9
Fig3.1Arduinoboardsusing7seglightdiode...10
Fig4.1developmentboardArduinoUNO.....11
Fig4.2variouspinoutputsoftheArduinoUNO...12
Table1.1SpecsoftheArduinoUNOdevelopmentboard..13
Fig4.3AtmetATMega328P..13
Fig4.4ArduinoUNOIDE.15
Fig4.5connectionofArduinoUNOwithapc..16
Fig4.6basiclayoutoftheArduinoIDE17
Fig4.7serialmonitorintheArduinoUNO...25
Fig4.8PWMregardingthedutycycle..27
Fig5.1MSP430Launchpad.29
Fig5.2pinoutspecificationsoftheLaunchpad.31
Table5.1technicalspecsoftheMsp420G2452..32
Fig5.3IDEfortheMSP430LP...33
Fig5.4comparisonofthetwoIDEs.34
Fig6.1Avrdevelopmentboard..35
Fig6.2fullyequippedAVRdb..38
Fig6.3userinterfaceoftheAtmelstudio6.0..39
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
1. INTRODUCTIONTOEMBEDDEDSYSTEMSANDMICROCONTROLLERS
Anembeddedsystemissomecombinationofcomputerhardwareandsoftware,either
fixedincapabilityorprogrammable,thatisspecificallydesignedforaparticularfunction.
Industrialmachines,automobiles,medicalequipment,cameras,householdappliances,
airplanes,vendingmachinesandtoys(aswellasthemoreobviouscellularphoneand
PDA)areamongthemyriadpossiblehostsofanembeddedsystem.Embedded
systemsthatareprogrammableareprovidedwithprogramminginterfaces,and
embeddedsystemsprogrammingisaspecializedoccupation.
Thesoftwarewhichisusedforinterfacingwithaparticularembeddedsystemor
developmentboardisknownastheENVIRONMENTofthatparticularsystem.
Fig1.1:VariouscomponentsofEmbeddedsystem
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
2.WORKINGOFANEMBEDDEDSYSTEM
Embeddedsystemusesmicrocontrollersforthevarioustaskassignedtothem.
Thetermmicroprocessorandmicrocontrollerhavealwaysbeenconfusedwitheach
other.Bothofthemhavebeendesignedforrealtimeapplication.Theysharemany
commonfeaturesandatthesametimetheyhavesignificantdifferences.BoththeICs
i.e.,themicroprocessorandmicrocontrollercannotbedistinguishedbylookingatthem.
Theyareavailableindifferentversionstartingfrom6pintoashighas80to100pinsor
evenhigherdependingonthefeatures.
Differencebetweenmicroprocessorandmicrocontroller
MicroprocessorisanICwhichhasonlytheCPUinsidethemi.e.onlytheprocessing
powerssuchasIntelsPentium1,2,3,4,core2duo,i3,i5etc.Thesemicroprocessors
donthaveRAM,ROM,andotherperipheralonthechip.Asystemdesignerhastoadd
themexternallytomakethemfunctional.Applicationofmicroprocessorincludes
DesktopPCs,Laptops,notepadsetc.
ButthisisnotthecasewithMicrocontrollers.MicrocontrollerhasaCPU,inaddition
withafixedamountofRAM,ROMandotherperipheralsallEmbeddedonasingle
chip.Attimesitisalsotermedasaminicomputeroracomputeronasinglechip.
Todaydifferentmanufacturersproducemicrocontrollerswithawiderangeoffeatures
availableindifferentversions.SomemanufacturersareATMEL,Microchip,TI,
Freescale,Philips,Motorolaetc.
Basically,aMicrocontrollerisasmallCPU..consistingofRAM,ROMandother
peripheralscontaininginasmallchip.
ExamplesareATMELAVR(8bit),AVR32(32bit),TEXASINSTRUMENTSTI
MSP430(32bit),etc.
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
3.MICROCONTROLLERDEVELOPMENTBOARDS
Amicrocontrollerdevelopmentboardisaprintedcircuitboardcontaininga
microcontrollerandtheminimalsupportlogicneededforanengineertobecome
acquaintedwiththemicroprocessorontheboardandtolearntoprogramit.Italso
servedusersofthemicroprocessorasamethodtoprototypeapplicationsinproducts.
Unlikeageneralpurposesystemsuchasahomecomputer,usuallyadevelopment
boardcontainslittleornohardwarededicatedtoauserinterface.Itwillhavesome
provisiontoacceptandrunausersuppliedprogram,suchasdownloadingaprogram
throughaserialporttoflashmemory,orsomeformofprogrammablememoryina
socketinearliersystems.
Fig2.1:ARDUINODEVELOPMENTBOARD
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Fig2.2:AVRdevelopmentboard
4.FEATURESOFDEVELOPMENTBOARDS
ThemostimportantfeatureofthemicroprocessordevelopmentboardwastheROM
basedbuiltinmachinelanguagemonitor,or"debugger"asitwasalsosometimes
called.Oftenthenameoftheboardwasrelatedtothenameofthismonitorprogram,for
examplethenameofthemonitorprogramoftheKIM1was"KeyboardInputMonitor",
becausetheROMbasedsoftwareallowedentryofprogramswithouttherowsof
cumbersometoggleswitchesthatoldersystemsused.Thepopular6800based
systemsoftenusedamonitorwithanamewiththeword"bug"for"debugger"init,for
examplethepopular"MIKBUG".
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Oftentheboardhassomekindtoexpansionconnectorthatbroughtoutallthe
necessaryCPUsignals,sothatanengineercouldbuildandtestanexperimental
interfaceorotherelectronicdevice.
Themajorapplicationofdevelopmentboardisthatitcaninterfacewithotherelectrical
components..
Itcanbeusedtooperatevariouselectricalcomponentsdependinguponthevarious
conditionswhichisprocessedinthemicrocontrollers.
DevelopmentboardarebasicallyusedfortheapplicationinInternetofthings,Home
automation,etc.
Fig3.1:Arduinodevelopmentboardusinga7seglightdiode
10
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
5.VARIOUSDEVELOPMENTBOARDS
5.1:ARDUINO
5.1.1ARDUINOUNOHARDWARESPECS
Fig4.1:DevelopmentboardArduinoUNO
11
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Arduinoisanopensourceprojectthatcreatedmicrocontrollerbasedkitsforbuilding
digitaldevicesandinteractiveobjectsthatcansenseandcontrolphysicaldevices.
Thesesystemsprovidesetsofdigitalandanaloginput/output(I/O)pinsthatcan
interfacetovariousexpansionboards(termedshields)andothercircuits.Theboards
featureserialcommunicationinterfaces,includingUniversalSerialBus(USB)onsome
models,forloadingprogramsfrompersonalcomputers.Forprogrammingthe
microcontrollers,theArduinoprojectprovidesanintegrateddevelopment
environment(IDE)basedonaprogramminglanguagenamedProcessing,whichalso
supportsthelanguagesCandC++.
Fig4.2:VariouspinoutputsofArduinoUNO.
12
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
ArduinoUNOboardusesamicrocontrollernamedAtmelATmega328P.
Table1.1:SpecificationofArduinoUNOdevelopmentboard
Fig4.3:AtmelATmega328PMicrocontroller
13
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
ArduinoUNOdevelopmentboardcanbeusedwithvariousotherelectricalcomponents
andcaninteractwiththem.
Sincetheoperatingvoltageislow(~5V)thusisalowpowerdevelopmentboard.
Whatmakesadevelopmentboardsspecialisthattheycaninteractwithalmostall
electricalcomponentsandthusmakingthemuseefficiently.
SuchexamplesofusingdevelopmentboardscanbeseeninHomeautomation,Internet
ofthings,etc.
5.1.2Software(environmentfordevelopment)
TheArduinoprojectprovidestheArduinointegrateddevelopmentenvironment(IDE),
whichisacrossplatformapplicationwrittenintheprogramminglanguageJava.
ItoriginatedfromtheIDEforthelanguagesProcessingandWiring.Itisdesignedto
introduceprogrammingtoartistsandothernewcomersunfamiliarwithsoftware
development.Itincludesacodeeditorwithfeaturessuchassyntaxhighlighting,brace
matching,andautomaticindentation,andprovidessimpleoneclickmechanismto
compileandloadprogramstoanArduinoboard.AprogramwrittenwiththeIDEfor
Arduinoiscalleda"sketch".[15]
TheArduinoIDEsupportsthelanguagesCandC++usingspecialrulestoorganize
code.TheArduinoIDEsuppliesasoftwarelibrarycalledWiringfromtheWiring
project,whichprovidesmanycommoninputandoutputprocedures.AtypicalArduino
C/C++sketchconsistoftwofunctionsthatarecompiledandlinkedwithaprogramstub
main()intoanexecutablecyclicexecutiveprogram:
setup():afunctionthatrunsonceatthestartofaprogramandthatcan
initializesettings.
loop():afunctioncalledrepeatedlyuntiltheboardpowersoff.
AftercompilingandlinkingwiththeGNUtoolchain,alsoincludedwiththeIDE
distribution,theArduinoIDEemploystheprogramavrdudetoconverttheexecutable
14
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
codeintoatextfileinhexadecimalcodingthatisloadedintotheArduinoboardbya
loaderprogramintheboard'sfirmware.
Fig4.4:BasicuserinterfaceofArduinoUNOIDE
15
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Fig4.5:ConnectionofArduinoUNOwithaPCforuploadingaprogrammeinthemicrocontroller
ThelanguagethatisusedinArduinoUNOIDEisC/C++.
Thisisusedtointeractwiththevariouspingivenontheboardandusethem
individually.
Variouselectricalcomponentsareconnectedtotheterminalsofthedevelopmentboard
andtheterminalscanbeassignedInputorOutputpinviatheprogrammingintheIDE.
InArduinoUNOonlypin13haveinternalresistancethatisanycomponentcanbe
addedtopin13withoutaddinganyexternalresistance.
InthedevelopmentboardthereisanextrapushbuttongivenneartheUSBportcalled
Reset.
Themainfunctionoftheresetbuttonistoclearthememoryofthemicrocontroller.
Whichmeansthatonpressingtheresetbuttontheboardwillclearanyorallthe
previousstoredprogrammesinthemicrocontroller.
TheresetbuttoncleartheROMoftheMicrocontroller.
16
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Fig4.6:basiclayoutofArduinoIDE
VariousprogrammesarepreinstalledintheArduinoIDEforthefirsttimerstogetan
ideaonhowtheprogrammesworkinthisenvironmentandhowtheyareuploaded.
OncetheprogrammeiswrittenintheIDEthenitischeckedforerrorviacompilingand
thenisuploadedtotheboardbypressingthetheuploadbuttongivenintheIDE.
IntheArduinoUNOIDEtherearesomelibrariespreinstalledwhichhelpstheuserto
writeaprogrammemuchmoreeasilyandefficiently.
5.1.2.A:Arduinolibraries
LibrariesarefileswritteninCorC++(.c,.cpp)whichprovideyoursketches
withextrafunctionality(e.g.theabilitytocontrolanLEDmatrix,orreadan
encoder,etc.).TheywereintroducedinArduino0004.
17
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
TouseanexistinglibraryinasketchsimplygototheSketchmenu,choose
"ImportLibrary",andpickfromthelibrariesavailable.Thiswillinsertan
#includestatementatthetopofthesketchforeachheader(.h)fileinthe
library'sfolder.Thesestatementsmakethepublicfunctionsandconstants
definedbythelibraryavailabletoyoursketch.TheyalsosignaltheArduino
environmenttolinkthatlibrary'scodewithyoursketchwhenitiscompiled
oruploaded.
Usingalibraryhavesomedrawbackstoo..
Oneofthemiswhenlibrariesareuploadedtotheboardwithyoursketch,
theyincreasetheamountofspaceusedbytheATmega328ontheboard.
WhileusinglibrariesoneshouldkeepinmindthatIfasketchnolonger
needsalibrary,simplydeleteits#includestatementsfromthetop
ofyourcode.ThiswillstoptheArduinoIDEfromlinkingthelibrary
withyoursketchanddecreasetheamountofspaceusedonthe
Arduinoboard.
ThishelpstheMicrocontrollertosavesomememoryinitandthuscanbe
efficientlyutilized.
5.1.2.B:Arduinobasicprogrammesandfunctions.
InArduinoIDEvariousbasicexamplesaregivensothatoecanlearnfromit.
Thevariousexamplesaregivenintheformofprogrammesdoingsimpletaskslike
blinkinganled,orchangingthebrightnessofitandmuchmoreprogrammesincluding
variouselectricalcomponentslikebuzzer,pushbuttons,leds,IR(infraredleds),etc.
TheseexamplesarefoundintheArduinoIDE,justclickFile>Examples>Basics.
InBasicsthereare6programmespresentfor6basicpurposes.
Theseprogrammesare
1.AnalogReadSerial
18
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
2.BareMinimum
3.Blink
4.DigitalReadSerial
5.Fade
6.ReadAnalogVoltage
Thesebasicsprogrammesareveryhelpfulforusertogetabasicideaonhowtheboard
worksandhowcompilationanduploadingprocessisdoneviaIDE
Theprogramsare
1. AnalogReadSerial:
/*
AnalogReadSerial
Readsananaloginputonpin0,printstheresulttotheserialmonitor.
Graphicalrepresentationisavailableusingserialplotter(Tools>SerialPlottermenu)
AttachthecenterpinofapotentiometertopinA0,andtheoutsidepinsto+5Vand
ground.
Thisexamplecodeisinthepublicdomain.
*/
//thesetuproutinerunsoncewhenyoupressreset:
voidsetup(){
//initializeserialcommunicationat9600bitspersecond:
Serial.begin(9600)
}
//thelooproutinerunsoverandoveragainforever:
voidloop(){
//readtheinputonanalogpin0:
intsensorValue=analogRead(A0)
//printoutthevalueyouread:
Serial.println(sensorValue)
delay(1)//delayinbetweenreadsforstability
}
19
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Theaboveprogramsbasicfunctionalityistomeasuretheanaloginputgiventothepin
A0andprinttheoutputinserialmonitor
Serial.begin(9600)intheaboveprogramsignifiesthebaudrateoftheboard,iethe
numberofbitsitscantransferpersec
Theserialplotterisusedtomeasureorprinttheanalogvaluesobtainedfromthe
analogpinsthiscanbeveryhelpfulinmeasuringachangeintheinputofananalog
signal.
2.Blink
/*
Blink
TurnsonanLEDonforonesecond,thenoffforonesecond,repeatedly.
MostArduinoshaveanonboardLEDyoucancontrol.OntheUnoand
Leonardo,itisattachedtodigitalpin13.Ifyou'reunsurewhat
pintheonboardLEDisconnectedtoonyourArduinomodel,check
thedocumentationathttp://www.arduino.cc
Thisexamplecodeisinthepublicdomain.
*/
//thesetupfunctionrunsoncewhenyoupressresetorpowertheboard
voidsetup(){
//initializedigitalpin13asanoutput.
pinMode(13,OUTPUT)
}
//theloopfunctionrunsoverandoveragainforever
voidloop(){
digitalWrite(13,HIGH)//turntheLEDon(HIGHisthevoltagelevel)
delay(1000)//waitforasecond
digitalWrite(13,LOW)//turntheLEDoffbymakingthevoltageLOW
delay(1000)//waitforasecond
20
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Intheaboveprogram..Pin13isusedtoconnecttheLEDbecauseonPinno13an
additionalinternalresistanceisalreadyincluded.ThissavestheLEDfromgettingburnt
outfromthehighcurrentifitsattachedtoadifferentPINwithoutanyresistance.
Variousfunctionsusedintheaboveprogram
pinMode(Pinno,INPUT/OUTPUT)
ThisfunctionallowsthearduinotodecidewhichPinisusedforwhatpurpose
Example:ifwewantpin5tobeanoutputpinandpin4tobeaninputpin
Sothecommandswhichwillbewritteninthesetupdialogwillbe
pinMode(5,OUTPUT)
pinMode(4,INPUT)
Theabovetwolinesassignpin5foroutputpurposeandpin4forinput.
digitalWrite(pinno,high/low)
digitalRead(pinno)
digitalWriteanddigitalReadarethetwofunctionswhichallowsustoreadthestateor
alterthestateofdigitalpins.
Indigitalelectronicsthesignalonlycontainstwovaluesie1(HIGH)and0(LOW).
UsingthefunctiondigitalRead(pinno)
Wecanfindoutthestateofthedigitalpinitisin..
Ifthestatedpinnoisat1(High)
Theabovefunctionwillreturnvalue1and0otherwise.
21
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
ThefunctiondigitalWrite(pinno,HIGH/LOW)
Isusedtodefinethestateofthedigitalpin.
Tomakeadigitalpinhighjustwrite
digitalWrite(13,HIGH)
Theabovetwocommandsarewritteninthethesetupdialogboxtodefinethe
permanentlyforaparticularprogram.
*note:thedigitalReadanddigitalWritecommandscanonlyworkonthedigitalpinsof
theboard
delay(noofms)
Theabovecommandisthemostcommoncommandusedinarduinoprogramming.
Thiscommandsignifiesthatthethecompilerwillwaitforparticularnumberof
millisecondsthatisstatedinthecommandbeforeexecutingthenextcommand.
Thismeansthatthepreviouscommandwillrunfortheamountoftimewritteninthe
delayfunctionbeforeexecutingnextcommand.
Iftheaboveblinkprogramisrunwithoutthedelaycommandthentheblinkingwouldbe
sofasttobeevennoticedbyanakedeye,hencethedelaycommandisused.
3.DigitalReadSerial
/*
DigitalReadSerial
Readsadigitalinputonpin2,printstheresulttotheserialmonitor
Thisexamplecodeisinthepublicdomain.
22
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
*/
//digitalpin2hasapushbuttonattachedtoit.Giveitaname:
intpushButton=2
//thesetuproutinerunsoncewhenyoupressreset:
voidsetup(){
//initializeserialcommunicationat9600bitspersecond:
Serial.begin(9600)
//makethepushbutton'spinaninput:
pinMode(pushButton,INPUT)
}
//thelooproutinerunsoverandoveragainforever:
voidloop(){
//readtheinputpin:
intbuttonState=digitalRead(pushButton)
//printoutthestateofthebutton:
Serial.println(buttonState)
delay(1)//delayinbetweenreadsforstability
}
Theaboveprogramisusetoreadthedigitalinputgivenatthepinno2andprintthe
outputattheserialmonitor
InArduinothepinno2isattachedtoapushbuttonandthedigitalstateofthatpinis
readviafunctiondigitalRead()
Andtheaboveinputisfedtotheserialmonitorforprocessingandtheoutput.
23
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Fig4.6:SerialmonitorinArduinoIDE
TheserialmonitorcanbedisplayedbyclickingTools>SerialMonitor.
Allthecommunicationmadeinarduinoboardisbidirectionaliebitscantransferinany
directionsfromtheboardtoPCorviceversa..
24
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
4.Fade
/*
Fade
ThisexampleshowshowtofadeanLEDonpin9
usingtheanalogWrite()function.
TheanalogWrite()functionusesPWM,soif
youwanttochangethepinyou'reusing,be
suretouseanotherPWMcapablepin.Onmost
Arduino,thePWMpinsareidentifiedwith
a"~"sign,like~3,~5,~6,~9,~10and~11.
Thisexamplecodeisinthepublicdomain.
*/
intled=9//thePWMpintheLEDisattachedto
intbrightness=0//howbrighttheLEDis
intfadeAmount=5//howmanypointstofadetheLEDby
//thesetuproutinerunsoncewhenyoupressreset:
voidsetup(){
//declarepin9tobeanoutput:
pinMode(led,OUTPUT)
}
//thelooproutinerunsoverandoveragainforever:
voidloop(){
//setthebrightnessofpin9:
analogWrite(led,brightness)
//changethebrightnessfornexttimethroughtheloop:
brightness=brightness+fadeAmount
//reversethedirectionofthefadingattheendsofthefade:
25
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
if(brightness==0||brightness==255){
fadeAmount=fadeAmount
}
//waitfor30millisecondstoseethedimmingeffect
delay(30)
}
IntheaboveprogramthetermPWMisused.
PWMstandsforPulseWidthModulation
PulseWidthModulation,orPWM,isatechniqueforgettinganalogresults
withdigitalmeans.Digitalcontrolisusedtocreateasquarewave,asignal
switchedbetweenonandoff.Thisonoffpatterncansimulatevoltagesin
betweenfullon(5Volts)andoff(0Volts)bychangingtheportionofthe
timethesignalspendsonversusthetimethatthesignalspendsoff.The
durationof"ontime"iscalledthepulsewidth.Togetvaryinganalogvalues,
youchange,ormodulate,thatpulsewidth.Ifyourepeatthisonoffpattern
fastenoughwithanLEDforexample,theresultisasifthesignalisasteady
voltagebetween0and5vcontrollingthebrightnessoftheLED.
Inthegraphicbelow,thegreenlinesrepresentaregulartimeperiod.This
durationorperiodistheinverseofthePWMfrequency.Inotherwords,with
Arduino'sPWMfrequencyatabout500Hz,thegreenlineswouldmeasure2
millisecondseach.AcalltoanalogWrite()isonascaleof0255,suchthat
analogWrite(255)requestsa100%dutycycle(alwayson),and
analogWrite(127)isa50%dutycycle(onhalfthetime)forexample.
26
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Fig4.7:PWMregardingthedutycycle
InthearduinoboardthePWMpinsarerepresentedby(~)beforetheirpin
number.
Thereforeanypinwith(~)beforeitiscapableofPWM.
ThefunctionanalogWrite()isusetoassignthedutycycleofaparticularpin.
Whenthepinisbeingusedat100%dutycyclethemaximumvalueitattains
is255.
Itmeansthatifthefunctionissayingforexample
analogWrite(9,255)
Thatmeansthatthefunctionisrequestingthepintobeoperatedat100%
dutycycle.
27
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
5.ReadAnalogVoltage
/*
ReadAnalogVoltage
Readsananaloginputonpin0,convertsittovoltage,andprintstheresult
totheserialmonitor.
Graphicalrepresentationisavailableusingserialplotter(Tools>Serial
Plottermenu)
AttachthecenterpinofapotentiometertopinA0,andtheoutsidepinsto
+5Vandground.
Thisexamplecodeisinthepublicdomain.
*/
//thesetuproutinerunsoncewhenyoupressreset:
voidsetup(){
//initializeserialcommunicationat9600bitspersecond:
Serial.begin(9600)
}
//thelooproutinerunsoverandoveragainforever:
voidloop(){
//readtheinputonanalogpin0:
intsensorValue=analogRead(A0)
//Converttheanalogreading(whichgoesfrom01023)toavoltage(0
5V):
floatvoltage=sensorValue*(5.0/1023.0)
//printoutthevalueyouread:
Serial.println(voltage)
}
TheaboveprogramisdesignedtotakeandinputinAnalogpinA0andthen
plotthegivenvoltageinSerialplotter
28
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
5.2TexasInstrumentsTIMSP430LAUNCHPAD
5.2.1:Hardwarespecifications
TheMSP430seriesbyTexasInstrumentsisalowpowerconsuming
developmentboards.
TheonlydrawbackofMSP430seriesisthattheIDEofthisboardcantbe
runonLINUXoranyIOS.
Fig5.1:MSP430launchpad
TheabovepadisMSP430launchpad.
ThebasicsstructureofthislaunchpadissameasthatonArduino.
29
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
TheMSPEXP430G2LaunchPadDevelopmentKitisaneasytousemicrocontroller
developmentboardforthelowpowerandlowcostMSP430G2xMCUs.
Ithasonboardemulationforprogramminganddebuggingandfeaturesa14/20pin
DIPsocket,onboardbuttonsandLEDs&BoosterPackPluginModulepinoutsthat
supportawiderangeofmodulesforaddedfunctionalitysuchaswireless,displays&
more.
TheMSPEXP430G2LaunchPadalsocomeswith2MSP430devices,withupto16kB
Flash,512BRAM,16MHzCPUspeedandintegratedperipheralssuchas8ch10bit
ADC,timers,serialcommunication(UART,I2C&SPI)&more!
TheMSP430launchpadpreincludessomesensorsalreadyintegratedontheboard.
Thelaunchpadhasatemperaturesensoraproximitysensorandaposition
sensor.
TheabovesensorsonbeingpreinstalledhelpsustomakeuseoftheLaunchPad
withoutanexternalelectronicscomponents.
30
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Fig5.2:PinoutspecificationsoftheLaunchPad
ThemicrocontrollerusedinthelaunchpadistheultralowpowerMSP430G2452.
TheTexasInstrumentsMSP430familyofultralowpowermicrocontrollersconsistof
severaldevicesfeaturingdifferentsetsofperipheralstargetedforvariousapplications.
Thearchitecture,combinedwithfivelowpowermodes,isoptimizedtoachieve
extendedbatterylifeinportablemeasurementapplications.Thedevicefeaturesa
powerful16bitRISCCPU,16bitregisters,andconstantgeneratorsthatcontributeto
maximumcodeefficiency.Thedigitallycontrolledoscillator(DCO)allowswakeupfrom
lowpowermodestoactivemodeinlessthan1s.
31
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
TechnicalspecificationofthemicrocontrollerMSP430G2452
Features:
LowSupplyVoltageRange:1.8Vto3.6V
UltraLowPowerConsumption
ActiveMode:220Aat1MHz,2.2V
StandbyMode:0.5A
OffMode(RAMRetention):0.1A
Parameters:
MSP430G2452Microcontroller
CPU
MSP430
FREQUENCY(MHz)
16
NONVOLATILEMEMORY
RAM(KB)
0.25
GPIOPIN(#)
16
12C
SPI
ADC
ADC108ch
TIMER(16bit)
MINVcc
1.8V
MAXVcc
3.6V
ACTIVEPOWER(uA/MHz)
320
STANDBYPOWER(uA)
0.7
Table5.1:technicalspecificationsofthemicrocontrollerMSP430G2452
32
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
TheMSP430launchpadisfamousbecauseofitsultralowpowerconsumptionsand
operations.
Thefrequencyatwhichthelaunchpadoperatesis16MHzbutthisfrequencycanbe
changedsimplybyusingtheIDE.
5.2.2:IDEforMSP430Launchpad
Fig5.3:IDEforMSP430Launchpad
TheuserinterfaceoftheIDEofLaunchpadissimilartothatoftheArduino.
ThereisbasicallynodifferencebetweenthetwoIDEs.
TheprogramminglanguageusedinthelaunchpadIDEisC/C++.Thereforeitisquite
easytodevelopvariousprogramsforthethisboardusingvariouselectronics
components.
33
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
TheIDEofthelaunchpadisbasicallyderivedfromthatoftheArduino,thereforethe
resemblanceisuncanny.ThebasicdifferencebetweenthetwoIDEisthatinArduino
youhaveserialplotterwhereasinthelaunchpadnosuchthingisavailable.
Fig5.4:sidebysidecomparisonofthetwoIDEs
TheIDEoftheLaunchpadisderivedfromtheArduinoitselfsotheprogramswhichrun
intheArduinoboardcanbemadetorunontheLaunchpad.
34
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
5.3AVRdevelopmentboards
5.3.1Hardware
TheAVRdevelopmentboardisbasicallyaboarddesignedtousetheATMEL
microcontrollers.TheATMELmicrocontrollersarequitepopularandhenceareused
invariousapplicationslikeHOMEAUTOMATION,SECURITY,etc.
TheAVRmicrocontrollerssuchasATMega32,ATMega64,ATMega16arequite
popular.Thenoattheendrepresentthebitamicrocontrollercanstore.
Fig6.1:AVRdevelopmentboards
35
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
AVRisafamilyofmicrocontrollersdevelopedbyAtmelbeginningin1996.Theseare
modifiedHarvardarchitecture8bitRISCsinglechipmicrocontrollers.AVRwasoneof
thefirstmicrocontrollerfamiliestouseonchipflashmemoryforprogramstorage,as
opposedtoonetimeprogrammableROM,EPROM,orEEPROMusedbyother
microcontrollersatthetime.
ThisfamilyofmicrocontrollersaredividedintomanysubgroupssuchastinyAVR,
megaAVR,Xmega,applicationspecificAVR,etc..
Themicrocontrollerscomingintothesecategoriescanbeusedforaspecificpurpose
onlythemicrocontrollerusedintheAVRdevelopmentboardisgenerally
ATMega16.
Themicrocontrollerweareusingis8bitAVRmicrocontrollerwith32Kbinsystem
programmableFlash.
FeaturesofATMega32
Highperformance,LowpowerAtmelAVR8bitMicrocontroller
AdvancedRISCArchitecture
131PowerfulInstructionsMostSingleclockCycleExecution
328GeneralPurposeWorkingRegisters
FullyStaticOperation
Upto16MIPSThroughputat16MHz
Onchip2cycleMultiplier
HighEnduranceNonvolatileMemorysegments
32KbytesofInSystemSelfprogrammableFlashprogrammemory
1024BytesEEPROM
2KbytesInternalSRAM
Write/EraseCycles:10,000Flash/100,000EEPROM
Dataretention:20yearsat85C/100yearsat25C(1)
OptionalBootCodeSectionwithIndependentLockBits
InSystemProgrammingbyOnchipBootProgram
TrueReadWhileWriteOperation
ProgrammingLockforSoftwareSecurity
JTAG(IEEEstd.1149.1Compliant)Interface
BoundaryscanCapabilitiesAccordingtotheJTAGStandard
36
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
ExtensiveOnchipDebugSupport
ProgrammingofFlash,EEPROM,Fuses,andLockBitsthroughtheJTAG
Interface
PeripheralFeatures
Two8bitTimer/CounterswithSeparatePrescalersandCompareModes
One16bitTimer/CounterwithSeparatePrescaler,CompareMode,andCapture
Mode
RealTimeCounterwithSeparateOscillator
FourPWMChannels
8channel,10bitADC
8SingleendedChannels
7DifferentialChannelsinTQFPPackageOnly
2DifferentialChannelswithProgrammableGainat1x,10x,or200x
ByteorientedTwowireSerialInterface
ProgrammableSerialUSART
Master/SlaveSPISerialInterface
ProgrammableWatchdogTimerwithSeparateOnchipOscillator
OnchipAnalogComparator
SpecialMicrocontrollerFeatures
PoweronResetandProgrammableBrownoutDetection
InternalCalibratedRCOscillator
ExternalandInternalInterruptSources
SixSleepModes:Idle,ADCNoiseReduction,Powersave,Powerdown,Standby
andExtendedStandby
I/OandPackages
32ProgrammableI/OLines
40pinPDIP,44leadTQFP,and44padQFN/MLF
OperatingVoltages
2.7V5.5VforATmega32L
4.5V5.5VforATmega32
SpeedGrades
08MHzforATmega32L
016MHzforATmega32
PowerConsumptionat1MHz,3V,25C
Active:1.1mA
IdleMode:0.35mA
PowerdownMode:<1A
37
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
ThemainfeatureoftheAVRdevelopmentboardisthattheusercandirectlyinteract
withthepinsofthemicrocontroller.
Thisgivestheadvantageofthepinstobeusedindependentlyandmoreefficiently.
Fig6.2:AfullyequippedAVRboard
AfullyequippedAVRboardcomeswithallthebasicelectronicscomponentsnecessary
forgettingstartedwiththeboard.
ThiscontainsaLCDscreen,Abuzzer,8LEDsand8Switches.
TheATMega32microcontrollerhasasingleA/DconvertorwhichislocatedontheA
port.
The40pinsoftheATMega32have8pinsforVcc,groundetc.andtheother32pins
aredividedinto4partsieA,B,CandD.
OutofwhichportAisonlycapableoftheA/Dconversion.
38
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
5.3.2SoftwarerequiredofinteractionwiththeboardIDE
ThesoftwarerequiredfortheinteractionwiththeATMega32ofanyotherAVR
microcontrollersisAtmelstudio6.0.
InthisSoftwaretheprogrammingisdoneinC/C++.
Theprogramisstoredin.cformatjustlikeinCprogramming.
Fig6.3:UserinterfaceoftheAtmelstudio6.0
39
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
InAtmelstudiotheuserinterfaceconsistsofmainly3boxoneofthemisthatin
whichyouwriteyourcode.Thesecondoneisforthecompilationbox,inwhichyoucan
seethecompilationprocessaswellasanyerrorsifanypresentinthecode..Thisboxis
generallylocatedatthebottomofthewindow.
Thethirdwindowwhichislocatedatthetoprightofthescreenshowsthefunctionsyou
haveusedintheprogram.
Thishelpsusaccesstheprogrameasilyandavoidanyerrorifpresentthere.
BeforelearningtoprogramintheAtmelstudio,bitwiseoperationsisnecessaryto
learn.
Somebasicfunctionstoincludebeforewritingcode
#include<avr/io.h>
Itsgoingtobewritteninalltheprograms.Itsaheaderfilewhichcontainsalotofthe
codethatwedonthavetowritebysimplyaddingthisheaderfile.Itcontainsvarious
definitionsfortheAVRmicrocontrollers.
Voidmain(void){}
Themainpartoftheprogramstartshere.Thevoidinthebeginningsignifiesthatweare
notgoingtoreturnanyvalues.Thevoidinthebracketssignifiesthatthereshouldbeno
valuespassedintothis.
DDR(datadirectionregister)
Thisallowustochangethestateofftheportietotakeaportasaninputoroutput
dependsontheDDRstatement.
ExampleDDRB=0b00000001
Forthefurtheruseofthisportweuse
PORTBthisallowsustousetheparticularPORTofthemicrocontroller
40
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Andchangeanypinoftheporttoinputoroutputiftheprogramrequiresso.
Fig6.4:programfortheblinkingofaLED
41
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
PROJECTREPORT
HEARTBEATMONITORUSINGEMBEDDEDSYstem
Submittedinpartialfulfilmentoftherequirementofthedegreeof
BACHELOROFTECHNOLOGYin
ELECTRICALANDELECTRONICSENGINEERING
By
Akhilpratap
02813204914
EEE
42
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
1.1Introductiontotheproject
Theembeddedsystemcanbedefinedasaseriesofaprocesscontainingsimplesteps
andprocessingtheoutputviarealtimeprocessing.
Fig1.1:Basicstepsregardingembeddedsystem
ThesestepsareprocessedinthemicrocontrollersandtheuserinterfaceisviatheIDE
orthesensorswhichcomesundertheperipherals.
1.2Objectiveoftheproject:
TheobjectiveofthisprojectistoexplorethecapabilityoftheArduinoboardbymaking
aheartbeatmonitor.
Thisprojectrequiresvarioussensorsandmodules.
Variousknowledgeaboutthesubjectisneededformakingthisprojectsuchas
1. KnowledgeoftheArduinoUnokitanditsworkingenvironment.
2. Humananatomyandhowthebodyworks.
3. KnowledgeoflightsandtheirwavelengthsandaboutLDR.
4. OperationofanOPAMP.
43
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Themainreasonforselectingthearduinoboardofthedevelopmentofthisprojectisthe
userfriendlyenvironment.AndeaseofcodingintheIDE.
1.3Basicprincipleinvolved
Ourbodyhavenervesinallpartsofthebody.Thefunctionofthesenervesisto
distributethebloodinallpartsofthebody.
Thebloodflowismaintainedviatheheart,whichpumpsthebloodsothatitcan
circulateproperly.
Duetothistheheartbeatcanbefeltindifferentbodypartsbecauseoftherushofthe
bloodinthenerveswitheverypumpofthepart.
Thisbloodflowcanbeusedtodeterminetheheartbeatoftheperson.
TherearevariouswaystomeasuretheHeartbeat.
1. Viapressuresensors
2. VialightsandLDR.
Fig1.2:Bloodflowinthenervesofthehand
44
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Inthisprojectwearegoingtomeasuretheheartbeatbyusingthelightsource.
Thebasicprincipleinvolvedisthatwheneverthebloodflowsthroughthearteriesinthe
handtheopacityofthefingersincreasesbecauseoftheincreasedbloodflow.This
increaseinopacitycanbemeasurewiththehelpofLDR.
ALDRisaLightDependentResistorwhosevaluechangesdependinguponthelight
fallinguponit.Thischangeinthevalueoftheresistorcanbemeasuredandtherefore
canbeusedtomeasuretheHeartbeatoftheperson.
1.4:Thelightspectrumwrtthewavelengths
Fig1.3:Thelightspectrumwrtwavelengthandfrequency
45
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Aswecanseefromtheabovefigurethewavelengthoftheredlightisthemaximumin
thevisiblerangeandwiththeminimumfrequency.
Aswealreadyknowthatredlightgetsleastdispersed,henceitstheperfectsourceof
visiblelightfortheproject.
Alsointheabovespectrum,theIR(Infrared)rayhasbiggerwavelengthcomparedto
theredlightandhencethereadingcanbemoreaccuratebuttheproblemiswiththe
LDRsoinsteadoftheLDRweusethephotodiodeandreceivetheanalogsignalofthe
diodeandthechangeinthatanalogsignalcanbeusedtomeasuretheHeartbeat.
Whenafingertipisplacedclosetotheledlightsource,45%ofthelightisabletopass
throughit.
ThislightsignalcanbeusedfordetectionpurposeusinganLDR.
Fig1.4:LightDetectingResistor
46
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
1.5:Programused:
Themainobjectiveistomeasurethechangeintheanalogvaluetheanalogvalueofthe
LDRandcountthechangepresentinit.
/*programtocountthenoofchangeintheanalogvalueoftheLDRandthus
calculatingthevalueoftheHeartbeart
thisprogramrequiresandanalogpinandonedigitalpin.
thedigitalpinisfortheRedledandtheAnalogpinforthe
LDR
*/
/*ThissketchprintstheHEARTBEATtotheLCD
Thecircuit:
*LCDRSpintodigitalpin12
*LCDEnablepintodigitalpin11
*LCDD4pintodigitalpin5
*LCDD5pintodigitalpin4
*LCDD6pintodigitalpin3
*LCDD7pintodigitalpin2
*LCDR/Wpintoground
*LCDVSSpintoground
*LCDVCCpinto5V
*10Kresistor:
*endsto+5Vandground
*wipertoLCDVOpin(pin3)
*/
#include<LiquidCrystal.h>
LiquidCrystallcd(12,11,5,4,3,2)
unsignedlongt_start,t_now
intcount=0
intinitial
intfin
voidsetup(){
47
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
lcd.begin(16,2)
Serial.begin(9600)
pinMode(13,OUTPUT)
pinMode(A0,INPUT)
digitalWrite(13,HIGH)
}
voidloop(){
t_start=millis()
t_now=millis()
while(t_nowt_start<6000)
{
t_now=millis()
initial=analogRead(A0)
Serial.println(initial)
delay(50)
fin=analogRead(A0)
if(fininitial>10)
count++
}
lcd.print(count)
}
Hereintheaboveprogramaliquidcrystaldisplayhasbeenusedtoshowthevalueof
heartbeatperminutewiseofthehumanhand.
ThedifferencebetweenthetwoanalogvaluesoftheLDRistakentobe10torecordthe
heartbeatoftheperson.
48
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Fig1.5:connectionoftheLCDwithArduino
TheaboveprogramiswrittenbytakinginmindthataRedledisbeingusedtoservethe
purposeofthelightsource.
ThecaseiswholedifferentwhenaIRsourceistaken.
1.6:UsinganIRmoduleformeasuringtheHeartbeat
Fig1.6:IRled
49
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
Fig1.7:IRdetectorsorphotodiode
ThesetwocomponentsareusedformakingaheartbeatmonitoralongwiththeLCD
screen.
Theprogramforthefollowingis:
/*programtocountthenoofchangeintheanalogvalueofthephotodiodeandthus
calculatingthevalueoftheHeartbeart
thisprogramrequiresandanalogpinandonedigitalpin.
thedigitalpinisfortheRedledandtheAnalogpinforthediode
*/
/*ThissketchprintstheHEARTBEATtotheLCD
Thecircuit:
*LCDRSpintodigitalpin12
*LCDEnablepintodigitalpin11
*LCDD4pintodigitalpin5
*LCDD5pintodigitalpin4
*LCDD6pintodigitalpin3
*LCDD7pintodigitalpin2
*LCDR/Wpintoground
*LCDVSSpintoground
50
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
*LCDVCCpinto5V
*10Kresistor:
*endsto+5Vandground
*wipertoLCDVOpin(pin3)
*/
#include<LiquidCrystal.h>
LiquidCrystallcd(12,11,5,4,3,2)
unsignedlongt_start,t_now
intcount=0
intinitial
intfin
voidsetup(){
lcd.begin(16,2)
Serial.begin(9600)
pinMode(13,OUTPUT)
pinMode(A0,INPUT)
digitalWrite(13,HIGH)
}
voidloop(){
t_start=millis()
t_now=millis()
while(t_nowt_start<6000)
{
t_now=millis()
initial=analogRead(A0)
Serial.println(initial)
delay(50)
fin=analogRead(A0)
if(fininitial>10)
count++
}
lcd.print(count)
}
51
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
1.7:Applications
Theabovecomponentscanbeembeddedintoonesinglecomponentspecifically
designedformeasuringtheheartbeat.
Intheworldwhereobesityhasbecomeacommonproblemandpeoplearesuffering
fromgreatHealthissuessuchasHeartdiseases,asthamaetc.
Oneneedtotakecareofhimselfregularly.Onecandosobyconstantlymonitoringthe
heartbeatofhim/herself.Thishelpsinagreatdealtokeepcheckoftheirdietsand
improvetheirlifestyleofliving.
Thissensorcanalsoplayanimportantroleinwarningthepersonthatifhis/her
heartbeatisnotstableandneedsamedicalattention.
Everythinginthiseraisgoingformodernisationletitbeyourmobileorsomethingelse.
Sodoesyourhealthmonitors.
Thissensorandbeusedwithanymicrocontrollersandwiththehelpofanywifimodule
canbeconnectedtoyourmobilephones
OnesuchwifimoduleistheESP2866.
Fig1.8:ESP2866WIFImodule
52
EMBEDDEDSYSTEMSANDHARDWAREDESIGNUSINGVARIOUSBOARDSAKHILPRATAP
BIBLIOGRAPHY
[1].www.arduino.cc
[2].TonyGivargisFrankVahid:EmbeddedSystemDesign:AUnifiedHardware/
SoftwareIntroduction
[3].https://www.ti.com/
[4].Wikipedia.org
[5].www.atmel.com/products/microcontrollers/avr/ATmega32
[6].DatasheetsoftheMicrocontrollersATmega328P,ATmega32,MSP430G2452.
53