Hardware Reference
In-Depth Information
continued
YoucanuseOhm'slawtodecideonaresistorvalueforthiscircuit.
AssumethatthisisastandardLEDwith20mAforwardcurrentanda2V
dropacrossit.Becausethesourcevoltageis5Vanditendsatground,a
totalof5Vmustdropacrossthiscircuit.SincetheLEDhasa2Vdrop,the
other3Vmustdropacrosstheresistor.Knowingthatyouwantapproxi-
mately20mAtolowthroughthesecomponents,youcanindtheresistor
valuebysolvingforR:
R=V/I
WhereV=3VandI=20mA.
SolvingforR,R=3V/0.02A=150Ω.So,witharesistorvalueof150Ω,
20mAlowsthroughboththeresistorandLED.Asyouincreasetheresis-
tancevalue,lesscurrentisallowedtolowthrough.220Ωisabitmorethan
150Ω,butstillallowstheLEDtoglowsuficientlybright,andisaverycom-
monlyavailableresistorvalue.
Anotherusefulequationtokeepinmindisthepowerequation.Thepower
equationtellsyouhowmuchpower,inwatts,isdissipatedacrossagiven
resistivecomponent.Becauseincreasedpowerisassociatedwithincreased
heatdissipation,componentsgenerallyhaveamaximumpowerrating.You
wanttoensurethatyoudonotexceedthemaximumpowerratingforresis-
torsbecauseotherwisetheymightoverheat.Acommonpowerratingfor
resistorsis1/8ofawatt(abbreviatedasW,milliwattsasmW).Thepower
equationisasfollows:
P=IV
WherePispowerinwatts,andIandVarestilldeinedasthecurrentand
voltage.
Fortheresistordeinedearlierwithavoltagedropof3Vandacurrentof
20mA,P=3V n 0.02A=60mW,wellundertheresistor'sratingof1/8W,or
125mW.So,youdonothavetoworryabouttheresistoroverheating;itiswell
withinitsoperatinglimits.
ProgrammingDigitalOutputs
By default, all Arduino pins are set to inputs. If you want to make a pin an
output, you need to first tell the Arduino how the pin should be configured.
In the Arduino programming language, the program requires two parts: the
setup() and the loop() .
As you learned in Chapter 1, the setup() function runs one time at the start
of the program, and the loop() function runs over and over again. Because
you'll generally dedicate each pin to serve as either an input or an output, it is
 
Search WWH ::




Custom Search