You are on page 1of 32
Getting Started with APduln0 wririccs na xf | Fisess! ,, i Cl Faasaaas & agence Suenasu @to6% © by Massimo Banzi Aknowledgments “This haoket contains mata oe code writen by Bea Calogero, Das Cuatiels, ef Gray Ten Igoe, Dan Melisa Christian Nad “The Andina tam is composed of Massimo Bana, David Cortes, Tom Ios, David Melis and Gianloe Marino. “The Andino teatn would keto thank the allowing people and institatons for Uhesport in making this booklets Alla Corelle forthe typesetting of the second release, ‘lea Candice fr the iltrtions: ‘Alexander Zvanovi for corection and feedback Interaction Design tab, Milan ovis Aeadems, ano Interaction Design Institut, Milano Malm University acl of A, Culture and Communication (K3) ‘aie and typeset by Alesana Desehampe-Sonsino Index Introduction ots interaction design? {ats pysial computing? ‘The Arduiro way ‘tinkering ‘pacing iret ending ‘etoara hacks {oe lve jk cing toss {oolibration ‘ve Anta harcvare ‘he software 1D) ‘he development environment ly getting started Pease iniroductic to programming ‘mang an LED Bink. (hts electicie? ‘rhe sreadbonrd ‘racing a pst baton drsing aschetls dagram [fon off sensors ‘igh: sensors ‘Fal inputs (oser eitivesonsoes {serial communiesion ‘anal outpats diving geo loads ‘eomplex sensors ‘allng tosatiware Find out more Appendix 29°31 Introduction Arduino isam open soure physical computing platform based oa single 0 tour and a development evircent hit impletents he Proceaing nue ‘Arduino can be use to develop stand-alone interactive objects an be ‘conneeted to software on jour compute (eg, Fash, Processing. Man/NSP)-The boars can be assembled by hand or purchased pre-asembled the open-souree DE can be downoad fo fee. Arduino sdifeent rom oter platforms that ean be found on the marsetfora tab of reasons: ~The Arduino Projet was developed ote an edweational environment an is ‘hereore reat fer newcomers to get things working qui ‘is a mul-platform ensironment ean run on Window, Maintshand noe. Teisnsed on the Processing pouring 18 Teisprogrammed ia USB eae ota sera pot This sel beause many ‘oder computers dont hae sei ports anymore. eis Open Gore hardvarc and oftware Ifyou wih 3ouean downead the rat dagram, buy all the components, and make your own, without fain, ‘myehing tothe makers of rdin. ‘The hardatets cheap, The USD board cost about C20 and replacing burt out ‘Alpen board teat and cts no moran So youcan aldo make tsa, "Theres an active community of ers online septs never ery fara {n short, this bolts designed toa beginners to understand what beets they ean get rom leaning how to sete Ard platform and adopting ts pllosopt: ‘Note: Tis booklet was written forthe “orginal” Arduino uses, designs and, tts: therefor tres to explain things way that might dive some ‘engineers raz Actually one of them defined the introductory chapters as “Bu “That's preciely the point, Lets fants most engineers arent able toeplin what they do toaneter engineers let alone a regular human being, Let's now delve ‘ee ino the ft Foreword _Afow yar go Iwas given very intersting challange teach designers the bare imum in eletronic stat they could bald interctve prototypes forthe projets. | sare ftloving a snbeonsins method of teaching electrons that resembled the way I wastaught a seFoo eventually realised that it simpy didi work as ‘sell ae wool have liked and reminded me of siting cles, bored to deat as someone thre thea at me without any practice already knew lectronics in ‘very empirea way: through alot of hands-on experince and ver itl theory find started othink about hor that had happened Asa chil, vas fascinate by diseoverng how things worked and usd tte them apart. This passion grew as targeted any unused object inthe house and ‘would take itt bits Eventually; people would bring all sorts of devices for me to ‘isot My bigest proc at the Ge was dishwasher and an ear computer ‘hat eame fom an insane office whieh ha a huge printer etronies ad, magnetic ard eaters and many other pars. This prove quite challenger take part After quitea tof this dissecting Ine what elatronic components were and ‘gh what the dd: On topo that, my house was ful of elecrons magazines tha father ast have bought atthe beginning of the 70s and ‘Spent countless hours reading the ails and locking a the creat dlagrams ‘nthot densanding ver mis ‘This process weading these aries nthe igh of knowledge ape ube {aking apart creuts crated a slow tious de A bretkthrogh happened one Chrismas. My dad gave me a it that woud allo teenagers to kam about elsctrones. Every component was housed ina plastic. be with theeleeonic symbol written on topo it. The eubes would magnetically ‘Shap together wth eter cabes establishing connection. Lied Tow that the toy as designe by Ditr Rams landmark designer from Germany) i the or. ‘woth his new toa could ull put together eis and tryout what -nappened Te prototyping eyee was geting shorter and shorter rom then on | built rads, amplifr, circuits that would preduce hob and ‘ceasonll nice sounds, ain sensor tin robes. 1 spent longtime finding an lish word that could sum up away of working without spre plan starting with ea and ending up with a completes Unexpected result and “Takerng” came along subsequentydisconert that this way of operating has been used n many ther lds to desenibe people who {set themeles on a path cf exploration A generation of Prench dirctors who {avebinh the "Newvelle Vague" wer called the "nkerersfor example My favorit defntion of tinkering comes rom anexitition held atthe "xplortorinm in San Francis: “Tinkering ie wha happens when you try someting you donk quite now how todo, guded by whi, dmegination aad uri. Tsao letting the spark of an tea ignite, no matter how fir fe dais When yo tinker thee ave no instructions, ut there m0 Fatlr,norighe or ean wes ding things. ts} about figuring out hw things work — and about reworking thom. Mabou pursing fas ation ne ting unfold into process of discovery, abt seeing the patel pl of junk nd ‘rote e-naging i as arouse. Contraptions machines, telly msmatched oes warty mt harmomy ths arches ote the st of nergy. Tern s,s most base, proese that marries play and inquiry” From my early experiments recognised how much experience you net inorder tobeable tactente a crt that would do what I wanted starting rom he basic ‘component {nthe summer of 1982 went 1 London forthe st time with my parents an spent many hous vsting the Seience Museum. They had jist opened anew wing ConrlPanel-> System. > Hardware-> Devie Manager | Look forthe device inthe ist under “Ports (COM fe LPT) ‘ino willcome wp as an USD Serial Por” and wil ave a namelikeCOM [ricsereensht ofthe device manager showing Arduino) Then nthe 1D, sleet the appropriate por from the “Tooe> SerialPort ment Now the Arduino development environment ean talk tothe Arduino boud and NB: Hor some reasons on some windows machine the CO port has amaonbor ‘greater han 9a hs eres some problems when Arno yng 10 ‘Sommunioate witht, Chek nthe Arun troubleshooting section ofthe website how ita Really getting started ‘Now that we haveintrsuced yout the Arduino pilbsophy and its components wwe are ready to mak comeing happen wit your bard Inthe following pages lg through afew exarples ofthe bas hinge you «an do with Arduino. After these exercises you willbe ready to experiment ob sourown. [he intracive device ‘Most f the objets we wil build using the Arduino board fllow avery simple pater that we el the “interactive Device” isan electronic cc that is abet sense the environment using components «ill! “Sensrs” and processing the infonnation the "behavior Itapemented as satareThe device wl hen beset interact back wth the world sing “actus” (ewmeors and ostatone Sensors and Actustors are electronic component that allow aplose of etnies tolnerat with the world. Sine the microcontroller isa very simple computer it an only proesseetrc ‘inal (bit ike the lee pulses that are sent between neuroas in our beat). Imorder tonable tt sens ight. emperatarecr other pial quae it reeds somethngthat ean conver them nalts first “Theeye for example, convert ight to sgn that get sit othe brain sing nerves. Inthe word of lcronis we could we a simple devi called LDR that ‘an meastre the aout fight hat hist and report ack a ial ia ean be understod by the proces. (nce the senses have been read, the device has the iformation need to "decide" howto rea This done through Actuators. These are lectree ‘components hat ean convert an electric sighalinto a physi action Mascles the lectrenie word this ncn cc be performed bya lactis tor. Inthe next chapters we wil se ho to read sensors of diferent types and control fret bie of aetuator ne /basic introduction to programming Ifyou have pergrammed befor youn hip this chapter Programming salou translating the behaviour we have in mind for ou device Jo instructions that cane understood by the process. ln ely the processor ‘uses very dete and vr low-level language so through ime high level” languages hme been devel ped, These are closer to human language Let's sc hove we would go about translating simple behasourinto a piece of program A sinple pram ca always be writen ss sentences ‘en tis ery dark fant the ight ogo andthe motor start rnin soul ‘Wie could the rewrite histo “pseudo coe" (something that looks mre ike a program buts sil human language) ‘Wie quickly cise that we need two types programming structures: ops and condtinalsatements_ loop i necesary 1 allow the processor to continually ‘ead the stats oft nuts ae wel sto elite the tates fs oats Conditional statements br tse 0 check er certain conditions and change {the corse of te program epending on then the base Arno pogra Toots ike this [tata ta 8 coment 11 sactabie dectazet ion 17 pit code here oid Loop 0 + 7) pat code hese y tthe beginning ofthe rogram, we delare variables which are areas memory tied to stove data ‘Then the voidint) funtion is usod to setup the program and defines vic pins ‘onthe processor are inputs and which are outpats. “The as fncton, ei loop) wil be exec indefinitely until yon ten the Arduino arto. This ahora the conditions lg wil be tore hts the ete ofthe progr where you can contol te Bo oF the prea ‘The text begining wth // sa comment which use or ou toremind ‘ourself wat your ade does when you e-open tater awhile for eer People wha might want to ewer yor code variables ‘One spel hing about programming that eer time you want to store some salve you need fo use a arabe that you have to declare hat stl the ‘computer what ind of ave to expe. Tere area fe base data pest ‘computer canexpet that we wll go heough here: int anintoserisa whole umber 1.958 byte anintegernumber between 0 and 26, hiss useful ifsou ned to Save memory beeaseituses only Esteof memory: (eerie thatthe Arduino board has aly 1024 bytes of RAM) or moat ofthe programming you wll be doing these datatypes wl eal you wl eed. or moce detail se: htp://uurw arduin.ce/en/Reference/HomeP ace flaw control {condition Then InArcin,anifstatement looks tke this ittexpression! , 3 ‘Where the expresion could be one (or acombination) ofthe following: b acquilb AID aisnetequaltob a>b aisgreterthand cb alsiessthanb Seb ais ne than or equals to 550 als gator than orequalstob (\.B.do notcofise == with the assignment operator = that actualy changes the vlc of te variable othe leo this can be very dangers!) ‘Statements can fant you Tae Ging more eon statements). for kop for (iat) ‘ ) A forloop is away toexeewte a certain piece of code for a er specific amount of tines In the example som statenen tenet tines with" going om 4 wos. a) ae) delays aatay 200) 7 ‘The dla) fanetin is uel for embed programming to slow down the rate t whi the yronesor updates. This suse to ake thing happens ater ‘ate, fr exampleifwe want to link and ed every second, after we tur ton we ‘plage a dlay(1000) whieh wll make the poses st there ado nothing for second (000 mils) Delis also asf in debmgzng and general fo contol /making an LED blink ‘rently cue Tew a fst tr oa spear he eure testom of hewindow, These are messages that makeiteasier fo ndersand the “Ths program sth first code orm that tests that your Arduino boas working Froccashascouleted cored and conigired corey. ype the following et it sour Arun or ‘There a2 L&Ds marked RX and TX on he Board they Mash everytime byes sent or esi by the ber. During dood process, the Keep ficken |Fthis dant happen it meanethere are some communist problem oro (1 Sisnkiog U9 - haven slects eit por inthe Tooke / Sal Port mer acini 1 Sigal pa MTGNB ech menieG non heb acen nit void setupt) pinwode(iedrin, cure; // sets the aisitel 11 pin as eutpse 7 votd Leopt? cigstalliritetledPan, HIGH); // turns the 12D on Setay (1000); Hy saite for 3 second Gigieaideive(teavin, Low); // turn the Lab ofe ‘Now thatthe codes in your IDE you need to verify itand uplad it to the board. Pres “Vor adi everthing eoreet youl se tis messige appear at the baton ofthe prouram text: At this pint yu can upload itinto the board Pres the rect button onthe “Arduino board, thisfores the board t step what is ding and listen far instrctiane coming fom the USD por. Nov you have abou 6 scant press the "Upload 29 1/0 Boar button. /what is electricity? you've ever done any plambingat home, understanding letronies vont be prober for sot In aero understand No electri a elect ets work ‘ell we a mental mode! called the “water analogy” ‘Tostat with, t's look at a simple device ke a portable fin. you were to take apart sol se ha conan a small batter, a wires soi oan electric motor one of which is imerpted ya site, Make sure you havea new battery ited ito the device and aetvate these the mor sans tospin ow does this work? Imagine tha the battery isa water pump and the site ca tap wile the motor one of thee whels in water When you open the apy ‘eater lows from th pump and pushes the whel into motion, In thissmplesstom two rameter are important: the pressure ofthe water (etermined show powe-l the pup 6) ad the amount of water tat ext Howe Inthe pipes determined ty thesia ofthe pipes and the resistance thatthe wheel ll oppes the stream of water iting i. Ifyou want the wheel 10 spin faster, you need toineease the sof he pipes and Jnerease the pressre that te pumpean achive Inereasng te sie ofthe pipes Allows more varert ow trorgh them, and by mang then tere ese the resstanc they opposeto te low of wer. This work tl the whe! wont pin any fatr bees the presse ofthe water ent ston cnouh. This is ‘ven ve need the pun tobe stronger In tur, this works unl the wheel alls apart because the water fli to trong and destroys You notice that asthe wel ops fase, the axle wl heat up a Title bt No water hw well we mount the whee, the ction between the axe sind the oles is monnsed in il generate het le'simportantto understand thatin system ike this, ntl the energy you ‘ump into the system wil be converted into movement Sonne fil be st na ‘umber of neicieneies (generally as heat emanating from some parts ofthe stem). ‘The importa psi of ths system are sbezefor: the peste proce bythe up the este that ‘he psa whee oppseto Use ow of water and the cual Mow ofwater (represented y the nunnber of ies of water that Mw in obe Sond. ‘lett works in sini fashion: any sour of ety tea batery ora wal pla ese a kind of pump that pases eet ears (ike “dep? lect) down wires (similar othe pipes) whee some devices ae alle to se ‘them to produce heat Gor grandma's thermal lank) ight (jour becooms Tamp) sound jour stereo) movement {our fan) and mach more Furthermore, hen 3u read on abate “9¥" imagine the voltage ofthe battery Tike the water presse that can be pte prc by this tle “pamp"- This Isimeasured in Vols om Akssindto Vlla, he lventr ofthe st tery “The fow of water hasan electric equivalent called “curent” satis measured Ampere (fom Andre Marie Amp), Finally the resistance opposed othe flow of curent by any means travels tough calla “reshance, messed n Ohms (rom the Geran pssst (Georg oi. He was alo ableto demonstrate than tei, the voltage" the “eument and the resistance” areal lated to each other. The resistance opposed bythe ‘reits determines the act of rest tat wl lw though give certain ‘pplseotnge Going bck to ou analogy, given a certain pump and assuming tap hich we ‘an assimilate toa variable reistorin lotic) the more I cose the ap Increasing estes ower Hote less afer wl ow through eps. 8, Ifyou take a 9V battery ad plug it into simple ccult while measuring curren, ‘you wil ind hat the more resistors you addto the cel he ess cure il, travel tought ‘Mr Ohm summarise his aw int this formal: R(vsistane) = wcltage) / (current) reve “Thisis the only rule that you realy have to iemorse and learn 1 use. 6 /the breadboard ‘The proes of geting a eel to works largely asd on making ots of changes toltunsit behaves prope sis. er fat terative proces that could bese a8 {he electroniceuvalentfosetching The design evoles in your hard 85 you ty ‘ferent comsinations In onder to achive the best results you need owe a ‘stem that willow you change the connections Deween components nthe fasts, most practical and non-destructive wa ‘This requirement rules out soldering, i's time-consuming proces that puts ‘every omporent unde tress everytime ou eat tem up ad eoo then dow The answer this issues the ery practical device ale aSolderess Breadboat . WE GEER AN, Itisasinall pic board fll ef oles, ach one of thom containing a pring Joaded contac. When jou push aeomponentsleginto cof theses hoes t establishes a lee eoneeton thal the ot holes in the same verte] column. ach hole i at distance of 2.34 mm from the oer, since most the ‘components have the gs (ls known a pins) spaced at that standard ‘stance. Thisis very practic fr cigs with nail eg [Ntalhe contacts on a breadboant are crested eqeal.The topmost an bottom row (coloured in red and blue and aptly marked wth + and -) are connected horizontally and are wed to carry the power crs the beard so that when we reed power or round we an pve vers ak with short jumper this is hhta sweater oa funny sect uta short plese of wie used to cone! 0 ols inthe dre) Akitionaly inthe mide there is a are gap thats as wide asthe sia ofa small, ‘hip This isto indicate tit each vertical line of hese interrupted in ‘he mide “othat wien sou plan achipin, sou won't shot cit pins tat are onthe wo ‘sldesor the chip. "7 /reading a pushbutton Nowe see how Aino reeves input fom the external word “Thishappeas wth the digtalendQ function which, shen given the number of ia, wl el oui there sa voltage applied to tf the voltage 25 or more ‘ols digialResdQ il return HIGH wile ere sn voltage wil ur, tow. ‘Thiscove checks the state ofthe digital pin and tm onthe LED ifthe buttons pressed To et started quick bul the circuit yo se belo. 8 (J+ Blink LED when che mutton is pressed “ ant 1ecein = 13; // chooge the pin tor the LED int infin'= 7) // choose the input pin 17 (for a pushiboteen! }/ voriabie for reading the pin atscue int val = 9) void seeupt) { indode(ieaPin, ovzear) iMede ania, INEOT) 1) aaciave LED as ourpue 17 declare pushbutton ae snput void 1eoptt{ Eearpeeno etteeeat ete a eae erecta 1/ check L€ he input sa HIGH (button released) 4 (yar a= ra Gieitalweive(edpin, vow); // turn LED OFF } lee [ 1/ bilo che LAD and go OFF Gicitalwritetledrin, HIGH); ‘elay 200) sestalWriveteapsn, Loe: ‘delay (2000) /drawing a schematics diagram Sofar, we have used yer etal istrations to describe haw to assemble ‘ret Hownve, ath lng rs, drawings aren the mest eent wy 40 ‘document your experiments "gingers hve developed a quick way to capture the essence of ict to be able todocument rand ruil later on. Schematics dagrans allow yu to deserbe ‘your ereuitin away thats understonby the restfthe community a5 Well Ingividuel components aro represented by symbol that area sort of absration of the the shape ofthe component or he esence of then Herearea few examples: ‘Acspacor is made of two metal plates separated either by ror paste therefore tonmel a = ‘An nut thats aul by wlnding copper wite around cling shape ‘consequently the ymbol aa ‘The connesions betneen components are usually ade using iter wires or tracks on the printed creit board and they are represented on the diagram as ‘Simple ies, When two wires are connected this srepresented by peng 4B, other thetwotines eras. “Thisis all you need to understand base schematics. You wil nd ‘comprehensive list oso on hp una Ape rculscom synbotin. “The symbols this booklet are commonly usd in Europe. In the USA however, some symbols have a slightly diferent shape, bat ar ileal recognisable, Conventionally; youshould aways draw diagrams from eft to right as showin this diagram of the pushbuton eeu you have just put together. + 5vots 10k / other on & off sensors ‘Now that youve ued the push-button sou can epee it with aloof alent ‘sero that ave the ste type oF outta that lous ad opens. (One good example is the it sensor. This sa simple electronic component that ‘contains two contact rl ile metal bal ‘When the sensors ints upright postin the bl bridges the two conte and lik whon sou pres the push-buton Wen yout thie sensor the ball moves and ‘the contac is opened like when you release the push-button. Using thssimple “component yx can implement for example, gestralnefaces that reacts to ‘when an objets moved shaken, _Anothe sensor you might want to try ithe infrared sensor fom bangla alarms (alsoknownas PIR sensor) “Thssal device riggers when a human being is movingin ts proximity. It's a ‘simple way to detec the presence of people Ws gad toenpinent looking at all he posible dees that have two contacts that os, the thermostat thats used in apartments ost the room tempera ral to iene scat oer and oping 20 / using a light sensor Thisis an LOR orlight dayendeot resistor: Inthe dat, ts resistance site igh ‘se when tis exposed tight, the resatane uk dope and lens 3 ‘reasonably good conductor af etsy Replace the pash-utton by the LDR and ou wll notice that ifyou cover or ‘eoveritwith your nde the LED is timeon an oY jst bat your fist sensor driven LED. / analog inputs -Asscentn the previous setion, Arduino can detet if there voltage spl to ‘oe ftps and reports ehroh the digtallead faeton- This woo or alo ‘of aplistions, bt the ight sensor that we have fst used can tell ust ust iF theres ight oot, Ba asofow muh it theres “Thisis the difference betwen an oof sensor (simpy telling wf somethings ther or not and an analog sencor whose vale continictsy angen ode toreadthistype of ensors we need a diferent pect pi. In the lower ht part ‘of Arno yl se 6 pins marked “Analg In ese are special pins hat noe ‘nly can ell sf theresa eltage applied totem or not but also tab. ‘By using the analgend) function we can rad the yltage applied 1 enecf the pins. Thiefincton retires number tetwoen and You representing voltages between oand 5 volts Fr example fthere isa voltage of2 volts applied opin rupabe o,analouRead() wl turn 512 et, you now bul the eel that you se nthe tstraton by sing a 10K resto tnd ou run the pee of ede inelued yu ae the ed linking att that ‘pendent onthe amount of ight that its the sensor. a 17 age sensative LED sae val = J warsabie to store the valve {1 coming fom the eanaor vata aetup() pinmbdel1s, obTPUN; // ledpin 1s ae an OUTeUT J/ ze0d the value frou {/ the sensor aigicatweice(s3, uiah); // turn the LED on selay wally U1 stop the program cor 11 nome tine Sigicatweite(s3, Low, “// turn the LED off olay (va 17 stop Om yrosean Cor 1 none time ) / other resistive sensors Using the sme cre tat you have sen nthe prvous ston ou cen const ‘Tot of other restive sensors that work more erlessin the same way For ‘exanple yout could comeet a thermistor. “Thisis a simple device whose resistance changes with dhe tmperature.ta the ‘ret we lve shown yes, changes eistanc Doce changes in volage that ‘ean be measuredby Arduino. ‘Be aware that there it a dict elationship between the valve you reid andthe ‘cua temperature measured. Ifyou need an exact reading, you shouead the ‘humbes that come out ofthe analogue pin wile measuring with real thermometer. You ould pu these numbers Se by skein ableand work out the relationship between the ales ‘Until no, we have as used an LED asa ntput device but bow do we read the etal ais that Ardine reading rom the sera? oe tis poe, we ‘an ue Serial Communication hat i deseribed inthe next chapter / serial communication ‘At the ginning ofthe bot; you might have notice that Arduino hs USB “Type this code into ane eketh: ‘conection thi iswsed by the IDEto upload eee to the processor. int tengorPin = 0; J eeiect the input pin for the 17 pocent caster 17 coming from the sensor weld sett) Serial bepia (Se {] open thee oncial port to anna) 1) data Bock vo the corputer st 71 9600 bits per second yoxa 1o0p (0 { Ysl= snslogiasd(senacrPin); // rasd the value from Uf the sonar Sersa1_printin(val) if print the velve to U1 She gerist port ae.ay\u0U) ; Ackitionaly this connection ca als be wed by the prosras we write Now thatthe argram is ranning you should pressthe “Serial Monitor” button on ‘Aruino to Send data ack tothe compar or receive com>-mars omit ‘the arduino IDE and you see te rumbers ing up inthe bottom pat ofthe ‘window or this purpose, we ae going tose the Sees. This object cons al the “Any software that ean red rem the ial port can talk to Arduino now ‘code we ne to send and reve data ‘We're now going to use the last eireut we have built using the the thernistor and send the values ead back tothe compe 23 / analog outputs \With what youve ean 2 fr, sou oul take wp the as of baling a0 Interactive lm, amp that cant conrad no jst than cro itch et snasbe wth litle poet (neo the intations ofthe blinking LED examples we have sen sof is that yostean aly turn on ado the ight while fancy interactive lp needs tobe Aleta dim the ight proper: To solve this problem, we can ise arc that is ‘sed in'TVorcinoma: persistance of sion. In theirs LED blinking example x08 made, change the ners in the delay fneton uti you can't se the LED Winking ame Yow observe thst the LED stems to be dimmed at 508 oft normal rightness, ‘Now change the numbers o thatthe time the LED ison sone forth oe time itSoff Run the program and youl see the brightness roughly 25%. “This echnique scaled Pulse Witt Medaltion (PMD, which meansthat thatf 01 blink the LE fast enough ou dons ink anymore butyou ean change itslvghtesshy engin erate teen the on tne athe of tine. Heres ‘all diogram honing bow thi waa. PRM “Tie technige alo works with other devises. For example you can change the speed of meter inthe exacsame way. While experimenting, youcan se that inking the LED by hand s tightly inconvenient cats as soon as you want to read a sensor or send data on the serial por the LED wil flckr. Fortunately te processor asd bs the ANing Boar has 3 pee of barre tat can ery efficent link ¢ LEDs wile your program does something ele This is implemented by pin 9, xoand 11 that ean be controlled by the anaogWrite) ‘Writing analegrte(,128) wl seo S0% the brightness of an LED connec ino. Why 128? beesine analogs expect numer between © and 256 a8 parameter where 255 means 100%. Having chapels very good because you buy rd, geen and lve LEDs you can make light of any cou you The! This LD isadiode (Galt paitn ‘Seria oan) / driving bigger loads ‘ach pin on an Arduino boa ean be wed to power sis that we upto onan eich sa very sal amount of current, just enough to deve an LED ‘nd not eh more. you to drive something ikea mctrthe pin wlimmetely stop working tn il poorly arn the whole processor. “Todkive bigger loads like motors or incandescent amps we need owe an ‘extemal component tat ean site sic things on and off while being riven by ‘Arduino pn. One o sich devices Iselled a MOSFET Transistor whieh san ‘lectroni sich that canbe driven by applying volage tone ofits thee pins called "gate tea be sen asthe ight switch we use at home where the action that our finger oes tur the lish and ff replaced by apn on the Arduino boa sending ‘kage tothe ate" ofthe MOSFET. {nthe following pieture youcze how you would we a MOBEET ike the IRF520t0 tur on and of sal motor attached to fn, ‘You wil aso notice thatthe motor takes its power supply fom the 9V connector ‘onthe Ari board, which sanother benefit ofthe MOSFET: it allovsus to ‘rivedeviees that havea power supply different from the one used by Aino, Sine the MOSFET is connected opin 9 we ean also se angle conte the pee of the motor through PN 25 / complex sensors We define “complex sensors asthe ones that reduce a typeof information that requires more tha dgtalRead0 or analogfesd) to be ud. These are ‘lly sal euits that have already a stall mlcroconvler ine that pre- Drocesses the information. \Weveilustrated 9 tpescf sensors below an Utrasonie Range, an Inared Ranger and an Accecromtor. Youcan find examples on how to se them at ape/fuwwambn.ceen7Paorial/HomePoge 26 / talking to software In this section we wil show you how to use the data sent bys Arduino oan through the USE port fa plee of steare runing in your computer {J virtual Btoh A Sketch vaing 2 Potentiometers ‘This program roads two anslog senacra vis serial and drawn heir volves 90 % and Y Processing Code by Christian Nold, 22 Feb 06 “ Inport pronasaing serial. String but =" String tanp =" Float temporary = 0.0; float screenideh ~ 6.0 float xcoorainate = 0, lost yeaorasnate = 0) Serial port; vyold setup) c ss170(200, 200), SSerokeWesaht (10); // fat sroke 2681) smooth) Ore = new Gerla (hie, 2) | oft = bose supsesieg|9, butt 2ongehl)-1); Soe pl = Batfindexot(""); // find comm’ 11 poe evecyening betare the couna into a temp variable tanp = bute-aupseeieg(0, pil 77 worn tha pring isto & floating polat nunber emutay © Cua. (vel 11 emouiace x position coordinate ~ widen’ (202¢/temporary): Trocine ae aaa debugging pesnein eCoordinate: 1/ do the sane with the test after che coma temp + butt eubstringip + 1, butf.length()); temporary = float IteNel yooorsinate = heiaht/(1024/cerporarn ; Brintin iycoordinate: + , U/ Clear the value of “bute wees ) Find out more Apart rom the obions Arduino ite, har ate a few sites that might be wef as ‘sou get deeper into the woeld of interation design ad psa comping, tp/fet.com/bo9/ Intp/fere.cerfroaks.net/ tp eicio.ws/popular/ nding apf dyna nap/frr.arduin.ce/n/Main/ArduinoBoardityPad 28 Appendix chematics diagrams Yow ind hee ll the schematics diagrams fr ll the curt built inthe booklet ‘avs hem loads Q+Vin Restor k ‘rom aio mas é [= mrsxo tearing l= rs - J Noster Pay oxo ere ox te Ardsino nabs 0 30 B: reading resistors & capacitors Inorder to use electronic pats, you should be able to Went them whieh can be iia a foe a beginner oat ofthe resistors you wil find in shopstave a body ith two ees ticking out and coloured makings all around hem ‘When the ft commercial resistors were made there mas no way opin numbers small that they wou on thei body so engineers cided that the could just. represent the vales wth strip of coloured pant. “Tada beginners veto figure ot away tonterret these signs. ‘There isquiteshnple, generally you wl a4 strips and each cow number (One ings is usually gold” whlch represents the precision of tat pace that to ‘height hand sid, read the colours and map them othe mimbers Forexample brown, black, orange and old markings mean 03 25% Bas ight? ‘ites because there isa twist the tir ing represent the numberof oes inthe “ale therefore 103isactally 10 pls 3 zeos so the en ese 10 000 Ohms "Hlectronis gees edt shorten values by expresing them in Kil Oh Ohms) td Mega Ohno (ilion of Ohm) 20410000 chm rato wal 010k. Please note that, since engineers are fend f oping everthing, on eremaic > fam un Et Et Bom — = St ame wo et am ret)? (> ean o =: i: wie Js Cs —_ 3 [7 a

You might also like