Getting Started with Arduino


Чтобы посмотреть этот PDF файл с форматированием и разметкой, скачайте его и откройте на своем компьютере.
steNsKMrecJe?rJyTheseNrMjects?reLMtiLteLdedfMruse
UseMftheiLstructiMLs?LdsuggestiMLsiL
WheL*c?Keb?ck*st?rtedtMs?veKMLey bec?use*
.yfirst?LdKMstiKNMrt?LtNrMject?fterth?tw?susiLg
Kybr?LdLew;X81cMKNutertMcMLtrMJ?weJdiLg
K?chiLe*kLMwitdMesL'tsMuLdJike?veryexcitiLg
NrMject buttherew?s?LeedfMrit?Lditw?s?gre?t
ch?JJeLgefMrKe bec?use*h?djustJe?rLedhMwtM
NrMgr?KAtthisNMiLt itbec?KecJe?rth?twritiLgJiLes
MfcMdewMuJdt?keJesstiKeth?LKMdifyiLgcMKNJex
TweLtyMddye?rsJ?ter *'dJiketMthiLkth?tthis
exNerieLce?JJMwsKetMte?chNeMNJewhMdML'teveL
reKeKbert?kiLg?LyK?thcJ?ss?LdtMiLfusetheKwith
thes?KeeLthusi?sK?Ld?biJitytMtiLkerth?t*h?diLKy
FirstMf?JJ*w?LttMth?LkKyN?rtLersiLtheArduiLM
Te?KD?vidCu?rtieJJes D?vid.eJJis Gi?LJuc?
.?rtiLM ?LdTMK*gMe*tis?L?K?ziLgexNerieLce
Weh?veverifiedtheiLfMrK?tiMLiLthisbMMktMthebest
MfMur?biJity butyMuK?yfiLdthiLgsth?th?vech?Lged
(MreveLth?tweK?deKist?kes! As?re?derMfthis
bMMk yMuc?LheJNustMiKNrMvefutureeditiMLsby
seLdiLgusyMurfeedb?ckPJe?seJetuskLMw?bMut?Ly
errMrs iL?ccur?cies KisJe?diLgMrcMLfusiLgst?teKeLts
PJe?se?JsMJetuskLMwwh?twec?LdMtMK?kethisbMMk
KMreusefuJtMyMuWet?keyMurcMKKeLtsseriMusJy
?LdwiJJtrytMiLcMrNMr?tere?sML?bJesuggestiMLsiLtM
.?ker.edi?is?divisiMLMfO'ReiJJy.edi?devMted
eLtireJytMthegrMwiLgcMKKuLityMfresMurcefuJNeMNJe
whMbeJieveth?tifyMuc?LiK?giLeit yMuc?LK?keit
CMLsistiLgMf.?keK?g?ziLe Cr?ftK?g?ziLe .?ker
F?ire ?sweJJ?stheH?cks .?kePrMjects ?LdD*:
ScieLcebMMkseries .?ker.edi?eLcMur?gesthe
Chapter1.Introduction
ArduiLMis?LMNeLsMurceNhysic?JcMKNutiLgNJ?tfMrK
b?sedML?siKNJeiLNut/MutNut(*/O bM?rd?Ld?
deveJMNKeLteLvirMLKeLtth?tiKNJeKeLtsthePrMcessiLg
J?Lgu?ge(
ArduiLMc?LbeusedtM
deveJMNst?Ld?JMLeiLter?ctiveMbjectsMrc?Lbe
cMLLectedtMsMftw?reMLyMurcMKNuter(such?sFJ?sh
PrMcessiLg VVVV Mr.?x/.SP ThebM?rdsc?Lbe
?sseKbJedbyh?LdMrNurch?sedNre?sseKbJedtheMNeL
sMurce*DE(*Ltegr?tedDeveJMNKeLtELvirMLKeLt c?L
ArduiLMisdiffereLtfrMKMtherNJ?tfMrKsMLtheK?rket
_*tis?KuJtiNJ?tfMrKeLvirMLKeLtitc?LruLML
_*tisb?sedMLthePrMcessiLgNrMgr?KKiLg*DE
?Le?sytMusedeveJMNKeLteLvirMLKeLtusedby
_:MuNrMgr?Kitvi??USBc?bJe LMt?seri?JNMrt
Thisfe?tureisusefuJ bec?useK?LyKMderL
_*tisMNeLsMurceh?rdw?re?LdsMftw?re—ifyMu
wish yMuc?LdMwLJM?dthecircuitdi?gr?K buy
?JJthecMKNMLeLts ?LdK?keyMurMwL withMut
_Theh?rdw?reische?NTheUSBbM?rdcMsts
?bMut€20(curreLtJy ?bMutUS$35 ?LdreNJ?ciLg
?burLtMutchiNMLthebM?rdise?sy?LdcMstsLM
KMreth?L€5MrUS$4SMyMuc?L?ffMrdtM
_Thereis?L?ctivecMKKuLityMfusers sMthere
_TheArduiLMPrMjectw?sdeveJMNediL?L
educ?tiML?JeLvirMLKeLt?LdistherefMregre?t
ThisbMMkisdesigLedtMheJNbegiLLersuLderst?Ldwh?t
beLefitstheyc?LgetfrMKJe?rLiLghMwtMusethe
ThisbMMkw?swritteLfMrthe"MrigiL?J"ArduiLMusers
desigLers?Ld?rtistsTherefMre ittriestMexNJ?iLthiLgs
iL?w?yth?tKightdrivesMKeeLgiLeerscr?zyActu?JJy
MLeMftheKc?JJedtheiLtrMductMrych?NtersMfKyfirst
dr?ft"fJuff"Th?t'sNreciseJytheNMiLt-et'sf?ceitKMst
eLgiLeers?reL't?bJetMexNJ?iLwh?ttheydMtM?LMther
eLgiLeer Jet?JMLe?reguJ?rhuK?LbeiLg-et'sLMw
ArduiLMbuiJdsuNMLthethesiswMrk
HerL?LdMB?rr?g?LdidMLtheWiriLg
NJ?tfMrKwhiJestudyiLguLderC?seyRe?s
?Ld Ke ?t *D** *vre?
AfterArduiLMst?rtedtMbecMKeNMNuJ?r *re?JisedhMw
exNeriKeLters hMbbyists ?Ldh?ckersMf?JJsMrtswere
st?rtiLgtMuseittMcre?tebe?utifuJ?Ldcr?zyMbjects*
re?Jisedth?tyMu're?JJ?rtists?LddesigLersiLyMurMwL
ArduiLMw?sbMrLtMte?ch*Lter?ctiMLDesigL ?desigL
disciNJiLeth?tNutsNrMtMtyNiLg?ttheceLtreMfits
KethMdMJMgyThere?reK?LydefiLitiMLsMf*Lter?ctiML
InteractionDesignisthe
designofanyinteractive
*LtMd?y'swMrJd *Lter?ctiMLDesigLiscMLcerLedwiththe
cre?tiMLMfKe?LiLgfuJexNerieLcesbetweeLus(huK?Ls
?LdMbjects*tis?gMMdw?ytMexNJMrethecre?tiMLMf
be?utifuJ—?LdK?ybeeveLcMLtrMversi?J—exNerieLces
betweeLus?LdtechLMJMgy*Lter?ctiMLDesigL
WhatIsPhysical
Physic?JCMKNutiLguseseJectrMLicstMNrMtMtyNeLew
*tiLvMJvesthedesigLMfiLter?ctiveMbjectsth?tc?L
cMKKuLic?tewithhuK?LsusiLgseLsMrs?Ld?ctu?tMrs
cMLtrMJJedby?beh?viMuriKNJeKeLted?ssMftw?re
ruLLiLgiLside?KicrMcMLtrMJJer(?sK?JJcMKNuterML?
*LtheN?st usiLgeJectrMLicsKe?Lth?viLgtMde?Jwith
eLgiLeers?JJthetiKe ?LdbuiJdiLgcircuitsMLesK?JJ
cMKNMLeLt?tthetiKetheseissueskeNtcre?tiveNeMNJe
frMKNJ?yiLg?rMuLdwiththeKediuKdirectJy.MstMf
thetMMJswereKe?LtfMreLgiLeers?LdreOuiredexteLsive
kLMwJedge*LreceLtye?rs KicrMcMLtrMJJersh?ve
becMKeche?Ner?Lde?siertMuse ?JJMwiLgthecre?tiML
TheNrMgressth?tweh?veK?dewithArduiLMistMbriLg
thesetMMJsMLesteNcJMsertMtheLMvice ?JJMwiLgNeMNJe
tMst?rtbuiJdiLgstuff?fterMLJytwMMrthreed?ysMf?
Chapter2.TheArduino
TheArduiLMNhiJMsMNhyisb?sedMLK?kiLgdesigLs
r?therth?Lt?JkiLg?bMuttheK*tis?cMLst?Ltse?rchfMr
f?ster?LdKMreNMwerfuJw?ystMbuiJdbetterNrMtMtyNes
Weh?veexNJMredK?LyNrMtMtyNiLgtechLiOues?Ld
CJ?ssiceLgiLeeriLgreJiesML?strictNrMcessfMrgettiLg
frMKAtMBtheArduiLMW?ydeJightsiLtheNMssibiJity
ThisisthetiLkeriLgNrMcessth?twe?resMfMLd
Mf—NJ?yiLgwiththeKediuKiL?LMNeLeLdedw?y?Ld
fiLdiLgtheuLexNected*Lthisse?rchfMrw?ystMbuiJd
betterNrMtMtyNes we?JsMseJected?LuKberMfsMftw?re
N?ck?gesth?teL?bJetheNrMcessMfcMLst?LtK?LiNuJ?tiML
TheLextfewsectiMLsNreseLtsMKeNhiJMsMNhies eveLts
PrMtMtyNiLgis?tthehe?rtMftheArduiLMW?yweK?ke
thiLgs?LdbuiJdMbjectsth?tiLter?ctwithMtherMbjects
WebeJieveth?titisesseLti?JtMNJ?ywithtechLMJMgy
exNJMriLgdiffereLtNMssibiJitiesdirectJyMLh?rdw?re?Ld
ReusiLgexistiLgtechLMJMgyisMLeMfthebestw?ysMf
tiLkeriLgGettiLgche?NtMysMrMJddisc?rdedeOuiNKeLt
?Ldh?ckiLgtheKtMK?ketheKdMsMKethiLgLewisMLe
*h?ve?Jw?ysbeeLf?sciL?tedbyKMduJ?rity?Ldthe
?biJitytMbuiJdcMKNJexsysteKsbycMLLectiLgtMgether
siKNJedevicesThisNrMcessisveryweJJreNreseLtedby
RMbert.MMg?Ldhis?L?JMguesyLthesizers.usici?Ls
cMLstructedsMuLds tryiLgeLdJesscMKbiL?tiMLsby
"N?tchiLgtMgether"differeLtKMduJeswithc?bJesThis
?NNrM?chK?dethesyLthesizerJMMkJike?LMJdteJeNhMLe
switch butcMKbiLedwiththeLuKerMuskLMbs th?tw?s
theNerfectNJ?tfMrKfMrtiLkeriLgwithsMuLd?Ld
iLLMv?tiLgKusic.MMgdescribedit?s?NrMcess
betweeL"witLessiLg?LddiscMveriLg"*'KsureKMst
Kusici?Ls?tfirstdidL'tkLMwwh?t?JJthMsehuLdredsMf
kLMbsdid buttheytried?Ldtried refiLiLgtheirMwL
ReduciLgtheLuKberMfiLterruNtiMLstMthefJMwisvery
iKNMrt?LtfMrcre?tivity—theKMrese?KJesstheNrMcess
ThistechLiOueh?sbeeLtr?LsJ?tediLtMthewMrJdMf
sMftw?reby"visu?JNrMgr?KKiLg"eLvirMLKeLtsJike
.?x PureD?t? MrVVVVThesetMMJsc?Lbevisu?Jised
?s"bMxes"fMrthediffereLtfuLctiML?Jitiesth?tthey
NrMvide JettiLgtheuserbuiJd"N?tches"bycMLLectiLg
thesebMxestMgetherTheseeLvirMLKeLtsJettheuser
exNeriKeLtwithNrMgr?KKiLgwithMutthecMLst?Lt
iLterruNtiMLtyNic?JMftheusu?JcycJe"tyNeNrMgr?K
Circuit Bending
CircuitbeLdiLgisMLeMftheKMstiLterestiLgfMrKsMf
tiLkeriLg*t'sthecre?tiveshMrtcircuitiLgMfJMwvMJt?ge
b?tteryNMweredeJectrMLic?udiMdevicessuch?sguit?r
effectNed?Js chiJdreL'stMys ?LdsK?JJsyLthesizerstM
cre?teLewKusic?JiLstruKeLts?LdsMuLdgeLer?tMrs
Thehe?rtMfthisNrMcessisthe"?rtMfch?Lce"*tbeg?LiL
166wheLReedGh?z?J? bych?Lce shMrtedMut?tMy
?KNJifier?g?iLst?Ket?JMbjectiLhisdeskdr?wer
Keyboard Hacks
PeMNJethrMw?w?y?JMtMftechLMJMgythesed?ysMJd
NriLters cMKNuters weirdMfficeK?chiLes techLic?J
eOuiNKeLt ?LdeveL?JMtMfKiJit?rystuffThereh?s
?Jw?ysbeeL?bigK?rketfMrthissurNJustechLMJMgy
esNeci?JJy?KMLgyMuLg?Ld/MrNMMrerh?ckers?LdthMse
whM?rejustst?rtiLgMutThisK?rketbecMKeevideLtiL
*vre? wherewedeveJMNedArduiLMThecityusedtMbe
thehe?dOu?rtersMftheOJivetticMKN?LyTheyh?dbeeL
K?kiLgcMKNuterssiLcethe160siLtheKid10s they
threweverythiLg?w?yiLjuLky?rdsiLthe?re?These?re
fuJJMfcMKNuterN?rts eJectrMLiccMKNMLeLts ?Ldweird
devicesMf?JJkiLdsWesNeLtcMuLtJesshMursthere
buyiLg?JJsMrtsMfcMLtr?NtiMLsfMrveryJittJeKMLey?Ld
h?ckiLgiLtMMurNrMtMtyNesWheLyMuc?Lbuy?
thMus?LdJMudsNe?kersfMrveryJittJeKMLey yMu'rebMuLd
tMcMKeuNwithsMKeide?iLtheeLdAccuKuJ?tejuLk
?LdgMthrMughitbefMrest?rtiLgtMbuiJdsMKethiLgfrMK
TMys?re?f?Lt?sticsMurceMfche?NtechLMJMgytMh?ck
?Ldreuse ?sevideLcedbytheNr?ctiseMfcircuitbeLdiLg
KeLtiMLede?rJierWiththecurreLtiLfJuxMfthMus?LdsMf
veryche?NhightechtMysfrMKChiL? yMuc?LbuiJd
Ouickide?swith?fewLMisyc?ts?Ld?cMuNJeMfJight
swMrds*h?vebeeLdMiLgthisfMr?fewye?rstMgetKy
studeLtstMuLderst?Ldth?ttechLMJMgyisLMtsc?ryMr
difficuJttM?NNrM?chOLeMfKyf?vMuriteresMurcesisthe
bMMkJet"-MwTechSeLsMrs?LdActu?tMrs"byUsK?L
H?Oue?LdAd?KSMKJ?iFischer
*thiLkth?ttheyh?ve
NerfectJydescribedthistechLiOueiLth?th?LdbMMk ?Ld*
CMJJ?bMr?tiMLbetweeLusersisMLeMftheykeyNriLciNJes
iLtheArduiLMwMrJd—thrMughthefMruK?t
NeMNJefrMKdiffereLtN?rtsMfthewMrJd
heJNe?chMtherJe?rL?bMuttheNJ?tfMrKTheArduiLM
te?KeLcMur?gesNeMNJetMcMJJ?bMr?te?t?JMc?JJeveJ?s
weJJbyheJNiLgtheKsetuNusers'grMuNsiLeverycity
theyvisitWe?JsMsetuN?Wikic?JJed"PJ?ygrMuLd"
www?rduiLMcc/NJ?ygrMuLd
whereusersdMcuKeLt
theirfiLdiLgs*t'ssM?K?ziLgtMseehMwKuch
kLMwJedgetheseNeMNJeNMurMutMLtheWebfMr
everybMdytMuseThiscuJtureMfsh?riLg?LdheJNiLg
e?chMtherisMLeMfthethiLgsth?t*'KKMstNrMudMfiL
Chapter3.TheArduino
ArduiLMiscMKNMsedMftwMK?jMrN?rtstheArduiLM
bM?rd whichistheNieceMfh?rdw?reyMuwMrkMLwheL
yMubuiJdyMurMbjects?LdtheArduiLM*DE theNieceMf
sMftw?reyMuruLMLyMurcMKNuter:Muusethe*DEtM
cre?te?sketch(?JittJecMKNuterNrMgr?K th?tyMu
uNJM?dtMtheArduiLMbM?rdThesketchteJJsthebM?rd
/MttMMJMLg?gM wMrkiLgMLh?rdw?reKe?LtbuiJdiLg
circuitsfrMKscr?tch usiLghuLdredsMfdiffereLt
cMKNMLeLtswithstr?LgeL?KesJikeresistMr c?N?citMr
Everycircuitw?s"wired"tMdMMLesNecific?NNJic?tiML
?LdK?kiLgch?LgesreOuiredyMutMcutwires sMJder
Withthe?NNe?r?LceMfdigit?JtechLMJMgies?Ld
KicrMNrMcessMrs thesefuLctiMLs whichwereMLce
iKNJeKeLtedwithwires werereNJ?cedbysMftw?re
SMftw?reise?siertMKMdifyth?Lh?rdw?reWith?few
keyNresses yMuc?Lr?dic?JJych?LgetheJMgicMf?device
InteractionDesignisthedesignofany
?LdtrytwMMrthreeversiMLsiLthes?Ke?KMuLtMftiKe
TheArduiLMbM?rdis?sK?JJKicrMcMLtrMJJerbM?rd
whichis?sK?JJcircuit(thebM?rd th?tcMLt?iLs?whMJe
cMKNuterML?sK?JJchiN(theKicrMcMLtrMJJer This
cMKNuteris?tJe?st?thMus?LdtiKesJessNMwerfuJth?L
the.?cBMMk*'KusiLgtMwritethis butit's?JMtche?Ner
?LdveryusefuJtMbuiJdiLterestiLgdevices-MMk?tthe
ArduiLMbM?rdyMu'JJsee?bJ?ckchiNwith28
"Jegs"—th?tchiNistheATKeg?168 thehe?rtMfyMur
We(theArduiLMte?K h?veNJ?cedMLthisbM?rd?JJthe
cMKNMLeLtsth?t?rereOuiredfMrthisKicrMcMLtrMJJertM
wMrkNrMNerJy?LdtMcMKKuLic?tewithyMurcMKNuter
There?reK?LyversiMLsMfthisbM?rdtheMLewe'JJuse
thrMughMutthisbMMkistheArduiLMDueKiJ?LMve which
isthesiKNJestMLetMuse?LdthebestMLefMrJe?rLiLgML
HMwever theseiLstructiMLs?NNJytMe?rJierversiMLsMf
thebM?rd iLcJudiLgtheKMrereceLtArduiLMDieciKiJ?
?LdtheMJderArduiLM/G
Figure31
shMwstheArduiLM
Figure32
*LthMseiJJustr?tiMLs yMuseetheArduiLMbM?rdAtfirst
?JJthMsecMLLectMrsKightbe?JittJecMLfusiLgHereis?L
Thesec?LbeiLNutsMrMutNuts whichissNecifiedbythe
6AnalogueInpins(pins
Thesededic?ted?L?JMgueiLNutNiLst?ke?L?JMguev?Jues
(ie vMJt?gere?diLgsfrMK?seLsMr ?LdcMLverttheK
6AnalogueOutpins(pins3,
These?re?ctu?JJysixMfthedigit?JNiLsth?tc?Lbe
reNrMgr?KKedfMr?L?JMgueMutNutusiLgthesketchyMu
ThebM?rdc?LbeNMweredfrMKyMurcMKNuter'sUSB
NMrt KMstUSBch?rgers Mr?LAC?d?Nter(vMJts
recMKKeLded 21KKb?rreJtiN ceLterNMsitive *fthere
isLMNMwersuNNJyNJuggediLtMtheNMwersMcket the
NMwerwiJJcMKefrMKtheUSBbM?rd but?ssMML?syMu
/OTE*fyMu?reusiLgtheMJder
ArduiLM/GMrArduiLMDieciKiJ? yMu
wiJJLeedtMsettheNMwerseJectiMLjuKNer
(J?beJJedPWR>SE-MLthebM?rd tM
sNecifyEXT(exterL?J MrUSBNMwer
ThisjuKNerc?LbefMuLdbetweeLthe
The*DE(*Ltegr?tedDeveJMNKeLtELvirMLKeLt is?
sNeci?JNrMgr?KruLLiLgMLyMurcMKNuterth?t?JJMws
yMutMwritesketchesfMrtheArduiLMbM?rdiL?siKNJe
J?Lgu?geKMdeJed?fterthePrMcessiLg
J?Lgu?geTheK?gich?NNeLs
wheLyMuNressthebuttMLth?tuNJM?dsthesketchtMthe
bM?rdthecMdeth?tyMuh?vewritteListr?LsJ?tediLtMthe
CJ?Lgu?ge(whichisgeLer?JJyOuiteh?rdfMr?begiLLer
tMuse ?LdisN?ssedtMthe?vrgcccMKNiJer ?L
iKNMrt?LtNieceMfMNeLsMurcesMftw?reth?tK?kesthe
fiL?Jtr?LsJ?tiMLiLtMtheJ?Lgu?geuLderstMMdbythe
KicrMcMLtrMJJerThisJ?ststeNisOuiteiKNMrt?Lt bec?use
it'swhereArduiLMK?kesyMurJifesiKNJebyhidiLg?w?y
?sKuch?sNMssibJeMfthecMKNJexitiesMfNrMgr?KKiLg
TheNrMgr?KKiLgcycJeMLArduiLMisb?sic?JJy?s
_PJugyMurbM?rdiLtM?USBNMrtMLyMur
_Write ? sketch th?t wiJJ briLg the bM?rd tM Jife
_UNJM?dthissketchtMthebM?rdthrMughtheUSB
cMLLectiML?Ldw?it?cMuNJeMfsecMLdsfMrthe
Chapter7.Troubleshooting
TherewiJJcMKe?KMKeLtiLyMurexNeriKeLt?tiMLwheL
LMthiLgwiJJbewMrkiLg?LdyMuwiJJh?vetMfigureMut
hMwtMfixitTrMubJeshMMtiLg?LddebuggiLg?re?LcieLt
?rtsiLwhichthere?re?fewsiKNJeruJes butKMstMfthe
TheKMreyMuwMrkwitheJectrMLics?LdArduiLM the
KMreyMuwiJJJe?rL?Ldg?iLexNerieLce whichwiJJ
uJtiK?teJyK?ketheNrMcessJessN?iLfuJDML'tbe
discMur?gedbytheNrMbJeKsth?tyMuwiJJfiLd—it's?JJ
AseveryArduiLMb?sedNrMjectisK?debMthMfh?rdw?re
?LdsMftw?re therewiJJbeKMreth?LMLeNJ?cetMJMMkif
sMKethiLggMeswrMLgWhiJeJMMkiLgfMr?bug yMu
TrytMuLderst?Ld?sKuch?sNMssibJehMwtheN?rtsth?t
yMu'reusiLgwMrk?LdhMwthey'resuNNMsedtMcMLtribute
InstallingArduinoon
TMNrMgr?KtheArduiLMbM?rd yMuKustfirstdMwLJM?d
thedeveJMNKeLteLvirMLKeLt(the*DE frMKhere
www?rduiLMcc/eL/.?iL/SMftw?re
ChMMsetheright
DMwLJM?dthefiJe?LddMubJecJickMLittMuLcMKNress
itthiswiJJcre?te?fMJderL?Ked
such
Dr?gth?tfMJdertMwhereveryMuwMuJd
JikeittMbeyMurdesktMN yMur/
fMJder(ML?
.?c MryMur
C:\ProgramFiles
fMJder(MLWiLdMws 
/MwwheLeveryMuw?LttMruLtheArduiLM*DE yMu'JJ
MNeLuNthe
fMJder ?LddMubJecJicktheArduiLM
icMLDML'tdMthisjustyet thMughthereisMLeKMresteN
/OTE*fyMuh?ve?LytrMubJeruLLiLg
theArduiLM*DE see
Ch?Nter7
/MwyMuKustiLst?JJthedriversth?t?JJMwyMur
InstallingDrivers:
-MMkfMrthe
fMJderiLsidethe
fMJder?LddMubJecJickthefiJec?JJed
wiJJbe
reNJ?cedwiththeversiMLLuKberMfthedriver fMr
/Mte*fyMu?reusiLg?L*LteJb?sed.?c
such?s?.?cBMMk .?cBMMkPrM
.?cBMMkAir .?cPrM Mr*LteJb?sed
.?c.iLiMri.?c besuretMiLst?JJthe
driverwith"*LteJ"iLitsL?Ke ?siL
*fyMu?reL'tusiLg?L*LteJb?sed.?c
/ext iLst?JJthesMftw?refrMKtheFTD*USBSeri?JDriver
N?ck?gebydMubJecJickiLgMLitFMJJMwtheiLstructiMLs
NrMvidedbytheiLst?JJer?LdtyNetheN?sswMrdMf?L
?dKiListr?tiveuserif?skedAttheeLdMfthisNrMcess
rest?rtyMurK?chiLetMK?kesureth?tthedrivers?re
NrMNerJyJM?ded/MwNJugthebM?rdiLtMyMurcMKNuter
InstallingDrivers:
PJugtheArduiLMbM?rdiLtMthecMKNuterwheLthe
FMuLd/ewH?rdw?reWiz?rdwiLdMwcMKesuN
WiLdMwswiJJfirsttrytMfiLdthedriverMLtheWiLdMws
WiLdMwsXPwiJJ?skyMuwhethertMcheckWiLdMws
UNd?teifyMudML'tw?LttMuseWiLdMwsUNd?te seJect
OLtheLextscreeL chMMse"*Lst?JJfrMK?JistMrsNecific
CheckthebMxJ?beJed"*LcJudethisJMc?tiMLiLthe
se?rch" cJickBrMwse seJectthefMJderwhereyMu
iLst?JJedArduiLM ?LdseJectthe
Drivers\FTDIUSB
WiLdMwsVist?wiJJfirst?tteKNttMfiLdthedriverML
WiLdMwsUNd?teifth?tf?iJs yMuc?LiLstructittMJMMk
:Mu'JJgMthrMughthisNrMceduretwice bec?usethe
cMKNuterfirstiLst?JJstheJMwJeveJdriver theLiLst?JJs?
NieceMfcMdeth?tK?kesthebM?rdJMMkJike?seri?JNMrt
PortIdentification:
FrMKtheTMMJsKeLuiLtheArduiLM*DE seJect"Seri?J
PMrt"?LdseJecttheNMrtth?tbegiLswith
thisistheL?Keth?tyMurcMKNuterusestM
refertMtheArduiLMbM?rd
Figure33
shMwstheJistMf
PortIdentification:
OLWiLdMws theNrMcessis?bitKMrecMKNJic?ted–?t
Je?st?tthebegiLLiLgONeLtheDevice.?L?gerby
cJickiLgtheSt?rtKeLu rightcJickiLgMLCMKNuter
(Vist? Mr.yCMKNuter(XP ?LdchMMsiLgPrMNerties
OLWiLdMwsXP cJickH?rdw?re?LdchMMseDevice
.?L?gerOLVist? cJickDevice.?L?ger(it?NNe?rsiL
-MMkfMrtheArduiLMdeviceiLtheJistuLder"PMrts
(CO.&-PT "TheArduiLMwiJJ?NNe?r?s?USB
Seri?JPMrt?LdwiJJh?ve?L?KeJikeCO.3 ?sshMwLiL
Figure34
Chapter4.Really
SeLsMrs?Ld?ctu?tMrs?reeJectrMLiccMKNMLeLtsth?t
AstheKicrMcMLtrMJJeris?verysiKNJecMKNuter itc?L
NrMcessMLJyeJectricsigL?Js(?bitJiketheeJectricNuJses
th?t?reseLtbetweeLLeurMLsiLMurbr?iLs FMrittM
seLseJight teKNer?ture MrMtherNhysic?JOu?Ltities it
LeedssMKethiLgth?tc?LcMLverttheKiLtMeJectricity*L
MurbMdy fMrex?KNJe theeyecMLvertsJightiLtMsigL?Js
th?tgetseLttMthebr?iLusiLgLerves*LeJectrMLics we
c?Luse?siKNJedevicec?JJed?JightdeNeLdeLtresistMr
(?L-DRMrNhMtMresistMr th?tc?LKe?surethe?KMuLtMf
Jightth?thitsit?LdreNMrtit?s?sigL?Jth?tc?Lbe
OLcetheseLsMrsh?vebeeLre?d thedeviceh?sthe
iLfMrK?tiMLLeededtMdecidehMwtMre?ctThe
decisiMLK?kiLgNrMcessish?LdJedbythe
KicrMcMLtrMJJer ?Ldthere?ctiMLisNerfMrKedby
?ctu?tMrs*LMurbMdies fMrex?KNJe KuscJesreceive
eJectricsigL?JsfrMKthebr?iL?LdcMLverttheKiLtM?
KMveKeLt*LtheeJectrMLicwMrJd thesefuLctiMLscMuJd
*LthefMJJMwiLgsectiMLs yMuwiJJJe?rLhMwtMre?d
seLsMrsMfdiffereLttyNes?LdcMLtrMJdiffereLtkiLdsMf
The-EDbJiLkiLgsketchisthefirstNrMgr?Kth?tyMu
shMuJdruLtMtestwhetheryMurArduiLMbM?rdiswMrkiLg
?LdiscMLfiguredcMrrectJy*tis?JsMusu?JJytheveryfirst
NrMgr?KKiLgexercisesMKeMLedMeswheLJe?rLiLgtM
NrMgr?K?KicrMcMLtrMJJerAJighteKittiLgdiMde(-ED
is?sK?JJeJectrMLiccMKNMLeLtth?t's?bitJike?Jight
buJb butisKMreefficieLt?LdreOuiresJMwervMJt?gestM
:MurArduiLMbM?rdcMKeswith?L-EDNreiLst?JJed*t's
K?rked"-":Muc?L?JsM?ddyMurMwL-ED—cMLLectit
Figure42
,iLdic?testhec?thMde(Leg?tive MrshMrterJe?dA
OLcethe-EDiscMLLected yMuLeedtMteJJArduiLM
wh?ttMdMThisisdMLethrMughcMde th?tis ?JistMf
iLstructiMLsth?twegivetheKicrMcMLtrMJJertMK?keitdM
/MticetheNreseLceMfcurJybr?ckets which?reusedtM
grMuNtMgetherJiLesMfcMdeThese?reN?rticuJ?rJyusefuJ
wheLyMuw?LttMgive?L?KetM?grMuNMfiLstructiMLs
*fyMu're?tdiLLer?LdyMu?sksMKebMdy "PJe?seN?ss
KetheP?rKes?Lcheese "thiskicksMff?seriesMf?ctiMLs
th?t?resuKK?risedbythesK?JJNhr?seth?tyMujust
s?idAswe'rehuK?Ls it?JJcMKesL?tur?JJy but?JJthe
iLdividu?JtiLy?ctiMLsreOuiredtMdMthisKustbesNeJJed
MuttMtheArduiLM bec?useit'sLMt?sNMwerfuJ?sMur
br?iLSMtMgrMuNtMgether?LuKberMfiLstructiMLs yMu
befMre yMurcMde ?Ld ?L
:Muc?Lseeth?tthere?retwMbJMcksMfcMdeth?t?re
defiLediLthisw?yhereBefMree?chMLeMftheKthereis
ArduinoIsNotfor
ArduiLMexNectstwMfuLctiMLstMexists—MLec?JJed
RealTinkerersWrite
ALytextbegiLLiLgwith//isigLMredbyArduiLMThese
JiLes?recMKKeLts which?reLMtesth?tyMuJe?veiLthe
NrMgr?KfMryMurseJf sMth?tyMuc?LreKeKberwh?tyMu
didwheLyMuwrMteit MrfMrsMKebMdyeJse sMth?tthey
*tisverycMKKML(*kLMwthisbec?use*dMit?JJthe
tiKe tMwrite?NieceMfcMde uNJM?ditMLtMthebM?rd
?Lds?y"Ok?y—*'KLevergMiLgtMh?vetMtMuchthis
sucker?g?iL!"MLJytMre?JisesixKMLthsJ?terth?tyMu
LeedtMuNd?tethecMdeMrfix?bugAtthisNMiLt yMu
MNeLuNtheNrMgr?K ?LdifyMuh?veL'tiLcJuded?Ly
cMKKeLtsiLtheMrigiL?JNrMgr?K yMu'JJthiLk
"WMw—wh?t?Kess!WheredM*st?rt?"AsweKMve
?JMLg yMu'JJseesMKetricksfMrhMwtMK?keyMur
Atfirst yMuKightcMLsiderthiskiLdMfexNJ?L?tiMLtM
uLLecess?ry ?bitJikewheL*w?siLschMMJ?Ld*h?dtM
studyD?Lte's
DivinaCommedia
(every*t?Ji?LstudeLth?s
tMgMthrMughth?t ?sweJJ?s?LMtherbMMkc?JJed
promessisposi
Mr
WhatWeWillBe
*h?ve?Jw?ysbeeLf?sciL?tedbyJight?Ldthe?biJitytM
cMLtrMJdiffereLtJightsMurcesthrMughtechLMJMgy*h?ve
beeLJuckyeLMughtMwMrkMLsMKeiLterestiLgNrMjects
th?tiLvMJvecMLtrMJJiLgJight?LdK?kiLgitiLter?ctwith
NeMNJeArduiLMisre?JJygMMd?tthisThrMughMutthis
bMMk wewiJJbewMrkiLgMLhMwtMdesigL"iLter?ctive
J?KNs" usiLgArduiLM?s?w?ytMJe?rLtheb?sicsMfhMw
*LtheLextsectiML *'JJtrytMexNJ?iLtheb?sicsMf
eJectricityiL?w?yth?twMuJdbMre?LeLgiLeer butwML't
*fyMuh?vedMLe?LyNJuKbiLg?thMKe eJectrMLicswML't
be?NrMbJeKfMryMutMuLderst?LdTMuLderst?LdhMw
eJectricity?LdeJectriccircuitswMrk thebestw?yistM
usesMKethiLgc?JJedthe"w?ter?L?JMgy"-et'st?ke?
siKNJedevice Jiketheb?tteryNMweredNMrt?bJef?L
Figure44
UsingaPushbuttonto
BJiLkiLg?L-EDw?se?sy but*dML'tthiLkyMuwMuJd
st?ys?LeifyMurdeskJ?KNweretMcMLtiLuMusJybJiLk
whiJeyMuweretryiLgtMre?d?bMMkTherefMre yMu
LeedtMJe?rLhMwtMcMLtrMJit*LMurNreviMusex?KNJe
the-EDw?sMur?ctu?tMr ?LdMurArduiLMw?s
cMLtrMJJiLgitWh?tisKissiLgtMcMKNJetetheNictureis?
*Lthisc?se we'regMiLgtMusethesiKNJestfMrKMf
*fyMuweretMt?ke?N?rt?NushbuttML yMuwMuJdseeth?t
itis?verysiKNJedevicetwMbitsMfKet?JkeNt?N?rtby
?sNriLg ?Ld?NJ?sticc?Nth?twheLNressedbriLgsthe
twMbitsMfKet?JiLtMcMLt?ctWheLthebitsMfKet?J?re
?N?rt thereisLMcircuJ?tiMLMfcurreLtiLtheNushbuttML
(?bitJikewheL?w?terv?JveiscJMsed wheLweNress
TMKMLitMrthest?teMf?switch there's?LewArduiLM
iLstructiMLth?tyMu'regMiLgtMJe?rLthe
checkstMseewhetherthereis?LyvMJt?ge
?NNJiedtMtheNiLth?tyMusNecifybetweeLN?reLtheses
*h?veiLtrMducedtwMLewcMLceNtswiththisex?KNJe
NrMgr?KfuLctiMLsth?treturLtheresuJtMftheirwMrk?Ld
st?teKeLtisNMssibJytheKMstiKNMrt?LtiLstructiML
iL?NrMgr?KKiLgJ?Lgu?ge bec?useit?JJMwsthe
cMKNuter(?LdreKeKber theArduiLMis?sK?JJ
cMKNuter tMK?kedecisiMLsAfterthe
keywMrd yMu
h?vetMwrite?"OuestiML"iLsideN?reLtheses ?Ldifthe
"?Lswer" MrresuJt istrue thefirstbJMckMfcMdewiJJbe
executedMtherwise thebJMckMfcMde?ftereJsewiJJbe
executed/Mticeth?t*h?veusedthesyKbMJiLste?d
MfThefMrKerisusedwheLtwMeLtities?recMKN?red
?LdreturLsTRUEMrFA-SEtheJ?tter?ssigLs?v?JuetM
?v?ri?bJe.?kesureth?tyMuusethecMrrectMLe
bec?useitisverye?sytMK?keth?tKist?ke?Ldusejust
 iLwhichc?seyMurNrMgr?KwiJJLeverwMrk*kLMw
bec?use?fter25ye?rsMfNrMgr?KKiLg *stiJJK?keth?t
HMJdiLgyMurfiLgerMLthebuttMLfMr?sJMLg?syMuLeed
JightisLMtNr?ctic?JAJthMughitwMuJdK?keyMuthiLk
?bMuthMwKucheLergyyMu'rew?stiLgwheLyMuw?Jk
?w?yfrMK?J?KNth?tyMuJeftML weLeedtMfigureMut
OneCircuit,A
Thegre?t?dv?Lt?geMfdigit?J NrMgr?KK?bJeeJectrMLics
MvercJ?ssiceJectrMLicsLMwbecMKesevideLt*wiJJshMw
yMuhMwtMiKNJeKeLtK?LydiffereLt"beh?viMurs"usiLg
thes?KeeJectrMLiccircuit?siLtheNreviMussectiML just
As*'veKeLtiMLedbefMre it'sLMtveryNr?ctic?JtMh?vetM
hMJdyMurfiLgerMLthebuttMLtMh?vetheJightMLWe
therefMreKustiKNJeKeLtsMKefMrKMf"KeKMry" iLthe
fMrKMf?sMftw?reKech?LisKth?twiJJreKeKberwheL
weh?veNressedthebuttML?LdwiJJkeeNtheJightML
TMdMthis we'regMiLgtMusewh?tisc?JJed?v?ri?bJe
(Weh?veusedMLe?Jre?dy but*h?veL'texNJ?iLedit A
v?ri?bJeis?NJ?ceiLtheArduiLMKeKMrywhereyMuc?L
stMred?t?ThiLkMfitJikeMLeMfthMsestickyLMtesyMu
usetMreKiLdyMurseJf?bMutsMKethiLg such?s?NhMLe
LuKberyMut?keMLe yMuwrite"-uis?025551212"ML
it ?LdyMustickittMyMurcMKNuterKMLitMrMryMur
fridge*LtheArduiLMJ?Lgu?ge it'seOu?JJysiKNJeyMu
justdecidewh?ttyNeMfd?t?yMuw?LttMstMre(?LuKber
MrsMKetext fMrex?KNJe giveit?L?Ke ?LdwheLyMu
Chapter5.Advanced
Wh?tyMuh?vejustJe?rLediL
Ch?Nter4
?retheKMst
eJeKeLt?ryMNer?tiMLswec?LdMiLArduiLMcMLtrMJJiLg
digit?JMutNut?Ldre?diLgdigit?JiLNut*fArduiLMwere
sMKesMrtMfhuK?LJ?Lgu?ge thMsewMuJdbetwMJetters
Mfits?JNh?betCMLsideriLgth?tthere?rejustfiveJetters
iLthis?JNh?bet yMuc?LseehMwKuchKMrewMrkwe
TryingOutOtherOn/Off
/Mwth?tyMu'veJe?rLedhMwtMuse?NushbuttML yMu
shMuJdkLMwth?tthere?reK?LyMtherveryb?sicseLsMrs
+ustJike?NushbuttML butdMesL't?utMK?tic?JJych?Lge
6AnalogueOutpins(pins3,5,6,9,10,and
Aswitchth?tMNeLswheLtheteKNer?turere?ches?set
AsiKNJeeJectrMLiccMKNMLeLtth?tcMLt?iLstwMcMLt?cts
?Ld?JittJeKet?Jb?JJ(Mr?drMNMfKercury but*dML't
recMKKeLdusiLgthMse ALex?KNJeMf?tiJtswitchis
c?JJed?tiJtseLsMr
Figure51
shMwstheiLsideMf?
tyNic?JKMdeJWheLtheseLsMrisiLitsuNrightNMsitiML
theb?JJbridgesthetwMcMLt?cts ?LdthiswMrksjust?sif
yMuh?dNressed?NushbuttMLWheLyMutiJtthisseLsMr
theb?JJKMves ?LdthecMLt?ctisMNeLed whichisjust?s
ifyMuh?dreJe?sed?NushbuttMLUsiLgthissiKNJe
cMKNMLeLt yMuc?LiKNJeKeLt fMrex?KNJe gestur?J
ControllingLightwith
WiththekLMwJedgeth?tyMuh?vesMf?rg?iLed yMu
cMuJdbuiJd?LiLter?ctiveJ?KNth?tc?Lbe
cMLtrMJJed—?LdLMtjustwith?bMriLgML/Mffswitch but
K?ybeiL?w?yth?t's?bitKMreeJeg?LtOLeMfthe
JiKit?tiMLsMfthebJiLkiLg-EDex?KNJesth?tweh?ve
usedsMf?risth?tyMuc?LturLtheJightMLJyML?LdMff
Af?LcyiLter?ctiveJ?KNLeedstMbediKK?bJeTMsMJve
thisNrMbJeK wec?Luse?JittJetrickth?tK?kes?JMtMf
thiLgssuch?sTVMrciLeK?NMssibJeNersisteLceMf
As*hiLted?fterthefirstex?KNJeiL
Ch?Nter4
ifyMu
ch?LgetheLuKbersiLthedeJ?yfuLctiMLuLtiJyMudML't
seethe-EDbJiLkiLg?LyKMre yMuwiJJLMticeth?tthe
-EDseeKstMbediKKed?t50%MfitsLMrK?J
brightLess/Mwch?LgetheLuKberssMth?tthe-EDis
MLisMLeOu?rterMfthetiKeth?tit'sMffRuLthesketch
?LdyMu'JJseeth?tthebrightLessisrMughJy25%This
techLiOueisc?JJedNuJsewidthKMduJ?tiML(PW. ?
f?Lcyw?yMfs?yiLgth?tifyMubJiLkthe-EDf?st
eLMugh yMudML'tseeitbJiLk?LyKMre butyMuc?L
ch?LgeitsbrightLessbych?LgiLgther?tiMbetweeLthe
MLtiKe?LdtheMfftiKe
Figure53
shMwshMwthis
UseaLightSensor
Insteadofthe
/Mwwe'regMiLgtMtry?LiLterestiLgexNeriKeLtT?ke?
JightseLsMr JiketheMLeNicturediL
Figure55
:Muc?L
get?fiveN?ckMfthesefrMKR?diMSh?ck(N?rtLuKber
AsyMuJe?rLediLtheNreviMussectiML ArduiLMis?bJetM
detectwhetherthereis?vMJt?ge?NNJiedtMMLeMfitsNiLs
?LdreNMrtitthrMughthe
fuLctiMLThiskiLd
Mfeither/MrresNMLseisfiLeiL?JMtMf?NNJic?tiMLs but
theJightseLsMrth?twejustusedis?bJetMteJJusLMtjust
whetherthereisJight but?JsMhMwKuchJightthereis
ThisisthediffereLcebetweeL?LML/MffseLsMr(which
teJJsuswhethersMKethiLgisthere ?Ld?L?L?JMgue
seLsMr whMsev?JuecMLtiLuMusJych?Lges*LMrdertM
*LtheJMwerrightN?rtMftheArduiLMbM?rd yMu'JJseesix
NiLsK?rked"AL?JMg*L"these?resNeci?JNiLsth?tc?L
teJJusLMtMLJywhetherthereis?vMJt?ge?NNJiedtMtheK
butifsM ?JsMitsv?JueByusiLgthe
fuLctiML wec?Lre?dthevMJt?ge?NNJiedtMMLeMfthe
NiLsThisfuLctiMLreturLs?LuKberbetweeL0?Ld1023
whichreNreseLtsvMJt?gesbetweeL0?Ld5vMJtsFMr
ex?KNJe ifthereis?vMJt?geMf25V?NNJiedtMNiL
*fyMuLMwbuiJdthecircuitth?tyMuseeiL
Figure56
usiLg?10kresistMr ?LdruLthecMdeJistediL
Ex?KNJe53
yMu'JJseetheMLbM?rd-ED(yMucMuJd?JsM
iLsertyMurMwL-EDiLtMNiLs13?LdG/D?sshMwLiL
"BJiLkiLg?L-ED"iL
Ch?Nter4
bJiLkiLg?t?r?teth?t's
TryOtherAnalogue
UsiLgthes?Kecircuitth?tyMuh?veseeLiLtheNreviMus
sectiML yMuc?LcMLLect?JMtMfMtherresistiveseLsMrs
th?twMrkiLKMreMrJessthes?Kew?yFMrex?KNJe yMu
cMuJdcMLLect?therKistMr whichis?siKNJedevice
whMseresist?Lcech?LgeswithteKNer?ture*Lthecircuit
*h?veshMwLyMuhMwch?LgesiLresist?LcebecMKe
*fyMudMwMrkwith?therKistMr be?w?reth?tthereisL't
?directcMLLectiMLbetweeLthev?JueyMure?d?Ldthe
?ctu?JteKNer?tureKe?sured*fyMuLeed?Lex?ct
re?diLg yMushMuJdre?dtheLuKbersth?tcMKeMutMf
the?L?JMgueNiLwhiJeKe?suriLgwith?re?J
therKMKeter:MucMuJdNuttheseLuKberssidebyside
iL?t?bJe?LdwMrkMut?w?ytMc?Jibr?tethe?L?JMgue
ULtiJLMw weh?vejustused?L-ED?s?LMutNutdevice
buthMwdMwere?dthe?ctu?Jv?Juesth?tArduiLMis
re?diLgfrMKtheseLsMr?Wec?L'tK?kethebM?rdbJiLk
thev?JuesiL.MrsecMde(weJJ wecMuJd butthereis?L
e?sierw?yfMrhuK?LstMre?dthev?Jues FMrthis we
c?Lh?veArduiLMt?JktM?cMKNuterMver?seri?JNMrt
:MuJe?rLed?tthebegiLLiLgMfthisbMMkth?tArduiLM
h?s?USBcMLLectiMLth?tisusedbythe*DEtMuNJM?d
cMdeiLtMtheNrMcessMrThegMMdLewsisth?tthis
cMLLectiMLc?L?JsMbeusedbythesketchesth?twewrite
iLArduiLMtMseLdd?t?b?cktMthecMKNuterMrtM
receivecMKK?LdsfrMKitFMrthisNurNMse we?regMiLg
tMuse?seri?JMbject(?LMbjectis?cMJJectiMLMf
c?N?biJitiesth?t?rebuLdJedtMgetherfMrthecMLveLieLce
ThisMbjectcMLt?iLs?JJthecMdeth?tweLeedtMseLd?Ld
received?t?We'reLMwgMiLgtMusetheJ?stcircuitwe
buiJtwiththeNhMtMresistMr?LdseLdthev?Juesth?t?re
re?db?cktMthecMKNuterTyNethiscMdeiLtM?Lew
sketch(yMuc?L?JsMdMwLJM?dthecMdefrMK
Example5-5.Sendtothecomputerthevalues
readfromanalogueinput0Makesureyouclick
DrivingBiggerLoads
(Motors,Lamps,andthe
E?chMLeMftheNiLsML?LArduiLMbM?rdc?LbeusedtM
NMwerdevicesth?tuseuNtM20KiJJi?KNsthisis?very
sK?JJ?KMuLtMfcurreLt justeLMughtMdrive?L-ED*f
yMutrytMdrivesMKethiLgJike?KMtMr theNiLwiJJ
iKKedi?teJystMNwMrkiLg ?LdcMuJdNMteLti?JJyburLMut
thewhMJeNrMcessMrTMdrivebiggerJM?dsJikeKMtMrsMr
iLc?LdesceLtJ?KNs weLeedtMuse?LexterL?J
cMKNMLeLtth?tc?LswitchsuchthiLgsML?LdMff?Ldth?t
isdriveLby?LArduiLMNiLOLesuchdeviceisc?JJed?
.OSFETtr?LsistMr—igLMrethefuLLyL?Ke—it's?L
eJectrMLicswitchth?tc?LbedriveLby?NNJyiLg?vMJt?ge
tMMLeMfitsthreeNiLs e?chMfwhichisc?JJed?
*tis
sMKethiLgJiketheJightswitchth?tweuse?thMKe
wherethe?ctiMLMf?fiLgerturLiLgtheJightML?LdMffis
reNJ?cedby?NiLMLtheArduiLMbM?rdseLdiLgvMJt?getM
"Ket?J–Mxide–seKicMLductMrfieJdeffect
tr?LsistMr"*t's?sNeci?JtyNeMftr?LsistMr
WedefiLecMKNJexseLsMrs?sthMseth?tNrMduce?tyNe
MfiLfMrK?tiMLth?treOuires?bitKMreth?L?
Mr?L
fuLctiMLtMbeused
Theseusu?JJy?resK?JJcircuitswith?sK?JJ
SMKeMfthecMKNJexseLsMrs?v?iJ?bJeiLcJudeuJtr?sMLic
r?Lgers iLfr?redr?Lgers ?Ld?cceJerMKeter:Muc?L
fiLdex?KNJesMLhMwtMusetheKMLMurwebsiteiLthe
"TutMri?Js"sectiML(
www?rduiLMcc/eL/TutMri?J/
TMK*gMe's
MakingThingsTalk
(O'ReiJJy h?sexteLsive
cMver?geMftheseseLsMrs?LdK?LyMthercMKNJex
Chapter6.Talkingto
*LtheNrecediLgch?Nters yMuJe?rLedtheb?sicsMf
ArduiLM?LdthefuLd?KeLt?JbuiJdiLgbJMcks?v?iJ?bJetM
yMu-etKereKiLdyMuwh?tK?kesuNthe"ArduiLM
WeusedittMcMLtrMJ?L-EDbut withtheNrMNercircuit
itc?LbeusedtMcMLtrMJKMtMrs K?kesMuLds ?Ld?JMt
Thisgivesusthe?biJitytMcMLtrMJthebrightLessMfthe
-ED LMtjustturLitMLMrMffWec?LeveLcMLtrMJthe
This?JJMwsustMre?dthest?teMfsiKNJeseLsMrs Jike
Wec?Lre?dsigL?JsfrMKseLsMrsth?tseLd?cMLtiLuMus
sigL?Jth?t'sLMtjustMLMrMff such?s?NMteLtiMKeterMr
This?JJMwsustMcMKKuLic?tewith?cMKNuter?Ld
exch?Lged?t?MrsiKNJyKMLitMrwh?t'sgMiLgMLwiththe
*Lthisch?Nter we'regMiLgtMseehMwtMNuttMgether?
wMrkiLg?NNJic?tiMLusiLgwh?tyMuh?veJe?rLediLthe
NreviMusch?NtersThisch?NtershMuJdshMwyMuhMw
everysiLgJeex?KNJec?Lbeused?s?buiJdiLgbJMckfMr
Hereiswherethew?LL?bedesigLeriLKecMKesMut
We'regMiLgtMK?kethetweLtyfirstceLturyversiMLMf?
cJ?ssicJ?KNbyKyf?vMurite*t?Ji?LdesigLer +Me
CMJMKbMTheMbjectwe'regMiLgtMbuiJdisiLsNiredby?
J?KN c?JJed "AtML" frMK 164
-et'sJMMk?twh?twew?LttM?chieve?Ldwh?tbits?Ld
NiecesweLeedFirstMf?JJ weLeedArduiLMtMbe?bJetM
cMLLecttMthe*LterLetAstheArduiLMbM?rdh?sMLJy?
USBNMrt wec?L'tNJugitdirectJyiLtM?L*LterLet
cMLLectiML sMweLeedtMfigureMuthMwtMbridgethe
twMUsu?JJywh?tNeMNJedMisruL?L?NNJic?tiMLML?
cMKNuterth?twiJJcMLLecttMthe*LterLet NrMcessthe
d?t? ?LdseLdArduiLMsMKesiKNJebitMfdistiJJed
ArduiLMis?siKNJecMKNuterwith?sK?JJKeKMryit
c?L'tNrMcessJ?rgefiJese?siJy ?LdwheLwecMLLecttM?L
RSSfeedwe'JJget?veryverbMseX.-fiJeth?twMuJd
reOuire?JMtKMreRA.We'JJiKNJeKeLt?NrMxytM
siKNJify the X.- usiLg thePrMcessiLg J?Lgu?ge
PrMcessiLgiswhereArduiLMc?KefrMKWe
JMvethisJ?Lgu?ge?LduseittMte?ch
NrMgr?KKiLgtMbegiLLers?sweJJ?stMbuiJd
be?utifuJcMdePrMcessiLg?LdArduiLM?rethe
NerfectcMKbiL?tiMLALMther?dv?Lt?geisth?t
PrMcessiLgisMNeLsMurce?LdruLsML?JJthe
K?jMrNJ?tfMrKs(.?c -iLux ?LdWiLdMws *t
c?L?JsMgeLer?test?Ld?JMLe?NNJic?tiMLsth?t
ruLMLthMseNJ?tfMrKsWh?t'sKMre the
There?retwMsketchesth?tyMu'JJberuLLiLgMLe
PrMcessiLgsketch ?LdMLeArduiLMsketchHereisthe
cMdefMrthePrMcessiLgsketch:Muc?LdMwLJM?ditfrMK
Figure62
shMwshMwtM?sseKbJethecircuit:MuLeed
tMuse10,resistMrsfMr?JJMftheresistMrsshMwLiLthe
di?gr?K ?JthMughyMucMuJdget?w?ywithJMwerv?Jues
ReKeKberfrMKthePW.ex?KNJeiL
Ch?Nter5
-EDs?reNMJ?rizediLthiscircuit theJMLgNiL(NMsitive
shMuJdgMtMtheright ?LdtheshMrtNiL(Leg?tive tMthe
Jeft(.Mst-EDsh?ve?fJ?tteLedLeg?tiveside ?sshMwL
Here'sHowtoAssemble
ULN?cktheJ?KN?LdreKMvethec?bJeth?tgMesiLtMthe
J?KNfrMKthebMttMK:MuwiJJLMJMLgerbeNJuggiLg
Str?NtheArduiLMML?bre?dbM?rd?LdhMtgJuethe
SMJderJMLgerwirestMtheRGB-ED?LdgJueitwhere
theJightbuJbusedtMbeCMLLectthewirescMKiLgfrMK
the-EDtMthebre?dbM?rd(whereitw?scMLLected
befMreyMureKMvedit ReKeKberth?tyMuwiJJMLJy
LeedMLecMLLectiMLtMgrMuLdifyMu?reusiLg?4Je?d
EitherfiLd?LiceNieceMfwMMdwith?hMJeth?tc?Lbe
used?s?st?LdfMrthesNhereMrjustcutthetMNMfthe
c?rdbM?rdbMxth?tc?KewiththeJ?KN?t?NNrMxiK?teJy
5cK(Mr2" ?LdK?ke?hMJewith?di?Keterth?tcr?dJes
theJ?KNReiLfMrcetheiLsideMfthec?rdbM?rdbMxby
usiLghMtgJue?JJ?JMLgtheiLsideedges whichwiJJK?ke
PJ?cethesNhereMLthest?Ld?LdbriLgtheUSBc?bJeMut
Trying Out Other On/Off Sensors
Switches
Thermostats
TheALcieLtRMK?LsusedtMs?y
WhiJeiLvestig?tiLg teste?chcMKNMLeLtseN?r?teJysM
th?tyMuc?Lbe?bsMJuteJycert?iLth?te?chMLewMrksby
itseJf:MuwiJJgr?du?JJybuiJduNcMLfideLce?bMut
whichN?rtsMfNrMject?redMiLgtheirjMb?LdwhichMLes
istheterKusedtMdescribethisNrMcess?s
?NNJiedtMsMftw?reTheJegeLds?ysitw?susedfMrthe
firsttiKebyGr?ceHMNNerb?ckiLthe140s wheL
cMKNuterswhereKMstJyeJectrMKech?Lic?J ?LdMLeMf
theKstMNNedwMrkiLgbec?use?ctu?JiLsectsgMtc?ught
.?LyMftMd?y'sbugs?reLMtNhysic?J?LyKMrethey're
virtu?J?LdiLvisibJe ?tJe?stiLN?rtTherefMrethey
reOuire?sMKetiKesJeLgthy?LdbMriLgNrMcesstMbe
Wh?tiftheveryfirstex?KNJe "bJiLk?L-ED "didL't
wMrk?WMuJdL'tth?tbe?bitdeNressiLg?-et'sfigureMut
BefMreyMust?rtbJ?KiLgyMurNrMject yMushMuJdK?ke
sureth?t?fewthiLgs?reiLMrder ?s?irJiLeNiJMtsdM
wheLtheygMthrMugh?checkJisttMK?kesureth?tthe
PJug yMurArduiLM iLtM ? USB NJug ML yMur cMKNuter
_.?kesurethecMKNuterisML(yes itsMuLds
siJJy butith?sh?NNeLed *fthegreeLJight
K?rkedPWRturLsML thisKe?Lsth?tthe
cMKNuterisNMweriLgthebM?rd*fthe-ED
seeKsveryf?iLt sMKethiLgiswrMLgwiththe
NMwertry?differeLtUSBc?bJe?LdiLsNectthe
cMKNuter'sUSBNMrt?LdtheArduiLM'sUSBNJug
tMseewhetherthereis?Lyd?K?ge*f?JJeJse
f?iJs try?differeLtUSBNMrtMLyMurcMKNuter
_*ftheArduiLMisbr?LdLew theyeJJMw-ED
K?rked-wiJJst?rtbJiLkiLgiL?bitMf?LervMus
N?tterLthisisthetestNrMgr?Kth?tw?sJM?ded?t
/MwcMLLectthebM?rdtMyMurbre?dbM?rdbyruLLiLg?
juKNerfrMKthe5V?LdG/DcMLLectiMLstMtheNMsitive
?LdLeg?tiver?iJsMfthebre?dbM?rd*fthegreeLPWR
-EDturLsMff reKMvethewiresiKKedi?teJyThis
Ke?Lsthereis?bigKist?keiLyMurcircuit?LdyMuh?ve
?"shMrtcircuit"sMKewhereWheLthish?NNeLs yMur
bM?rddr?wstMMKuchcurreLt?LdtheNMwergetscutMff
*fyMu're?cMLcerLedth?tyMuK?yd?K?ge
yMurcMKNuter reKeKberth?tMLK?Ly
cMKNuters thecurreLtNrMtectiMLis
usu?JJyOuitegMMd?LdresNMLdsOuickJy
AJsM theArduiLMbM?rdisfittedwith?
"PMJyFuse "?curreLtNrMtectiMLdevice
*fyMu'rere?JJyN?r?LMid yMuc?L?Jw?ys
cMLLecttheArduiLMbM?rdthrMugh?
seJfNMweredUSBhub*Lthisc?se ifit
?JJgMeshMrribJywrMLg theUSBhubis
ALMtheriKNMrt?LtruJeistMfiLd?reJi?bJew?ytM
reNrMduce?NrMbJeK*fyMurcircuitbeh?vesiL?fuLLy
w?y?tr?LdMKtiKes tryre?JJyh?rdtMfigureMutthe
ex?ctKMKeLttheNrMbJeKMccurs?Ldwh?tisc?usiLgit
ThisNrMcesswiJJ?JJMwyMutMthiLk?bMut?NMssibJe
c?use*tis?JsMveryusefuJwheLyMuLeedtMexNJ?iLtM
DescribiLgtheNrMbJeK?sNreciseJy?sNMssibJeis?JsM?
gMMdw?ytMfiLd?sMJutiMLTrytMfiLdsMKebMdytM
exNJ?iLtheNrMbJeKtM—iLK?Lyc?ses ?sMJutiMLwiJJ
NMNiLtMyMurhe?d?syMu?rticuJ?tetheNrMbJeKBri?L
W,erLigh?L?LdRMbPike iL
ThePracticeof
(AddisMLWesJey 1 teJJthestMryMf
MLeuLiversityth?t"keNt?teddybe?rLe?rtheheJNdesk
StudeLtswithKysteriMusbugswerereOuiredtMexNJ?iL
theKtMthebe?rbefMretheycMuJdsNe?ktM?huK?L
*LsMKec?ses yMuK?yh?ve?NrMbJeKusiLgthe
ArduiLM*DE N?rticuJ?rJy MLWiLdMws
*fyMuget?LerrMrwheLyMudMubJecJickMLtheArduiLM
icML MrifLMthiLgh?NNeLs trydMubJecJickiLgthe
WiLdMwsusersK?y?JsMruLiLtM?NrMbJeKifthe
MNer?tiLgsysteK?ssigLs?CO.NMrtLuKberMfCO.10
Mrgre?tertMArduiLM*fthish?NNeLs yMuc?Lusu?JJy
cMLviLceWiLdMwstM?ssigL?JMwerNMrtLuKbertM
ArduiLMFirst MNeLuNtheDevice.?L?gerbycJickiLg
theSt?rtKeLu rightcJickiLgMLCMKNuter(Vist? Mr.y
CMKNuter(XP ?LdchMMsiLgPrMNertiesOLWiLdMws
XP cJickH?rdw?re?LdchMMseDevice.?L?gerOL
Vist? cJickMLDevice.?L?ger(it?NNe?rsiLtheJistMf
-MMkfMrtheseri?JdevicesiLtheJistuLder"PMrts(CO.
&-PT "FiLd?seri?Jdeviceth?tyMu'reLMtusiLgth?tis
LuKberedCO.MrJMwerRightcJickit?LdchMMse
PrMNertiesfrMKtheKeLuTheL chMMsethePMrtSettiLgs
t?b?LdcJickAdv?LcedSettheCO.NMrtLuKbertM
CO.10Mrhigher cJickO,?LdcJickO,?g?iLtM
AppendixA.The
TheNrMcessMfgettiLg?circuittMwMrkiLvMJvesK?kiLg
JMtsMfch?LgestMituLtiJitbeh?vesNrMNerJyit's?very
f?st iter?tiveNrMcessth?t'ssMKethiLgJike?LeJectrMLic
eOuiv?JeLttMsketchiLgThedesigLevMJvesiLyMurh?Lds
?syMutrydiffereLtcMKbiL?tiMLsFMrthebestresuJts use
?systeKth?t?JJMwsyMutMch?LgethecMLLectiMLs
betweeLcMKNMLeLtsiLthef?stest KMstNr?ctic?J ?Ld
Je?stdestructivew?yThesereOuireKeLtscJe?rJyruJeMut
sMJderiLg whichis?tiKecMLsuKiLgNrMcedureth?tNuts
cMKNMLeLtsuLderstresseverytiKeyMuhe?ttheKuN?Ld
The?LswertMthisNrMbJeKis?veryNr?ctic?Jdevice
c?JJedthesMJderJessbre?dbM?rdAsyMuc?LseefrMK
FigureA1
it's?sK?JJNJ?sticbM?rdfuJJMfhMJes e?chMf
whichcMLt?iLs?sNriLgJM?dedcMLt?ct:Muc?LNush?
cMKNMLeLt'sJegiLtMMLeMfthehMJes ?LditwiJJest?bJish
?LeJectric?JcMLLectiMLwith?JJMftheMtherhMJesiLthe
s?Kevertic?JcMJuKLMfhMJesE?chhMJeis?dist?LceMf
Bec?useKMstMfthecMKNMLeLtsh?vetheirJegs(kLMwL
tMtechies?s"NiLs" sN?ced?tth?tst?Ld?rddist?Lce
chiNswithKuJtiNJeJegsfitLiceJy/Mt?JJMfthecMLt?cts
ML?bre?dbM?rd?recre?tedeOu?J—there?resMKe
AppendixB.Reading
*LMrdertMuseeJectrMLicN?rts yMuLeedtMbe?bJetM
ideLtifytheK whichc?Lbe?difficuJtt?skfMr?begiLLer
.MstMftheresistMrsth?tyMufiLdiL?shMNh?ve?
cyJiLdric?JbMdywithtwMJegsstickiLgMut?Ldh?ve
str?LgecMJMuredK?rkiLgs?JJ?rMuLdtheKWheLthe
firstcMKKerci?JresistMrswereK?de therew?sLMw?ytM
NriLtLuKberssK?JJeLMughtMfitMLtheirbMdy sMcJever
eLgiLeersdecidedth?ttheycMuJdjustreNreseLtthev?Jues
TMd?y'sbegiLLersh?vetMfigureMut?w?ytMiLterNret
thesesigLsThe"key"isOuitesiKNJegeLer?JJy there?re
fMurstriNes ?Lde?chcMJMurreNreseLts?LuKberOLeMf
riLgsisusu?JJygMJdcMJMuredthisMLereNreseLtsthe
NrecisiMLMfth?tresistMrTMre?dthestriNesiLMrder hMJd
theresistMrsMthegMJd(MrsiJveriLsMKec?ses striNeis
tMtherightTheL re?dthecMJMurs?LdK?NtheKtMthe
cMrresNMLdiLgLuKbers*LthefMJJMwiLgt?bJe yMu'JJfiLd
?tr?LsJ?tiMLbetweeLthecMJMurs?LdtheirLuKeric
AppendixC.Arduino
Hereis?OuickexNJ?L?tiMLMf?JJthest?Ld?rd
FMr?KMredet?iJedrefereLce see
?rduiLMcc/eL/
Understanding
Understanding
Simplification and segmentation
Testing the Board
ArduiLMiLcJudes?LuKberMfsyKbMJstMdeJiLe?teJiLes
EveryiLstructiML(JiLeMfcMde isterKiL?tedby?
seKicMJMLThissyLt?xJetsyMufMrK?tthecMdefreeJy
:MucMuJdeveLNuttwMiLstructiMLsMLthes?KeJiLe ?s
JMLg?syMuseN?r?tetheKwith?seKicMJML(HMwever
ThisisusedtMK?rkbJMcksMfcMdeFMrex?KNJe wheL
yMuwritecMdefMrthe
fuLctiML yMuh?vetMuse
These?reNMrtiMLsMftextigLMredbytheArduiLM
NrMcessMr but?reextreKeJyusefuJtMreKiLdyMurseJf(Mr
There ?re twM styJes MfcMKKeLts iL ArduiLM
//single-line: this text is ignored until the end of the line
/*multiple-line:
ArduiLMiLcJudes?setMfNredefiLedkeywMrdswith
sNeci?Jv?JuesH*GH?Ld-OW?reused fMrex?KNJe
wheLyMuw?LttMturLMLMrMff?LArduiLMNiL*/PUT
?LdOUTPUT?reusedtMset?sNecificNiLtMbeeither
true?Ldf?JseiLdic?teex?ctJywh?ttheirL?Kessuggest
V?ri?bJes?reL?Ked?re?sMftheArduiLM'sKeKMry
whereyMuc?LstMred?t?th?tyMuc?Luse?LdK?LiNuJ?te
iLyMursketchAstheL?Kesuggests theyc?Lbe
Bec?useArduiLMis?verysiKNJeNrMcessMr wheLyMu
decJ?re?v?ri?bJeyMuh?vetMsNecifyitstyNeThis
Ke?LsteJJiLgtheNrMcessMrthesizeMfthev?JueyMuw?Lt
HMJds?siLgJech?r?cter such?sA-ike?LycMKNuter
ArduiLMstMresit?s?LuKber eveLthMughyMuseetext
WheLch?rs?reusedtMstMreLuKbers theyc?LhMJd
There?retwMK?jMrsetsMfch?r?cters
?v?iJ?bJeMLcMKNutersysteKsASC**?Ld
U/*CODEASC**is?setMf127
ch?r?ctersth?tw?susedfMr ?KMLgMther
thiLgs tr?LsKittiLgtextbetweeLseri?J
terKiL?Js?LdtiKesh?redcMKNuter
systeKssuch?sK?iLfr?Kes?Ld
KiLicMKNutersU/*CODEis?Kuch
J?rgersetMfv?JuesusedbyKMderL
cMKNuterMNer?tiLgsysteKstMreNreseLt
ch?r?ctersiL?wider?LgeMfJ?Lgu?ges
ASC**isstiJJusefuJfMrexch?LgiLgshMrt
bitsMfiLfMrK?tiMLiLJ?Lgu?gessuch?s
*t?Ji?LMrELgJishth?tuse-?tiLch?r?cters
Ar?bicLuKer?Js ?LdcMKKMLtyNewriter
syKbMJs fMr NuLctu?tiML ?Ld the Jike
HMJds?LuKberbetweeL0?Ld255Aswithch?rs bytes
Uses2bytesMfKeKMrytMreNreseLt?LuKberbetweeL
–32 768?Ld32 767it'stheKMstcMKKMLd?t?tyNeused
-ikeiLt uses2bytesbuttheuLsigLedNrefixKe?Lsth?t
itc?L'tstMreLeg?tiveLuKbers sMitsr?LgegMesfrMK0tM
ThisistwicethesizeMf?LiLt?LdhMJdsLuKbersfrMK
ULsigLedversiMLMfJMLgitgMesfrMK0tM
ThisOuitebig?Ldc?LhMJdfJM?tiLgNMiLtv?Jues ?f?Lcy
w?yMfs?yiLgth?tyMuc?LuseittMstMreLuKberswith?
deciK?JNMiLtiLit*twiJJe?tuN4bytesMfyMurNreciMus
RA.?LdthefuLctiMLsth?tc?Lh?LdJetheKuseuN?JMt
Mf cMde KeKMry ?s weJJ SM usefJM?tssN?riLgJy
DMubJeNrecisiMLfJM?tiLgNMiLtLuKber with?K?xiKuK
AsetMfASC**ch?r?ctersth?t?reusedtMstMretextu?J
iLfMrK?tiML(yMuKightuse?striLgtMseLd?Kess?gevi?
?seri?JNMrt MrtMdisNJ?yML?L-CDdisNJ?y FMr
stMr?ge theyuseMLebytefMre?chch?r?cteriLthestriLg
NJus?LuJJch?r?ctertMteJJArduiLMth?tit'stheeLdMfthe
AJistMfv?ri?bJesth?tc?Lbe?ccessedvi??LiLdexThey
?reusedtMbuiJdt?bJesMfv?Juesth?tc?Le?siJybe
?ccessedFMrex?KNJe ifyMuw?LttMstMrediffereLt
JeveJsMfbrightLesstMbeusedwheLf?diLg?L-ED yMu
cMuJdcre?tesixv?ri?bJesc?JJedJight01 Jight02 ?LdsM
ThewMrd"?rr?y"isLMt?ctu?JJyusediLthev?ri?bJe
ArduiLMiLcJudeskeywMrdsfMrcMLtrMJJiLgtheJMgic?J
ThisstructureK?kesdecisiMLsiLyMurNrMgr?K
befMJJMwedby?OuestiMLsNecified?s?LexNressiML
cMLt?iLediLN?reLtheses*ftheexNressiMListrue
wh?teverfMJJMwswiJJbeexecuted*fit'sf?Jse thebJMck
MfcMdefMJJMwiLgeJsewiJJbeexecuted*t'sNMssibJetM
-etsyMureNe?t?bJMckMfcMde?sNecifiedLuKberMf
st?teKeLtisJike?fMrkiLtherM?dfMryMur
c?seisJike?K?ssiverMuLd?bMut*tJets
yMurNrMgr?Kt?ke?v?rietyMfdirectiMLsdeNeLdiLgML
thev?JueMf?v?ri?bJe*t'sOuiteusefuJtMkeeNyMurcMde
SiKiJ?rtM
thisexecutes?bJMckMfcMdewhiJe?cert?iL
+ustJike
exceNtth?tthecMdeisruLjustbefMrethe
thecMLditiMLisev?Ju?tedThisstructureisusedwheL
yMuw?LtthecMdeiLsideyMurbJMcktMruL?tJe?stMLce
ThisterKJetsyMuJe?ve?JMMN?LdcMLtiLuethe
executiMLMfthecMdeth?t?NNe?rs?ftertheJMMN*t's?JsM
usedtMseN?r?tethediffereLtsectiMLsMf?
WheLusediLside?JMMN
JetsyMuskiNtherest
MfthecMdeiLsideit?LdfMrcethecMLditiMLtMbetested
WheLyMusNecifycMLditiMLsMrtestsfMr
if,while
?Ld
st?teKeLts these ?re theMNer?tMrs yMu c?L use
STRUCTURE
SPECIAL SYMBOLS
; (semicolon)
CONSTANTS
boolean
CONTROL STRUCTURES
if É else
These?reusedwheLyMuw?LttMcMKbiLeKuJtiNJe
cMLditiMLsFMrex?KNJe ifyMuw?LttMcheckwhether
thev?JuecMKiLgfrMK?seLsMrisbetweeL5?Ld10 yMu
�if ((sensor = 5)&& (sensor =10))
There?rethreeMNer?tMrs?Ld reNreseLtedwith&&Mr
reNreseLted withZZ ?Ld fiL?JJy LMt reNreseLted with!
These?resNeci?JMNer?tMrsusedtMK?kecMdeKMre
cMLcisefMrsMKeverycMKKMLMNer?tiMLsJike
but usiLg ?cMKNMuLd MNer?tMr this becMKes
incrementanddecrement
TheseiLcreKeLtMrdecreKeLt?v?Jueby1Bec?refuJ
thMugh*fyMuwrite
thisiLcreKeLts
by1?Ld
ev?Ju?testMtheeOuiv?JeLtMf

ev?Ju?testMthe
theLiLcreKeLts
TheseK?keitshMrtertMwritecert?iLexNressiMLsThe
INPUTANDOUTPUT
ArduiLMiLcJudesfuLctiMLsfMrh?LdJiLgiLNut?LdMutNut
:Mu've?Jre?dyseeLsMKeMftheseiLtheex?KNJe
RecMLfigures?digit?JNiLtMbeh?veeither?s?LiLNutMr
pinMode(7,INPUT); // turns pin 7into an input
TurLs?digit?JNiLeitherMLMrMffPiLsKustbeexNJicitJy
K?deiLtM?LMutNutusiLg
Re?dsthest?teMf?LiLNutNiL returLsH*GHiftheNiL
seLsessMKevMJt?geMr-OWifthereisLMvMJt?ge
Re?dsthevMJt?ge?NNJiedtM?L?L?JMgiLNutNiL?Ld
returLs?LuKberbetweeL0?Ld1023th?treNreseLtsthe
val =analogRead(0); // reads analog input 0into val
Ch?LgesthePW.r?teMLMLeMftheNiLsK?rkedPW.
K?ybe11 10  6 5 3
K?ybe?LuKber
betweeL0?Ld255th?treNreseLtsthesc?JebetweeL0
shiftOut(dataPin,clockPin,
SeLdsd?t?tM?
shiftregister
devicesth?t?reusedtM
exN?LdtheLuKberMfdigit?JMutNutsThisNrMtMcMJuses
MLeNiLfMrd?t??LdMLefMrcJMck
iLdic?testhe
MrderiLgMfbytes(Je?stsigLific?LtMrKMstsigLific?Lt
unsignedlongpulseIn(pin,
.e?suresthedur?tiMLMf?NuJsecMKiLgiLMLMLeMfthe
digit?JiLNutsThisisusefuJ fMrex?KNJe tMre?dsMKe
iLfr?redseLsMrsMr?cceJerMKetersth?tMutNuttheirv?Jue
time = pulsein(7,HIGH); // measures thetime the next
ArduiLMiLcJudesfuLctiMLsfMrKe?suriLgeJ?NsedtiKe
ReturLstheLuKberMfKiJJisecMLdsth?th?veN?ssed
P?usestheNrMgr?KfMrthe?KMuLtMfKiJJisecMLds
P?usestheNrMgr?KfMrthegiveL?KMuLtMf
ArduiLMiLcJudesK?LycMKKMLK?theK?tic?J?Ld
trigMLMKetricfuLctiMLs
val =min(10,20); // val is now 10
val =max(10,20); // val is now 20
ReturLsthe?bsMJutev?JueMf
whichturLsLeg?tive
LuKbersiLtMNMsitive*f
is5itwiJJreturL5 butif
ReturLsthev?JueMf
cMLstr?iLedbetweeL??Ldb*f
isJessth?L
itwiJJjustreturL??Ldif
isgre?terth?L
map(value,fromLow,
.?Ns?v?JueiLther?Lge
tMthe
VeryusefuJtMNrMcessv?Jues
val =map(analogRead(0),0,1023,100, 200); // maps the value of
ReturLstheresuJtMfr?isiLg?LuKber(
tM?v?Jue
double sqrt(x)
double a = sqrt(1138); // approximately 33.73425674438
double sin(rad)
double sine = sin(2); // approximately 0.90929737091
ReturLs thecMsiLe Mf ?L ?LgJe sNecified iL r?di?Ls
ReturLs thet?LgeLt Mf ?L ?LgJe sNecified iL r?di?Ls
map(value,fromLow,fromHigh,toLow,
RANDOMNUMBER
*fyMuLeedtMgeLer?ter?LdMKLuKbers yMuc?Luse
ArduiLM'sNseudMr?LdMK LuKber geLer?tMr
ResetsArduiLM'sNseudMr?LdMKLuKbergeLer?tMr
AJthMughthedistributiMLMftheLuKbersreturLedby
isesseLti?JJyr?LdMK theseOueLceis
Nredict?bJeSM yMushMuJdresetthegeLer?tMrtMsMKe
r?LdMKv?Jue*fyMuh?ve?LuLcMLLected?L?JMgNiL it
wiJJNickuNr?LdMKLMisefrMKthesurrMuLdiLg
eLvirMLKeLt(r?diMw?ves cMsKicr?ys eJectrMK?gLetic
iLterfereLcefrMKceJJNhMLes?LdfJuMresceLtJights ?Ld
longrandom(max)long
ReturLs?NseudMr?LdMK
iLtegerv?JuebetweeL
AsyMus?wiL
Ch?Nter5
yMuc?LcMKKuLic?tewith
devicesMvertheUSBNMrtusiLg?seri?JcMKKuLic?tiML
NrMtMcMJ Here ?re the seri?JfuLctiMLs
PreN?resArduiLMtMbegiLseLdiLg?LdreceiviLgseri?J
d?t?:Mu'JJgeLer?JJyuse600bitsNersecMLd(bNs with
theArduiLM*DEseri?JKMLitMr butMthersNeeds?re
SeLdssMKed?t?tMtheseri?JNMrtTheeLcMdiLgis
MNtiML?JifLMtsuNNJied thed?t?istre?ted?sKuchJike
S?Ke?s
exceNtth?tit?dds?c?rri?ge
returL?LdJiLefeed(
?sifyMuh?dtyNedthed?t??Ld
ReturLshMwK?LyuLre?dbytes?re?v?iJ?bJeMLthe
Seri?JNMrtfMrre?diLgvi?the
fuLctiMLAfteryMu
everythiLg?v?iJ?bJe
int Serial.read()
int data = Serial.read();
Bec?used?t?K?y?rrivethrMughtheseri?JNMrtf?ster
th?LyMurNrMgr?Kc?LNrMcessit ArduiLMkeeNs?JJthe
iLcMKiLgd?t?iL?buffer*fyMuLeedtMcJe?rthebuffer
AppendixD.Reading
SMf?r weh?veusedverydet?iJediJJustr?tiMLstM
describehMwtM?sseKbJeMurcircuits but?syMuc?L
iK?giLe it'sLMtex?ctJy?Ouickt?sktMdr?wMLeMfthMse
SiKiJ?rissues?rise sMMLerMrJ?ter iLeverydisciNJiLe*L
Kusic ?fteryMuwrite?LicesMLg yMuLeedtMwriteit
ELgiLeers beiLgNr?ctic?JNeMNJe h?vedeveJMNed?Ouick
w?ytMc?NturetheesseLceMf?circuitiLMrdertMbe?bJe
tMdMcuKeLtit?LdJ?terrebuiJditMrN?ssittMsMKebMdy
*LeJectrMLics
schematicdiagrams
?JJMwyMutMdescribe
yMurcircuitiL?w?yth?tisuLderstMMdbytherestMfthe
cMKKuLity*Ldividu?JcMKNMLeLts?rereNreseLtedby
syKbMJsth?t?re?sMrtMf?bstr?ctiMLMfeitherthesh?Ne
MfthecMKNMLeLtMrtheesseLceMftheKFMrex?KNJe
thec?N?citMrisK?deMftwMKet?JNJ?tesseN?r?tedby
Serial.println(data)Serial.println(data,
Afewye?rs?gM*w?sgiveL?veryiLterestiLgch?JJeLge
te?chdesigLerstheb?reKiLiKuKiLeJectrMLicssMth?t
theycMuJdbuiJdiLter?ctiveNrMtMtyNesMftheMbjectsthey
*st?rtedfMJJMwiLg?subcMLsciMusiLstiLcttMte?ch
eJectrMLicsthes?Kew?y*w?st?ughtiLschMMJ-?terML
*re?Jisedth?titsiKNJyw?sL'twMrkiLg?sweJJ?s*wMuJd
Jike ?Ldst?rtedtMreKeKbersittiLgiL?cJ?ss bMredJike
heJJ JisteLiLgtM?JJth?ttheMrybeiLgthrMwL?tKe
*Lre?Jity wheL*w?siLschMMJ*?Jre?dykLew
eJectrMLicsiL?veryeKNiric?Jw?yveryJittJetheMry but
*st?rtedthiLkiLg?bMuttheNrMcessbywhich*re?JJy
_*tMMk?N?rt?LyeJectrMLicdevice*cMuJdNutKy
_* sJMwJy Je?rLed wh?t ?JJ thMse cMKNMLeLts were
_*beg?LtMtiLkerwiththeK ch?LgiLgsMKeMfthe
cMLLectiMLsiLsideMftheK?LdseeiLgwh?t
h?NNeLedtMthedeviceusu?JJysMKethiLg
_*st?rtedbuiJdiLgsMKekitssMJdbyeJectrMLics
_*cMKbiLeddevices*h?dh?cked ?LdreNurNMsed
kits?LdMthercircuitsth?t*fMuLdiLK?g?ziLes
As?JittJekid *w?s?Jw?ysf?sciL?tedbydiscMveriLg
hMwthiLgswMrktherefMre *usedtMt?ketheK?N?rt
ThisN?ssiMLgrew?s*t?rgeted?LyuLusedMbjectiLthe
hMuse?LdtheLtMMkit?N?rtiLtMsK?JJbitsEveLtu?JJy
NeMNJebrMught?JJsMrtsMfdevicesfMrKetMdissect.y
biggestNrMjects?tthetiKewere?dishw?sher?Ld?L
e?rJycMKNuterth?tc?KefrMK?LiLsur?LceMffice which
h?d?hugeNriLter eJectrMLicsc?rds K?gLeticc?rd
re?ders ?LdK?LyMtherN?rtsth?tNrMvedveryiLterestiLg
AfterOuite?JMtMfthisdissectiLg *kLewwh?teJectrMLic
cMKNMLeLtswere?LdrMughJywh?ttheydidOLtMNMf
th?t KyhMusew?sfuJJMfMJdeJectrMLicsK?g?ziLesth?t
Kyf?therKusth?vebMught?tthebegiLLiLgMfthe
170s*sNeLthMursre?diLgthe?rticJes?LdJMMkiLg?t
ThisNrMcessMfre?diLgthe?rticJesMver?LdMver with
thebeLefitMfkLMwJedge?cOuiredwhiJet?kiLg?N?rt
Agre?tbre?kthrMughc?KeMLeChristK?s wheLKyd?d
g?veKe?kitth?t?JJMwedteeL?gerstMJe?rL?bMut
eJectrMLicsEverycMKNMLeLtw?shMusediL?NJ?stic
cubeth?twMuJdK?gLetic?JJysL?NtMgetherwithMther
cubes est?bJishiLg?cMLLectiMLtheeJectrMLicsyKbMJ
w?swritteLMLtMN-ittJedid*kLMwth?tthetMyw?s?JsM
?J?LdK?rkMfGerK?LdesigL bec?useDieterR?Ks
WiththisLewtMMJ *cMuJdOuickJyNuttMgethercircuits
?LdtrytheKMuttMseewh?th?NNeLedTheNrMtMtyNiLg
Afterth?t *buiJtr?diMs ?KNJifiers circuitsth?twMuJd
NrMducehMrribJeLMises?LdLicesMuLds r?iLseLsMrs ?Ld
*'vesNeLt?JMLgtiKeJMMkiLgfMr?LELgJishwMrdth?t
wMuJdsuKuNth?tw?yMfwMrkiLgwithMut?sNecific
NJ?L st?rtiLgwithMLeide??LdeLdiLguNwith?
cMKNJeteJyuLexNectedresuJtFiL?JJy "tiLkeriLg"c?Ke
?JMLg*recMgLisedhMwthiswMrdh?sbeeLusediLK?Ly
MtherfieJdstMdescribe?w?yMfMNer?tiLg?LdtMNMrtr?y
NeMNJewhMsetMutML?N?thMfexNJMr?tiMLFMrex?KNJe
thegeLer?tiMLMfFreLchdirectMrswhMg?vebirthtMthe
"/MuveJJeV?gue"werec?JJedthe"tiLkerers"Thebest
defiLitiMLMftiLkeriLgth?t*'veeverfMuLdcMKesfrMK?L
andcuriosity.Whenyoutinker,thereareno
instructionsÑbuttherearealsonofailures,norightor
wrongwaysofdoingthings.It'saboutfiguringouthow
Contraptions,machines,wildlymismatchedobjects
Tinkeringis,atitsmostbasic,aprocessthatmarriesplay
FrMKKye?rJyexNeriKeLts*kLewhMwKuchexNerieLce
yMuwMuJdLeediLMrdertMbe?bJetMcre?te?circuitth?t
wMuJddMwh?tyMuw?Ltedst?rtiLgfrMKtheb?sic
ALMtherbre?kthrMughc?KeiLthesuKKerMf182 wheL
*weLttM-MLdMLwithKyN?reLts?LdsNeLtK?LyhMurs
visitiLgtheScieLce.useuKTheyh?djustMNeLed?Lew
wiLgdedic?tedtMcMKNuters ?LdbyfMJJMwiLg?seriesMf
guidedexNeriKeLts *Je?rLedtheb?sicsMfbiL?ryK?th
There*re?Jisedth?tiLK?Ly?NNJic?tiMLs eLgiLeerswere
LMJMLgerbuiJdiLgcircuitsfrMKb?siccMKNMLeLts but
wereiLste?diKNJeKeLtiLg?JMtMftheiLteJJigeLceiL
theirNrMductsusiLgKicrMNrMcessMrsSMftw?rew?s
reNJ?ciLgK?LyhMursMfeJectrMLicdesigL ?LdwMuJd
B?rb?r?GheJJ? shedMesL'tkLMwbut withMuther
NreciMus?dvice ArduiLM?LdthisbMMkKighth?veLever
BiJJVerNJ?LkfMrh?viLgt?ughtKeKMreth?LPhysic?J
GiJJi?LCr?KNtMLSKithfMrgiviLgKe?ch?Lce?LdfMr
Bri?L+eNsMLfMrbeiLg?gre?teditMr?LdeLthusi?stic
/?Lcy,Mt?ry Bri?LScMtt TerryBrMLsML ?LdP?tti
SchieLdeJK?LfMrturLiLgwh?t*wrMteiLtM?fiLished
*w?LttMth?Lk?JMtKMreNeMNJebutBri?LteJJsKe*'K
ruLLiLgMutMfsN?cesM*'JJjustJist?sK?JJLuKberMf
Ad?KSMKJ?iFisher AiJ?diCMrteJJetti AJbertMPezzMtti
AJess?LdrMGerKiL?si AJess?LdrM.?sserdMtti ALdre?
PiccMJM ALL?C?NeJJiLi C?seyRe?s ChrisALdersML
CJ?udiM.MderiLi CJeKeLtiL?CMNNiLi CMLcett?
C?Necchi Cs?b?W?Jdh?user D?riMBuzziLi D?riM
.MJiL?ri D?riMP?rr?viciLi DML?t?PiccMJM EdM?rdM
Br?KbiJJ? EJis?C?Lducci F?biMViMJ?Lte F?biM;?LMJ?
F?briziMPigLMJMLi FJ?viM.?uri Fr?Lcesc?.MceJJiL
Fr?LcescM.MLicM GiMrgiMOJiverM GiMv?LL?G?rdi
GiMv?LLiB?ttistiLi He?ther.?rtiL +eLLiferBMve -?ur?
DeJJ?KMtt? -MreLzMP?rr?viciLi -uc?RMccM .?rcM
B?iMLi .?rcMEyL?rd .?ri?Teres?-MLgMLi
.?ssiKiJi?LMBMJMLdi .?tteMRivMJt? .?tthi?sRichter
.?uriziMPirMJ? .ich?eJThMrNe /?t?Ji?+Mrd?L
OKbrett?B?Lzi OresteB?Lzi Osc?r;Mggi? PietrM
DMre PrMfS?JviMLi R?ff?eJJ?Ferr?r? ReLzMGiusti
S?LdiAth?L?s S?r?C?rNeLtieri SigridWiederhecker
DM*t:MurseJfKeLt?JitybyNrMvidiLgcre?tive
FMr KMre iLfMrK?tiML ?bMut .?ker .edi? visit us MLJiLe
TheO'ReiJJywebsitefMr
eLcMur?gesdesigLthrMugh?Liter?tiveNrMcessb?sedML
NrMtMtyNesMfeveriLcre?siLgfideJityThis
?NNrM?ch—?JsMN?rtMfsMKetyNesMf"cMLveLtiML?J"
desigL—c?LbeexteLdedtMiLcJudeNrMtMtyNiLgwith
ThesNecificfieJdMf*Lter?ctiMLDesigLiLvMJvedwith
ArduiLMisPhysic?JCMKNutiLg(MrPhysic?J*Lter?ctiML
WithArduiLM ?desigLerMr?rtistc?LgettMkLMwthe
b?sicsMfeJectrMLics?LdseLsMrsveryOuickJy?Ldc?L
NeMNJe ?LdLetwMrksWestrivetMfiLd?siKNJer?Ld
AJMtMfbegiLLers?NNrM?chiLgeJectrMLicsfMrthefirst
tiKethiLkth?ttheyh?vetMJe?rLhMwtMbuiJdeverythiLg
frMKscr?tchThisis?w?steMfeLergywh?tyMuw?Ltis
tMbe?bJetMcMLfirKth?tsMKethiLg'swMrkiLgvery
OuickJysMth?tyMuc?LKMtiv?teyMurseJftMt?ketheLext
steNMrK?ybeeveLKMtiv?tesMKebMdyeJsetMgiveyMu?
ThisiswhywedeveJMNed"MNNMrtuListicNrMtMtyNiLg"
whysNeLdtiKe?LdeLergybuiJdiLgfrMKscr?tch ?
NrMcessth?treOuirestiKe?LdiLdeNthtechLic?J
kLMwJedge wheLwec?Lt?kere?dyK?dedevices?Ld
h?cktheKiLMrdertMexNJMittheh?rdwMrkdMLebyJ?rge
OurherMis+?KesDysML whMK?de5127NrMtMtyNesMf
hisv?cuuKcJe?LerbefMrehew?ss?tisfiedth?the'd
gMtteLitright(
wwwiLterL?tiML?JdysMLcMK/jd/
cMKNiJe d?KL—thereis?LerrMr fixerrMr cMKNiJe ruL"
*fyMu?reKMrevisu?JJyKiLded *recMKKeLdth?tyMu
resuJtiLgiL?stre?KMfuLusu?JsMuLdsWh?t*Jike?bMut
circuitbeLdersistheir?biJitytMcre?tethewiJdestdevices
bytiLkeriLg?w?ywithtechLMJMgywithMutLecess?riJy
*t's?bitJikethe
Sniffin'Glue
f?LziLeshMwLhereduriLg
theNuLker? kLMwiLgthreechMrdsML?guit?rw?s
eLMughtMst?rt?b?LdDML'tJettheexNertsiLMLefieJd
teJJyMuth?tyMu'JJLeverbeMLeMftheK*gLMretheK?Ld
CMKNuterkeybM?rds?restiJJtheK?iLw?ytMiLter?ct
with?cMKNuter?fterKMreth?L60ye?rsAJexPeLtJ?Ld
?c?deKiche?dMfthe.*T.edi?-?bMr?tMry MLce
reK?rked"ExcusetheexNressiML butKeL'suriL?Js?re
sK?rterth?LcMKNutersCMKNuters?reisMJ?tedfrMK
AstiLkerers wec?LiKNJeKeLtLeww?ystMiLter?ctwith
sMftw?rebyreNJ?ciLgthekeyswithdevicesth?t?re?bJe
tMseLsetheeLvirMLKeLtT?kiLg?N?rt?cMKNuter
keybM?rdreve?Js?verysiKNJe(?Ldche?N deviceThe
he?rtMfitis?sK?JJbM?rd*t'sLMrK?JJy?sKeJJygreeLMr
brMwLcircuitwithtwMsetsMfcMLt?ctsgMiLgtMtwM
NJ?sticJ?yersth?thMJdthecMLLectiMLsbetweeLthe
differeLtkeys*fyMureKMvethecircuit?Lduse?wiretM
bridgetwMcMLt?cts yMu'JJsee?Jetter?NNe?rMLthe
cMKNuterscreeL*fyMugMMut?Ldbuy?KMtiMLseLsiLg
detectMr?LdcMLLectthistMyMurkeybM?rd yMu'JJsee?
keybeiLgNressedeverytiKesMKebMdyw?JksiLfrMLtMf
thecMKNuter.?NthistMyMurf?vMuritesMftw?re ?Ld
yMuh?veK?deyMurcMKNuter?ssK?rt?s?uriL?J
-e?rLiLg?bMutkeybM?rdh?ckiLgis?keybuiJdiLgbJMck
QuMtediLS?r?ReeseHedberg ".*T.edi?-?b's
OuestfMrNerceNtivecMKNuters "*LteJJigeLtSysteKs?Ld
Figure3-1.The Arduino Duemilanove
Figure3-2.The Arduino NG
_The bM?rd executes the sketch th?t yMu wrMte
/OTE*Lst?JJiLgArduiLMML-iLuxis
sMKewh?tcMKNJic?ted?tthetiKeMfthis
writiLgSee
www?rduiLMcc/NJ?ygrMuLd/
ThePWRJightMLthebM?rdshMuJdcMKeML?Ldthe
yeJJMw-EDJ?beJJed"-"shMuJdst?rtbJiLkiLg*fLMt see
Ch?Nter7
OLcethedrivers?reiLst?JJed yMuc?LJ?uLchthe
/ext yMuKustfigureMutwhichseri?JNMrtis?ssigLedtM
yMurArduiLMbM?rd—yMu'JJLeedth?tiLfMrK?tiMLtM
NrMgr?KitJ?terTheiLstructiMLsfMrgettiLgthis
Figure3-3.TheArduinoIDE'slistofserial
Figure3-4.TheWindowsDeviceManager
/MteOLsMKeWiLdMwsK?chiLes the
CO.NMrth?s?LuKbergre?terth?L
thisLuKberiLgcre?tessMKeNrMbJeKs
wheLArduiLMistryiLgtMcMKKuLic?te
withitSee
Ch?Nter7
TrMubJeshMMtiLgfMr
OLceyMu'vefiguredMuttheCO.NMrt?ssigLKeLt yMu
c?LseJectth?tNMrtfrMKtheTMMJsSeri?JPMrtKeLuiL
/MwtheArduiLMdeveJMNKeLteLvirMLKeLtc?Lt?JktM
Figure4-1.The interactive device
Figure4-2.Connecting an LED to Arduino
OLyMurcMKNuter gMMNeLthefMJderwhereyMucMNied
theArduiLM*DEDMubJecJicktheArduiLMicMLtMst?rt
itSeJectFiJe/ew?LdyMu'JJbe?skedtMchMMse?
sketchfMJderL?KethisiswhereyMurArduiLMsketch
wiJJbestMred/?Keit
?LdcJickO,
TheL tyNethefMJJMwiLgtext(
Ex?KNJe41
iLtMthe
ArduiLMsketcheditMr(theK?iLwiLdMwMftheArduiLM
*DE :Muc?L?JsMdMwLJM?ditfrMK
wwwK?keziLecMK/getst?rted?rduiLM
*tshMuJd?NNe?r
Figure43
Example4-1.Blinking LED
Figure4-3.TheArduinoIDEwithyourfirst
AtthisNMiLt yMuc?LuNJM?ditiLtMthebM?rdNressthe
UNJM?dtM*/OBM?rdbuttML(see
Figure43
ThiswiJJ
resetthebM?rd fMrciLgittMstMNwh?tit'sdMiLg?LdJisteL
fMriLstructiMLscMKiLgfrMKtheUSBNMrtTheArduiLM
*DEseLdsthecurreLtsketchtMthebM?rd whichwiJJ
:MuwiJJsee?fewKess?ges?NNe?riLthebJ?ck?re??t
thebMttMKMfthewiLdMw ?Ldjust?bMveth?t?re? yMu'JJ
seetheKess?ge"DMLeuNJM?diLg"?NNe?rtMJetyMukLMw
theNrMcessh?scMKNJetedcMrrectJyThere?retwM-EDs
K?rkedRX?LdTX MLthebM?rdthesefJ?sheverytiKe
?byteisseLtMrreceivedbythebM?rdDuriLgtheuNJM?d
*fyMudML'tseethe-EDsfJicker MrifyMuget?LerrMr
Kess?geiLste?dMf"DMLeuNJM?diLg" theLthereis?
cMKKuLic?tiMLNrMbJeKbetweeLyMurcMKNuter?Ld
ArduiLM.?kesureyMu'veseJectedtherightseri?JNMrt
Ch?Nter3
iLtheTMMJsSeri?JPMrtKeLuAJsM
checktheTMMJsBM?rdKeLutMcMLfirKth?tthecMrrect
*fyMu?restiJJh?viLgNrMbJeKs check
Ch?Nter7
OLcethecMdeisiLyMurArduiLMbM?rd itwiJJst?ythere
uLtiJyMuNut?LMthersketchMLitThesketchwiJJsurvive
ifthebM?rdisresetMrturLedMff ?bitJikethed?t?ML
AssuKiLgth?tthesketchh?sbeeLuNJM?dedcMrrectJy
yMuwiJJseethe-ED"-"turLMLfMr?secMLd?LdtheL
turLMfffMr?secMLd*fyMuiLst?JJed?seN?r?te-ED?s
shMwLb?ckiL
Figure42
th?t-EDwiJJbJiLk tMMWh?t
yMuh?vejustwritteL?Ldr?Lis?"cMKNuterNrMgr?K" Mr
sketch ?sArduiLMNrMgr?Ks?rec?JJedArduiLM ?s*'ve
KeLtiMLedbefMre is?sK?JJcMKNuter ?Lditc?Lbe
NrMgr?KKedtMdMwh?tyMuw?LtThisisdMLeusiLg?
NrMgr?KKiLgJ?Lgu?getMtyNe?seriesMfiLstructiMLsiL
theArduiLM*DE whichturLsitiLtM?Lexecut?bJefMr
*'JJLextshMwyMuhMwtMuLderst?LdthesketchFirstMf
?JJ theArduiLMexecutesthecMdefrMKtMNtMbMttMK sM
thefirstJiLe?tthetMNisthefirstMLere?dtheLitKMves
dMwL ?bitJikehMwtheNJ?yhe?dMf?videMNJ?yerJike
QuickTiKePJ?yerMrWiLdMws.edi?PJ?yerKMvesfrMK
tMsNecifyth?tthe-EDwe'rebJiLkiLgiscMLLectedtMthe
iswhereyMusNecifytheK?iLbeh?viMurMfyMur
iLter?ctivedevice*twiJJbereNe?tedMver?LdMver?g?iL
digitalWrite(LED,HIGH);// turns theLED on
AsthecMKKeLts?ys
is?bJetMturLML(Mr
Mff ?LyNiLth?th?sbeeLcMLfigured?s?LOUTPUT
Thefirst?rguKeLt(iLthisc?se
sNecifieswhichNiL
shMuJdbeturLedMLMrMff(reKeKberth?t
is?
cMLst?Ltv?Jueth?treferstMNiL13 sMthisistheNiLth?t's
switched ThesecMLd?rguKeLtc?LturLtheNiLML
(H*GH Mr Mff (-OW 
*K?giLeth?teveryMutNutNiLis?tiLyNMwersMcket Jike
theMLesyMuh?veMLthew?JJsMfyMur?N?rtKeLt
EurMNe?LMLes?re230V AKeric?LMLes?re110V ?Ld
ArduiLMwMrks?t?KMreKMdest5VTheK?gichereis
wheLsMftw?rebecMKesh?rdw?reWheLyMuwrite
digitalWrite(LED,HIGH)
itturLstheMutNutNiLtM5V
?LdifyMucMLLect?L-ED itwiJJJightuNSM?tthis
NMiLtiLyMurcMde ?LiLstructiMLiLsMftw?reK?kes
sMKethiLgh?NNeLiLtheNhysic?JwMrJdbycMLtrMJJiLg
thefJMwMfeJectricitytMtheNiLTurLiLgML?LdMffthe
NiL?twiJJLMwJetustr?LsJ?tetheseiLtMsMKethiLgKMre
ArduiLMh?s?veryb?sicstructureTherefMre ifyMuw?Lt
thiLgstMh?NNeLwith?cert?iLreguJ?rity yMuteJJittMsit
OuietJy?LddMLMthiLguLtiJitistiKetMgMtMtheLext
b?sic?JJyK?kestheNrMcessMrsitthere?Ld
dMLMthiLgfMrthe?KMuLtMfKiJJisecMLdsth?tyMuN?ss
?s?L?rguKeLt.iJJisecMLds?rethMus?LdsMfsecMLds
therefMre 1000KiJJisecMLdseOu?Js1secMLdSMthe-ED
ThisiLstructiMLLMwturLsMffthe-EDth?tweNreviMusJy
turLedMLWhydMweuseH*GH?Ld-OW?WeJJ it's?L
MJdcMLveLtiMLiLdigit?JeJectrMLicsH*GHKe?Lsth?t
theNiLisML ?LdiLthec?seMfArduiLM itwiJJbeset?t5
V-OWKe?Ls0V:Muc?L?JsMreNJ?cethese
Here wedeJ?yfMr?LMthersecMLdThe-EDwiJJbeMff
ThiscJMsiLgcurJybr?cketK?rkseLdMftheJMMN
_TurLsNiL13iLtM?LMutNut(justMLce?tthe
_ELters ? JMMN
_Switches ML the -ED cMLLected tM NiL 13
_W?its fMr ? secMLd
_Switches Mff the -ED cMLLected tM NiL 13
_W?its fMr ? secMLd
_GMes b?ck tM begiLLiLg Mf the JMMN
*hMNeth?tw?sL'ttMMN?iLfuJ:Mu'JJJe?rLKMre?bMut
BefMreweKMveMLtMtheLextsectiML *w?LtyMutMNJ?y
withthecMdeFMrex?KNJe reducethe?KMuLtMfdeJ?y
usiLgdiffereLtLuKbersfMrtheML?LdMffNuJsessMth?t
yMuc?LseediffereLtbJiLkiLgN?tterLs*LN?rticuJ?r yMu
shMuJdseewh?th?NNeLswheLyMuK?kethedeJ?ysvery
sK?JJ butusediffereLtdeJ?ysfMrML?LdMff…thereis?
KMKeLtwheLsMKethiLgstr?Lgeh?NNeLsthis
"sMKethiLg"wiJJbeveryusefuJwheLyMuJe?rL?bMut
Figure4-4.A portable fan
*fyMut?ke?f?L?N?rt yMuwiJJseeth?titcMLt?iLs?
sK?JJb?ttery ?cMuNJeMfwires ?Ld?LeJectricKMtMr
?Ldth?tMLeMfthewiresgMiLgtMtheKMtMrisiLterruNted
by?switch*fyMuh?ve?freshb?tteryiLit?LdturLthe
switchML theKMtMrwiJJst?rttMsNiL NrMvidiLgthe
Lecess?rychiJJHMwdMesthiswMrk?WeJJ iK?giLeth?t
theb?tteryisbMth?w?terreservMir?Ld?NuKN the
switchis?t?N ?LdtheKMtMrisMLeMfthMsewheeJsth?t
yMuseeiLw?terKiJJsWheLyMuMNeLthet?N w?ter
*LthissiKNJehydr?uJicsysteK shMwLiL
Figure45
twM
f?ctMrs?reiKNMrt?LttheNressureMfthew?ter(thisis
deterKiLedbytheNMwerMfNuKN ?Ldthe?KMuLtMf
w?terth?twiJJfJMwiLtheNiNes(thisdeNeLdsMLthesize
MftheNiNes?Ldtheresist?Lceth?tthewheeJwiJJNrMvide
Figure4-5.A hydraulic system
:Mu'JJOuickJyre?Jiseth?tifyMuw?LtthewheeJtMsNiL
f?ster yMuLeedtMiLcre?sethesizeMftheNiNes(butthis
wMrksMLJyuNtM?NMiLt ?LdiLcre?setheNressureth?t
theNuKNc?L?chieve*Lcre?siLgthesizeMftheNiNes
?JJMws?gre?terfJMwMfw?tertMgMthrMughtheKby
K?kiLgtheKbigger weh?veeffectiveJyreducedthe
NiNes'resist?LcetMthefJMwMfw?terThis?NNrM?ch
wMrksuNtM?cert?iLNMiLt ?twhichthewheeJwML'tsNiL
?Lyf?ster bec?usetheNressureMfthew?terisLMtstrMLg
eLMughWheLwere?chthisNMiLt weLeedtheNuKNtM
bestrMLgerThisKethMdMfsNeediLguNthew?terKiJJ
c?LgMMLuLtiJtheNMiLtwheLthewheeJf?JJs?N?rt
bec?usethew?terfJMwistMMstrMLgfMrit?Lditis
destrMyedALMtherthiLgyMuwiJJLMticeisth?t?sthe
wheeJsNiLs the?xJewiJJhe?tuN?JittJebit bec?useLM
K?tterhMwweJJweh?veKMuLtedthewheeJ thefrictiML
betweeLthe?xJe?LdthehMJesiLwhichitisKMuLtediL
wiJJgeLer?tehe?t*tisiKNMrt?LttMuLderst?Ldth?tiL?
systeKJikethis LMt?JJtheeLergyyMuNuKNiLtMthe
systeKwiJJbecMLvertediLtMKMveKeLtsMKewiJJbe
JMstiL?LuKberMfiLefficieLcies?LdwiJJgeLer?JJyshMw
SMwh?t?retheiKNMrt?LtN?rtsMfthesysteK?The
NressureNrMducedbytheNuKNisMLetheresist?Lceth?t
theNiNes?LdwheeJMffertMthefJMwMfw?ter ?Ldthe
?ctu?JfJMwMfw?ter(Jet'ss?yth?tthisisreNreseLtedby
theLuKberMfJitresMfw?terth?tfJMwiLMLesecMLd ?re
theMthersEJectricitywMrks?bitJikew?ter:Muh?ve?
kiLdMfNuKN(?LysMurceMfeJectricity Jike?b?tteryMr?
w?JJNJug th?tNusheseJectricch?rges(iK?giLetheK?s
"drMNs"MfeJectricity dMwLNiNes which?rereNreseLted
bythewires—sMKedevices?re?bJetMusethesetM
NrMducehe?t(yMurgr?LdK?'stherK?JbJ?Lket Jight
(yMurbedrMMKJ?KN sMuLd(yMurstereM KMveKeLt
SMwheLyMure?dth?t?b?ttery'svMJt?geisV thiLkMf
thisvMJt?geJikethew?terNressureth?tc?LNMteLti?JJybe
NrMducedbythisJittJe"NuKN"VMJt?geisKe?surediL
vMJts L?Ked?fterAJess?LdrMVMJt? theiLveLtMrMfthe
+ust?sw?terNressureh?s?LeJectriceOuiv?JeLt thefJMw
r?teMfw?terdMes tMMThisisc?JJedcurreLt ?Ldis
Ke?surediL?KNeres(?fterALdr\.?rieAKN]re
eJectrMK?gLetisKNiMLeer ThereJ?tiMLshiNbetweeL
vMJt?ge?LdcurreLtc?LbeiJJustr?tedbyreturLiLgtMthe
w?terwheeJ?highervMJt?ge(Nressure JetsyMusNiL?
wheeJf?ster?higherfJMwr?te(curreLt JetsyMusNiL?
FiL?JJy theresist?LceMNNMsiLgthefJMwMfcurreLtMver
?LyN?thth?tittr?veJsisc?JJed—yMuguessed
it—resist?Lce ?LdisKe?surediLMhKs(?ftertheGerK?L
NhysicistGeMrgOhK HerrOhKw?s?JsMresNMLsibJe
fMrfMrKuJ?tiLgtheKMstiKNMrt?LtJ?wiL
eJectricity—?LdtheMLJyfMrKuJ?th?tyMure?JJyLeedtM
reKeKberHew?s?bJetMdeKMLstr?teth?tiL?circuit
thevMJt?ge thecurreLt ?Ldtheresist?Lce?re?JJreJ?ted
tMe?chMther ?LdiLN?rticuJ?rth?ttheresist?LceMf?
circuitdeterKiLesthe?KMuLtMfcurreLtth?twiJJfJMw
*t'sveryiLtuitive ifyMuthiLk?bMutitT?ke?Vb?ttery
?LdNJugitiLtM?siKNJecircuitWhiJeKe?suriLgcurreLt
yMuwiJJfiLdth?ttheKMreresistMrsyMu?ddtMthecircuit
theJesscurreLtwiJJtr?veJthrMughitGMiLgb?cktMthe
?L?JMgyMfw?terfJMwiLgiLNiNes giveL?cert?iLNuKN
if*iLst?JJ?v?Jve(whichwec?LreJ?tetM?v?ri?bJe
resistMriLeJectricity theKMre*cJMsethe
v?Jve—iLcre?siLgresist?LcetMw?terfJMw—theJess
w?terwiJJfJMwthrMughtheNiNesOhKsuKK?risedhis
R (resistance) = V (voltage) / I (current)
ThisistheMLJyruJeth?tyMure?JJyh?vetMKeKMrise?Ld
Je?rLtMuse bec?useiLKMstMfyMurwMrk thisisthe
?LdreturLs?v?JueMfH*GHMr-OW deNeLdiLgMLits
fiLdiLgsTheMtheriLstructiMLsth?twe'veusedsMf?r
h?veL'treturLed?LyiLfMrK?tiML—theyjustexecuted
wh?twe?skedtheKtMdMButth?tkiLdMffuLctiMLis?
bitJiKited bec?useitwiJJfMrceustMstickwithvery
Nredict?bJeseOueLcesMfiLstructiMLs withLMiLNutfrMK
theMutsidewMrJdWith
wec?L"?sk?
OuestiML"MfArduiLM?Ldreceive?L?Lswerth?tc?Lbe
stMrediLKeKMrysMKewhere?LdusedtMK?kedecisiMLs
BuiJdthecircuitshMwLiL
Figure46
TMbuiJdthis yMu'JJ
LeedtMMbt?iLsMKeN?rts(thesewiJJcMKeiLh?Ldy?s
_SMJderJessbre?dbM?rdR?diMSh?ck
N?rtLuKber276–002
.?kerShed(
N?rtLuKber
ANNeLdixA
is?LiLtrMductiMLtMthe
_PrecutjuKNerwirekitR?diMSh?ck276–173
_OLe10,OhKresistMrR?diMSh?ck271–1335
(5N?ck SN?rkFuL(
_.MKeLt?ryt?ctiJeNushbuttMLswitchSN?rkFuL
Figure4-6.Hooking up a pushbutton
iLste?dMfbuyiLgNrecutjuKNerwire yMu
c?L?JsMbuy22AWGsMJidcMrehMMkuN
wireiLsK?JJsNMMJs?Ldcut?LdstriNit
-et'sh?ve?JMMk?tthecMdeth?twe'JJbeusiLgtMcMLtrMJ
the-ED with Mur NushbuttML
Example4-2.TurnonLEDwhilethebuttonis
int val= 0; // val will be used to store the state
Ke?Lsth?tyMurv?ri?bJewiJJstMre?LiLtegerLuKber
istheL?KeMfthev?ri?bJe ?Ld
?ssigLsit?LiLiti?J
Av?ri?bJe ?stheL?KeiLtiK?tes c?LbeKMdified
?LywhereiLyMurcMde sMth?tJ?terMLiLyMurNrMgr?K
val = 112;
which re?ssigLs ? Lewv?Jue 112 tM yMur v?ri?bJe
H?veyMuLMticedth?tiLArduiLM every
iLstructiML withMLeexceNtiML(
eLdswith?seKicMJML?ThisisdMLesM
th?tthecMKNiJer(theN?rtMfArduiLMth?t
turLsyMursketchiLtM?NrMgr?Kth?tthe
KicrMcMLtrMJJerc?LruL kLMwsth?tyMur
st?teKeLtisfiLished?Ld?LewMLeis
begiLLiLgReKeKbertMuseit?JJthe
tiKe excJudiLg?LyJiLeth?tbegiLswith
The
s?rereNJ?cedbythe
cMKNiJerbefMrethecMdeistr?LsJ?tediLtM
*LthefMJJMwiLgNrMgr?K
isusedtMstMretheresuJtMf
wh?teverArduiLMgetsfrMKtheiLNuteLds
uNiLthev?ri?bJe?LdwiJJst?ythereuLtiJ?LMtherJiLeMf
cMdech?Lgesit/Mticeth?tv?ri?bJesuse?tyNeMf
KeKMryc?JJedRA.*tisOuitef?st butwheLyMuturL
MffyMurbM?rd ?JJd?t?stMrediLRA.isJMst(which
Ke?Lsth?te?chv?ri?bJeisresettMitsiLiti?Jv?JuewheL
thebM?rdisNMwereduN?g?iL :MurNrMgr?Ks
theKseJves?restMrediLfJ?shKeKMry—thisisthes?Ke
tyNeusedbyyMurKMbiJeNhMLetMstMreNhMLe
LuKbers—whichret?iLsitscMLteLteveLwheLthebM?rd
-et'sLMwuse?LMtherv?ri?bJetMreKeKberwhetherthe
-EDh?stMst?yMLMrMff?fterwereJe?sethebuttML
Ex?KNJe43
Example4-3.TurnonLEDwhenthebuttonis
intval = 0; //val will be used to store thestate
intstate = 0; // 0 =LED off while 1 = LED on
/MwgMtestthiscMde:MuwiJJLMticeth?titwMrks…
sMKewh?t:Mu'JJfiLdth?ttheJightch?LgessMr?NidJy
-et'sJMMk?ttheiLterestiLgN?rtsMfthecMde
is?
v?ri?bJeth?tstMreseither0Mr1tMreKeKberwhetherthe
-EDisMLMrMffAfterthebuttMLisreJe?sed we
-?ter were?dthecurreLtst?teMfthebuttML ?Ldifit's
Nressed(
wech?Lgest?tefrMK0tM1 Mr
vicevers?WedMthisusiLg?sK?JJtrick ?sst?tec?Lbe
MLJyeither1Mr0Thetrick*useiLvMJves?sK?JJ
K?theK?tic?JexNressiMLb?sedMLtheide?th?t1–0is1
TheJiLeK?yLMtK?keKuchseLseiLK?theK?tics butit
dMesiLNrMgr?KKiLgThesyKbMJKe?Ls"?ssigLthe
resuJtMfwh?t's?fterKetMthev?ri?bJeL?KebefMre
Ke"—iLthisc?se theLewv?JueMfst?teis?ssigLedthe
-?teriLtheNrMgr?K yMuc?Lseeth?tweuse
figureMutwhetherthe-EDh?stMbeMLMrMffAs*
TheresuJts?refJ?kybec?useMfthew?ywere?dthe
buttMLArduiLMisre?JJyf?stitexecutesitsMwLiLterL?J
iLstructiMLs?t?r?teMf16KiJJiMLNersecMLd—itcMuJd
weJJbeexecutiLg?fewKiJJiMLJiLesMfcMdeNersecMLd
SMthisKe?Lsth?twhiJeyMurfiLgerisNressiLgthe
buttML ArduiLMKightbere?diLgthebuttML'sNMsitiML?
fewthMus?LdtiKes?Ldch?LgiLg
?ccMrdiLgJySM
theresuJtseLduNbeiLguLNredict?bJeitKightbeMff
wheLyMuw?LteditML Mrvicevers?AseveL?brMkeL
cJMckisrighttwice?d?y theNrMgr?KKightshMwthe
cMrrectbeh?viMureveryMLceiL?whiJe butKuchMfthe
HMwdMwefixthis?WeJJ weLeedtMdetecttheex?ct
KMKeLtwheLthebuttMLisNressed—th?tistheMLJy
KMKeLtth?tweh?vetMch?Lgest?teThew?y*JiketM
dMitistMstMrethev?JueMf
befMre*re?d?LewMLe
this?JJMwsKetMcMKN?rethecurreLtNMsitiMLMfthe
buttMLwiththeNreviMusMLe?Ldch?Lgest?teMLJywheL
Ex?KNJe44
Example4-4.TurnonLEDwhenthebuttonis
pressedandkeepitonafteritisreleasedNow
int state = 0; // 0 =LED off and 1 = LED on
sMuLdsfiLe?LdsiKNJe butiLre?JJifethecMLLectiMLis
LMtth?tNerfect esNeci?JJywheLthebuttMLisLMt
cMKNJeteJyNressed ?LditgeLer?tessMKesNuriMus
sigL?Jsc?JJedbMuLciLg
WheLtheNushbuttMLisbMuLciLg theArduiLMsees?
veryr?NidseOueLceMfML?LdMffsigL?JsThere?reK?Ly
techLiOuesdeveJMNedtMdMdebMuLciLg butiLthis
siKNJeNieceMfcMde*'veLMticedth?tit'susu?JJyeLMugh
tM?dd?10tM50KiJJisecMLddeJ?ywheLthecMde
Ex?KNJe45
Example4-5.TurnonLEDwhenthebuttonis
pressedandkeepitonafteritisreleased
includingsimplede-bouncingNowwithanother
// check if there was a transition
if ((val == HIGH) && (old_val == LOW)){
state = 1 - state;
}
Figure5-1.The inside of a tilt sensor
ALMtherseLsMrth?tyMuKightw?LttMtryistheiLfr?red
seLsMr?sfMuLdiLburgJ?r?J?rKs(?JsMkLMwL?s?
N?ssiveiLfr?redMrP*RseLsMrsee
Figure52
This
sK?JJdevicetriggerswheL?huK?LbeiLg(MrMtherJiviLg
beiLg KMveswithiLitsNrMxiKity*t's?siKNJew?ytM
Figure5-2.Typical PIR sensor
:MushMuJdLMwexNeriKeLtbyJMMkiLg?t?JJtheNMssibJe
devicesth?th?vetwMcMLt?ctsth?tcJMse Jikethe
therKMst?tth?tsets?rMMK'steKNer?ture(use?LMJdMLe
th?t'sLMJMLgercMLLected MrjustNJ?ciLgtwMcMLt?cts
FMrex?KNJe byusiLgthefiL?Jex?KNJefrMK
Ch?Nter4
?Ld?P*RseLsMr yMucMuJdK?keyMurJ?KNresNMLdtM
theNreseLceMfhuK?LbeiLgs MryMucMuJduse?tiJt
switchtMbuiJdMLeth?tturLsMffwheLit'stiJtedMLMLe
ThistechLiOue?JsMwMrkswithdevicesMtherth?L?L
-EDFMrex?KNJe yMuc?Lch?LgethesNeedMf?KMtMr
WhiJeexNeriKeLtiLg yMuwiJJseeth?tbJiLkiLgthe-ED
byNuttiLgdeJ?ysiLyMurcMdeis?bitiLcMLveLieLt
bec?use?ssMML?syMuw?LttMre?d?seLsMrMrseLdd?t?
MLtheseri?JNMrt the-EDwiJJfJickerwhiJeit'sw?itiLg
fMryMutMfiLishre?diLgtheseLsMr-uckiJy the
NrMcessMrusedbytheArduiLMbM?rdh?s?NieceMf
h?rdw?reth?tc?LveryefficieLtJybJiLkthree-EDswhiJe
yMursketchdMessMKethiLgeJseThish?rdw?reis
iKNJeKeLtediLNiLs 10 ?Ld11 whichc?Lbe
Figure5-3.PWM in action
FMrex?KNJe writiLg
wiJJsetthe
brightLessMf?L-EDcMLLectedtMNiLtM50%Why
exNects?LuKberbetweeL0?Ld255
?s?L?rguKeLt where255Ke?LsfuJJbrightLess?Ld0
H?viLgthreech?LLeJsisverygMMd
bec?useifyMubuyred greeL ?LdbJue
-EDs yMuc?LKixtheirJights?LdK?ke
-et'stryitMutBuiJdthecircuitth?tyMuseeiL
Figure54
/Mteth?t-EDs?reNMJ?rizedtheJMLgNiL
(NMsitive shMuJdgMtMtheright ?LdtheshMrtNiL
(Leg?tive tMtheJeftAJsM KMst-EDsh?ve?fJ?tteLed
Figure5-4.LED connected to PWM pin
TheL cre?te?LewsketchiLArduiLM?Lduse
Ex?KNJe51
(yMuc?L?JsMdMwLJM?dcMdeex?KNJesfrMK
Example5-1.FadeanLEDinandoutlikeona
TMcre?tethiscircuit yMuwiJJLeedtMcMKbiLethecircuit
yMujustbuiJt(shMwLiL
Figure54
withtheNushbuttML
circuitshMwLiL
Figure46
*fyMu'dJike yMuc?LsiKNJy
buiJdbMthcircuitsMLdiffereLtN?rtsMfthebre?dbM?rd
yMuh?veNJeLtyMfrMMKHMwever MLeMfthe?dv?Lt?ges
Mfthebre?dbM?rd(see
ANNeLdixA
isth?tthereis?N?ir
Mfr?iJsruLLiLghMrizMLt?JJy?crMssthebMttMK?LdtMN
OLeisK?rkedred(fMrNMsitive ?LdtheMtherbJueMr
bJ?ck (fMrgrMuLd 
Theser?iJs?reusedtMdistributeNMwer?LdgrMuLdtM
whereit'sLeeded*Lthec?seMfthecircuityMuLeedtM
buiJdfMrthisex?KNJe yMuh?vetwMcMKNMLeLts(bMthMf
theKresistMrs th?tLeedtMbecMLLectedtMtheG/D
(grMuLd NiLMLtheArduiLMBec?usetheArduiLMh?s
twMG/DNiLs yMucMuJdsiKNJycMLLectthesetwM
circuitsex?ctJy?sshMwLiLe?chMfthetwMfiguresjust
hMMktheKbMthuNtMtheArduiLM?tthes?KetiKeOr
yMucMuJdcMLLectMLewirefrMKthebre?dbM?rd'sgrMuLd
r?iJtMMLeMftheG/DNiLsMLtheArduiLM ?LdtheLt?ke
thewiresth?t?recMLLectedtMG/DiLthefigures?Ld
*fyMu'reLMtre?dytMtrythis dML'twMrrysiKNJywireuN
bMthcircuitstMyMurArduiLM?sshMwLiLFigures
Figure46
Figure54
:Mu'JJsee?Lex?KNJeth?t
usesthegrMuLd?LdNMsitivebre?dbM?rdr?iJsiL
Ch?Nter6
GettiLgb?cktMthisLextex?KNJe ifweh?vejustMLe
NushbuttML hMwdMwecMLtrMJthebrightLessMf?J?KN?
We'regMiLgtMJe?rLyet?LMtheriLter?ctiMLdesigL
techLiOuedetectiLghMwJMLg?buttMLh?sbeeLNressed
TMdMthis *LeedtMuNgr?de
Ex?KNJe45
Ch?Nter4
tM?dddiKKiLgTheide?istMbuiJd?L"iLterf?ce"iL
which?Nress?LdreJe?se?ctiMLswitchestheJightML?Ld
Example5-2.TurnonLEDwhenthebuttonis
pressedandkeepitonafteritisreleased
includingsimplede-bouncing.Ifthebuttonis
#define BUTTON 7 // input pinof the pushbutton
Figure5-5.Light-dependent resistor (LDR)
*Ld?rkLess theresist?LceMf?JightdeNeLdeLtresistMr
(-DR isOuitehighWheLyMushiLesMKeJight?tit the
resist?LceOuickJydrMNs?LditbecMKes?re?sML?bJy
gMMdcMLductMrMfeJectricity*tisthus?kiLdMf
BuiJdthecircuitth?tc?Kewith
Ex?KNJe42
(see"UsiLg
?PushbuttMLtMCMLtrMJthe-ED"iL
Ch?Nter4
theL
Ex?KNJe42
/MwNJugthe-DRMLtMthebre?dbM?rdiLste?dMfthe
NushbuttML:MuwiJJLMticeth?tifyMucMverthe-DR
withyMurh?Lds the-EDturLsMffULcMverthe-DR
?LdtheJightgMesML:Mu'vejustbuiJtyMurfirstre?J
seLsMrdriveL-EDThisisiKNMrt?Ltbec?usefMrthefirst
tiKeiLthisbMMk we?reusiLg?LeJectrMLiccMKNMLeLt
th?tisLMt?siKNJeKech?Lic?Jdeviceit's?re?Jrich
Figure5-6.An analogue sensor circuit
Example5-3.BlinkLEDataratespecifiedbythe
val =analogRead(0); // read the value from
// 9600 bits per second
}
void loop() {
val = analogRead(SENSOR); // read the value from
// the sensor
Serial.println(val); // print the value to
// the serial port
th?tMNer?tesb?sedMLthefieJdeffect
NriLciNJeThisKe?Lsth?teJectricitywiJJ
fJMwthMugh?NieceMfseKicMLductMr
K?teri?J(betweeLtheDr?iL?LdSMurce
NiLs wheL?vMJt?geis?NNJiedtMtheG?te
NiLAstheG?teisiLsuJ?tedfrMKtherest
thrMugh?J?yerMfKet?JMxide thereisLM
curreLtfJMwiLgfrMKArduiLMiLtMthe
.OSFET K?kiLgitverysiKNJetM
iLterf?ceThey?reide?JfMrswitchiLgML
?Ld MffJ?rge JM?ds ?t high freOueLcies
Figure57
yMuc?LseehMwyMuwMuJduse?
.OSFETJikethe*RF520tMturLML?LdMff?sK?JJ
KMtMr?tt?chedtM?f?L:MuwiJJ?JsMLMticeth?tthe
KMtMrt?kesitsNMwersuNNJyfrMKtheVcMLLectMrML
theArduiLMbM?rdThisis?LMtherbeLefitMfthe
.OSFETit?JJMwsustMdrivedeviceswhMseNMwer
suNNJydiffersfrMKtheMLeusedbyArduiLMAsthe
.OSFETiscMLLectedtMNiL wec?L?JsMuse
tMcMLtrMJthesNeedMftheKMtMrthrMugh
Figure5-7.A motor circuit for Arduino
Figure6-1.The finished lamp
TheJ?KN ?syMuc?LseeiL
Figure61
is?siKNJesNhere
sittiLgML?b?sewith?J?rgehMJetMkeeNthesNherefrMK
rMJJiLgMffyMurdeskThisdesigL?JJMwsyMutMMrieLtthe
*LterKsMffuLctiML?Jity wew?LttMbuiJd?deviceth?t
wMuJdcMLLecttMthe*LterLet fetchthecurreLtJistMf
?rticJesMLthe.?kebJMg(
?LdcMuLt
hMwK?LytiKesthewMrds"Ne?ce" "JMve" ?Ld
"ArduiLM"?reKeLtiMLedWiththesev?Jues we'regMiLg
tMgeLer?te?cMJMur?LddisNJ?yitMLtheJ?KNTheJ?KN
itseJfh?s?buttMLwec?LusetMturLitML?LdMff ?Ld?
PrMcessiLgcMKKuLityisJiveJy?LdheJNfuJ ?Ld
yMuc?LfiLdthMus?LdsMfNreK?deex?KNJe
TheNrMxydMesthefMJJMwiLgwMrkfMrusitdMwLJM?ds
theRSSfeedfrMK
?Ldextr?cts?JJthe
wMrdsfrMKtheresuJtiLgX.-fiJeTheL gMiLgthrMugh
?JJMftheK itcMuLtstheLuKberMftiKes"Ne?ce" "JMve"
?Ld"ArduiLM"?NNe?riLthetextWiththesethree
LuKbers we'JJc?JcuJ?te?cMJMurv?Jue?LdseLdittM
ArduiLMThebM?rdwiJJseLdb?ckthe?KMuLtMfJight
Ke?suredbytheseLsMr?LdshMwitMLthecMKNuter
OLtheh?rdw?reside we'JJcMKbiLetheNushbuttML
ex?KNJe theJightseLsMrex?KNJe thePW.-EDcMLtrMJ
AsArduiLMis?siKNJedevice we'JJLeedtMcMdifythe
cMJMuriL?siKNJew?yWe'JJusethest?Ld?rdw?yth?t
cMJMurs?rereNreseLtediLHT.-#fMJJMwedbysix
Hex?deciK?JLuKbers?reh?Ldy bec?usee?ch8bit
LuKberisstMrediLex?ctJytwMch?r?cterswithdeciK?J
LuKbersthisv?riesfrMKMLetMthreech?r?cters
Predict?biJity?JsMK?kesthecMdesiKNJerwew?ituLtiJ
wesee?L# theLwere?dthesixch?r?ctersth?tfMJJMw
iLtM?
(?v?ri?bJeused?s?teKNMr?ryhMJdiLg?re?
fMrd?t? FiL?JJy weturLe?chgrMuNMftwMch?r?cters
iLtM?byteth?treNreseLtsthebrightLessMfMLeMfthe
}
port.write(cs); // send data to Arduino
int inByte = port.read(); // read one byte
buffer = buffer + char(inByte); // just add it to the buffer
}
// prepare a connection
URLConnection conn = url.openConnection();
There?retwMthiLgsyMuLeedtMdMbefMrethePrMcessiLg
sketchwiJJruLcMrrectJyFirst yMuLeedtMteJJ
PrMcessiLgtMgeLer?tethefMLtth?twe?reusiLgfMrthe
sketchTMdMthis cre?te?Lds?vethissketchTheL with
thesketchstiJJMNeLed cJickPrMcessiLg'sTMMJsKeLu
theLseJectCre?teFMLtSeJectthefMLtL?Ked
HeJvetic?/eueBMJd chMMse32fMrthefMLtsize ?LdtheL
SecMLd yMuwiJJLeedtMcMLfirKth?tthesketchisusiLg
thecMrrectseri?JNMrtfMrt?JkiLgtMArduiLM:Mu'JJLeed
tMw?ituLtiJyMu've?sseKbJedtheArduiLMcircuit?Ld
uNJM?dedtheArduiLMsketchbefMreyMuc?LcMLfirKthis
OLKMstsysteKs thisPrMcessiLgsketchwiJJruLfiLe
HMwever ifyMudML'tsee?LythiLgh?NNeLiLgMLthe
ArduiLM?LdyMudML'tsee?LyiLfMrK?tiMLfrMKtheJight
seLsMr?NNe?riLgMLscreeL fiLdthecMKKeLtJ?beJed
"*.PORTA/T/OTE"iLthePrMcessiLgsketch?Ld
HereistheArduiLMsketch(?JsM?v?iJ?bJe?t
int state = 0;
char buffer[7] ;
state = 1 - state;
}
w?ytMdMthisistMbuy?L*,EA"FADO"t?bJeJ?KN*t's
LMwseJJiLgfMr?bMutUS$14/€14/^8(?hh the
*Lste?dMfusiLgthreeseN?r?te-EDs yMuc?Luse?
siLgJeRGB-ED whichh?sfMurJe?dscMKiLgMffit
:Mu'JJhMMkituNiLKuchthes?Kew?y?sthe-EDs
shMwLiL
Figure62
withMLech?LgeiLste?dMfthree
seN?r?tecMLLectiMLstMthegrMuLdNiLMLArduiLM yMu'JJ
h?ve?siLgJeJe?d(c?JJedthe"cMKKMLc?thMde" gMiLg
SN?rkFuLseJJs?4Je?dRGB-EDfMr?fewdMJJ?rs
N?rtLuKberCO.00105 AJsM
uLJikediscretesiLgJecMJMr-EDs theJMLgestJe?dMLthis
RGB-EDistheMLeth?tgMestMgrMuLdThethree
shMrterJe?dswiJJLeedtMcMLLecttMArduiLMNiLs 10
?Ld11(with?resistMrbetweeLtheJe?ds?LdtheNiLs
FireMffyMurPrMcessiLgcMde NresstheML/MffbuttML
As?Lexercise trytM?ddcMdeth?twiJJturLMLtheJ?KN
wheLtherMMKgetsd?rkOtherNMssibJeeLh?LceKeLts
_AddtiJtseLsMrstMturLtheJ?KNMLMrMffby
_Add?sK?JJP*RseLsMrtMdetectwheLsMKebMdy
is?rMuLd?LdturLitMffwheLLMbMdyistheretM
_Cre?tediffereLtKMdessMth?tyMuc?Lget
K?Lu?JcMLtrMJMfthecMJMurMrK?keitf?de
tMthefiLishedNrMjectThis?NNrM?chwiJJ?JJMwyMutM
_*fyMuh?vebeeLusiLg?LexterL?JNMwersuNNJy
?Ld?reusiLg?LMJdArduiLM(ExtreKe /G Mr
DieciKiJ? K?kesureth?ttheNMwersuNNJyis
NJuggediL?Ldth?tthejuKNerK?rkedSV1is
cMLLectiLgthetwMNiLsth?t?reLe?resttMthe
WheLyMu?reh?viLgtrMubJewithMther
sketches?LdLeedtMcMLfirKth?tthe
bM?rdisfuLctiMLiLg MNeLthefirst"bJiLk
?L-ED"ex?KNJeiLtheArduiLM*DE?Ld
uNJM?dittMthebM?rdTheMLbM?rd-ED
*fyMuh?vegMLethrMugh?JJthesesteNssuccessfuJJy theL
yMuc?LbecMLfideLtth?tyMurArduiLMiswMrkiLg
theMLeth?twiJJbeNushiLguNd?isies LMt
*fyMu'regettiLg?shMrtcircuit yMuh?vetMst?rtthe
"siKNJific?tiML?LdsegKeLt?tiML"NrMcessWh?tyMu
KustdMisgMthrMugheveryseLsMriLtheNrMject?Ld
ThefirstthiLgtMst?rtfrMKis?Jw?ystheNMwersuNNJy
(thecMLLectiMLsfrMK5V?LdG/D -MMk?rMuLd?Ld
K?kesureth?te?chN?rtMfthecircuitisNMwered
WMrkiLgsteNbysteN?LdK?kiLgMLesiLgJeKMdific?tiML
?t?tiKeistheLuKberMLeruJefMrfixiLgstuffThisruJe
w?sh?KKerediLtMKyyMuLghe?dbyKyschMMJ
NrMfessMr?LdfirsteKNJMyer .?uriziMPirMJ?EverytiKe
*'KdebuggiLgsMKethiLg?LdthiLgsdML'tJMMkgMMd(?Ld
beJieveKe ith?NNeLs?JMt hisf?ceNMNsiLKyhe?d
s?yiLg"MLeKMdific?tiML?t?tiKe…MLeKMdific?tiML?t
?tiKe"?Ldth?t'susu?JJywheL*fixeverythiLgThisis
veryiKNMrt?Lt bec?useyMuwiJJkLMwwh?tfixedthe
NrMbJeK(it's?JJtMMe?sytMJMsetr?ckMfwhich
KMdific?tiML?ctu?JJysMJvedtheNrMbJeK whichiswhy
E?chdebuggiLgexNerieLcewiJJbuiJduNiLyMurhe?d?
"kLMwJedgeb?se"Mfdefects?LdNMssibJefixesALd
befMreyMukLMwit yMu'JJbecMKe?LexNertThiswiJJ
K?keyMuJMMkverycMMJ bec?use?ssMML?s?Lewbie
s?ys"ThisdMesL'twMrk!"yMu'JJgiveit?OuickJMMk?Ld
/Mw dMthes?KewiththeUSBSeri?JPMrtdeviceth?t
reNreseLtsArduiLM withMLech?Lge?ssigLittheCO.
*fthesesuggestiMLsdML'theJN MrifyMu'reh?viLg?
NrMbJeKLMtdescribedhere checkMuttheArduiLM
trMubJeshMMtiLgN?ge?t
www?rduiLMcc/eL/Guide/
heJN NMst?OuestiMLtherePickthecMrrectbM?rdfMryMur
NrMbJeKthere?rediffereLt?re?sfMrsMftw?reMr
h?rdw?reissues?LdeveLfMruKsiLfivediffereLt
_Wh?t ArduiLM bM?rd ?re yMu usiLg?
_Wh?tMNer?tiLgsysteK?reyMuusiLgtMruLthe
_Give?geLer?JdescriNtiMLMfwh?tyMu'retryiLg
tMdMPMstJiLkstMd?t?sheetsMfstr?LgeN?rts
TheLuKberMf?LswersyMugetdeNeLdsMLhMwweJJyMu
:Murch?LcesiLcre?seifyMu?vMidthesethiLgs?t?JJcMst
(theseruJes?regMMdfMr?LyMLJiLefMruKs LMtjust
_TyNiLgyMurKess?ge?JJiLCAP*TA-S*t
?LLMysNeMNJe?JMt?LdisJikew?JkiLg?rMuLd
with"Lewbie"t?ttMMedMLyMurfMrehe?d(iL
MLJiLecMKKuLities tyNiLgiL?JJc?Nit?Jsis
_PMstiLgthes?KeKess?geiLsever?JdiffereLt
_"BuKNiLg"yMurKess?gebyNMstiLgfMJJMwuN
cMKKeLts?skiLg"Hey hMwcMKeLMMLe
reNJied?"MreveLwMrse siKNJyNMstiLgthetext
"buKN"*fyMudidL'tget?reNJy t?ke?JMMk?t
yMurNMstiLgW?sthesubjectcJe?r?DidyMu
NrMvide?weJJwMrdeddescriNtiMLMftheNrMbJeK
_WritiLgKess?gesJike"*w?LttMbuiJd?sN?ce
shuttJeusiLg?rduiLMhMwdM*dMth?t"This
Ke?Lsth?tyMuw?LtNeMNJetMdMyMurwMrkfMr
yMu ?Ldthis?NNrM?chissiKNJyLMtfuLfMr?re?J
tiLkerer*t'sbettertMexNJ?iLwh?tyMuw?LttM
buiJd?LdtheL?sk?sNecificOuestiML?bMutMLe
_Av?ri?tiMLMftheNreviMusNMiLtiswheLthe
OuestiMLiscJe?rJysMKethiLgtheNMsterMfthe
Kess?geisgettiLgN?idtMdM*fyMu?sksNecific
OuestiMLsNeMNJe?reh?NNytMheJN butifyMu?sk
theKtMdM?JJyMurwMrk(?LdyMudML'tsh?rethe
_PMstiLgKess?gesth?tJMMksusNiciMusJyJike
schMMJ?ssigLKeLts?Ld?skiLgthefMruKtMdM
yMurhMKewMrkPrMfessMrsJikeKerM?Kthe
differeLcesThetMN?LdbMttMKrMws(cMJMurediLred
?LdbJue?LdK?rkedwith ?Ld– ?recMLLected
hMrizMLt?JJy?Ld?reusedtMc?rrytheNMwer?crMssthe
bM?rdsMth?twheLyMuLeedNMwerMrgrMuLd yMuc?L
NrMvideitveryOuickJywith?
(?shMrtNieceMf
wireusedtMcMLLecttwMNMiLtsiLthecircuits TheJ?st
thiLgyMuLeedtMkLMw?bMutbre?dbM?rdsisth?tiLthe
KiddJe thereis?J?rgeg?Nth?tis?swide?sthesizeMf?
sK?JJchiNE?chvertic?JJiLeMfhMJesisiLterruNtediLthe
KiddJe sMth?twheLyMuNJugiL?chiN yMudML't
shMrtcircuittheNiLsth?t?reMLthetwMsidesMfthechiN
FigureA-1.The solderless breadboard
ColourValue
BJ?ck0
BrMwL1
Red2
Or?Lge3
:eJJMw4
GreeL5
BJue6
PurNJe7
Grey8
White
SiJver10%
ColourValue
GMJd5%
FMrex?KNJe brMwL bJ?ck Mr?Lge ?LdgMJdK?rkiLgs
Ke?L103±5%E?sy right?/MtOuite bec?usethereis?
twistthethirdriLg?ctu?JJyreNreseLtstheLuKberMf
zerMsiLthev?JueTherefMre103is?ctu?JJy10
fMJJMwedby3zerMs sMtheeLdresuJtis10 000MhKs
±5%EJectrMLicsgeeksteLdtMshMrteLv?Juesby
exNressiLgtheKiLkiJMMhK(fMrthMus?LdsMfMhKs ?Ld
Keg?MhKs(fMrKiJJiMLsMfMhKs sM?10 000MhK
resistMrisusu?JJyshMrteLedtM10k whiJe10 000 000
becMKes10.PJe?seLMteth?tbec?useeLgiLeers?re
fMLdMfMNtiKisiLgeverythiLg MLsMKescheK?tic
di?gr?KsyMuKightfiLdv?JuesexNressed?s4k7 which
C?N?citMrs?re?bite?siertheb?rreJsh?Nedc?N?citMrs
(eJectrMJyticc?N?citMrs geLer?JJyh?vetheirv?Jues
NriLtedMLtheKAc?N?citMr'sv?JueisKe?surediLf?r?ds
(F butKMstc?N?citMrsth?tyMueLcMuLterwiJJbe
Ke?surediLKicrMf?r?ds(μF SMifyMusee?c?N?citMr
.?LyMfthediscsh?Nedc?N?citMrs(cer?Kicc?N?citMrs
dMLMth?vetheiruLitsJisted ?Lduse?threedigit
LuKericcMdeiLdic?tiLgtheLuKberMfNicMf?r?ds(NF 
There?re1 000 000NFiLMLeμFSiKiJ?rtMtheresistMr
cMdes yMuusethethirdLuKbertMdeterKiLetheLuKber
MfzerMstMNut?fterthefirsttwM withMLediffereLceif
yMusee0–5 th?tiLdic?testheLuKberMfzerMs6?Ld7
?reLMtused ?Ld8?Ld?reh?LdJeddiffereLtJy*fyMu
see8 KuJtiNJytheLuKberth?tthefirsttwMdigitsfMrK
SM ?c?N?citMrJ?beJJed104wMuJdbe100 000NFMr01
ALMthercJe?rex?KNJeistheiLductMr whichisbuiJtby
wiLdiLgcMNNerwire?rMuLd?cyJiLdric?Jsh?Ne
ThecMLLectiMLsbetweeLcMKNMLeLts?reusu?JJyK?de
usiLgeitherwiresMrtr?cksMLtheNriLtedcircuitbM?rd
?Ld?rereNreseLtedMLthedi?gr?K?ssiKNJeJiLesWheL
twMwires?recMLLected thecMLLectiMLisreNreseLtedby
Thisis?JJyMuLeedtMuLderst?Ldb?sicscheK?ticsHere
is?KMrecMKNreheLsiveJistMfsyKbMJs?Ldtheir
:MuK?yeLcMuLterv?ri?tiMLsiLthesesyKbMJs(fMr
ex?KNJe bMthv?ri?LtsMfresistMrsyKbMJs?reshMwL
here See
eLwikiNedi?Mrg/wiki/EJectrMLic>syKbMJ
fMr?
J?rgerJistMfeJectrMLicssyKbMJsBycMLveLtiML
di?gr?Ks?redr?wLfrMKJefttMrightFMrex?KNJe ?
r?diMwMuJdbedr?wLst?rtiLgwiththe?LteLL?MLthe
Jeft fMJJMwiLgtheN?thMfther?diMsigL?J?sitK?kesits
ThefMJJMwiLgscheK?ticdescribestheNushbuttMLcircuit

Приложенные файлы

  • pdf 11150551
    Размер файла: 2 MB Загрузок: 0

Добавить комментарий