Transcript
Page 1: Model Railway Animation: Part 1, LEDs - Expanded By David KingModel Railway Animation: Part 1, LEDs - Expanded By David King By now you are most likely ready to proceed past the simple

ModelRailwayAnimation:Part1,LEDs-ExpandedByDavidKingBynowyouaremostlikelyreadytoproceedpastthesimpleBlinksketchsothatiswhatwewilldonow.Acoupleofsimplesketcheswecancreatewillbetosimulateasimplegradecrossingflasherandatrafficlight.AquicknoteabouttheLEDitselfisthatyoumayhavenoticedthatitmaynothaveworkedforyouatfirstandthereisapossiblereasonwhythismightofhappened.TheLEDsinkitshave2leadswithonebeinglongerandtheothershorter.TheLongleadistheanodeanditneedstobeconnectedclosesttothe+5voltpowerandtheshortedleadisthecathodeandshouldbelocatedclosesttothegroundconnection.Wealsousearesistorconnectedfromtheanodeto+5voltsorfromthecathodetoground.Itdoesn’tmatterwhichlocationtheresistorisplacedinthecircuitjustaslongasitisinthecircuit.IfatfirsttheLEDdoesn’tlightchecktoseeifyouhavetheLEDwiredupbackwards.IfitisbackwardsremovetheLEDandturnitaroundtoswapthoseleads.WhenusingaLEDwiththeoutputofArduinoUnoitisokayto1or2LED’stoasinglepin.Theoutputfromeachpinhasamaximumratingofabout40milliampsandeachLEDconnectedcandrawupto20milliamps.Asyoucanseeifyouconnect2LEDstoasingleoutputyoucouldbeatthelimitforthatpin.Withallofthatsaidthereisawaytoconnect2LEDstoasinglepinthatonlyusesthe20milliampsandnotthe40milliamps.ThiscanbeaccomplishedbythewayweconnecttheLEDsinthecircuitbyconnectingtheLEDsinparallelorseries.Thisimageshouldhelpmakethisalittleclearer.

Page 2: Model Railway Animation: Part 1, LEDs - Expanded By David KingModel Railway Animation: Part 1, LEDs - Expanded By David King By now you are most likely ready to proceed past the simple

TheGradeCrossingFlasherThegradecrossingflasherisjustapairofLEDsorsetsofpairsofLEDsthatneedtoflashatasetrateofspeedandeachLEDpairmusthaveoneLEDonwhiletheotherisoff.ThisisthealternatingpatternofLEDsthatwewant.Intherealworldthisalternatingflashinghappensataboutarateof1/3rdasecondforeachoftheLEDs.Thisisthetimethatwewillusetokeepiteasy.Yourcompletedsketchwouldbesimilartomysketchshownbelow.

InthissketchitisjustamatterofadjustingthetimesfromtheoriginalBlinksketchandaddingtheadditionoutputsforbothpinModeanddigitalWrite.AsseeninthissketchIhaveconnected4LEDstotheArduinoUnojusttokeepthewiringverysimple.ThereareothermethodsofwiringtheLEDsbutthisissimpletounderstandandeasytoconnect.IhavecreatedaFitzingdiagramtoshowyouhowtoconnectthewirestotheLEDsalongwithusingsomeresistors.RememberthattheresistorvaluesthatweresuppliedwithyourkitmyvaryslightlyfromtheonethatI’musinginthediagrambutthatisokayaslongasthereareinarangeof220to560ohms.

Page 3: Model Railway Animation: Part 1, LEDs - Expanded By David KingModel Railway Animation: Part 1, LEDs - Expanded By David King By now you are most likely ready to proceed past the simple

TheTrafficLightThebasictrafficlightthatweseeoutintherealworldisaverysimpledevicethathas3lights,red,amberandgreen,withonesetfacingthenorthboundtraffic,onesetfacingtheeastboundtraffic,onesetfacingthesouthboundtrafficandasetfacingthewestboundtraffic.Inmostcasestheeastboundandwestboundtrafficlightsetsworkinginthesamepattern.Aswellthesouthboundandnorthboundtrafficlightsetsworkinginthesamepattern.Wecancreateasimplelittlecharttodisplaythispatternandmakeiteasiertounderstand.InthechartIusedNSforNorth/SouthandEWforEast/West.AlsoIaddedanextrarowatthebottomofthechartsothatIcouldusethisforthepinassignmentsonmyArduinoUno.

Step

NSGreen

NSAm

ber

NSRed

EWGreen

EWAmber

EWRed

Time

1 On Off Off Off Off On 25sec.2 Off On Off Off Off On 7sec.3 Off Off On Off Off On 1sec.4 Off Off On On Off Off 22sec.5 Off Off On Off On Off 6sec.6 Off Off On Off Off On 1sec.

UnoPin 7 8 9 10 11 12

Page 4: Model Railway Animation: Part 1, LEDs - Expanded By David KingModel Railway Animation: Part 1, LEDs - Expanded By David King By now you are most likely ready to proceed past the simple

Asfarasthesketchgoesthisisjustandextendedversionofthesketchweusedforthegradecrossingflasheranduses6outputstorunalloftheLEDs.BesuretoassignpinModeanddigitalWriteforeachLEDinyoursketch.Oncecompleteyoushouldhaveasketchthatlookssimilartomineshownbelow.

Page 5: Model Railway Animation: Part 1, LEDs - Expanded By David KingModel Railway Animation: Part 1, LEDs - Expanded By David King By now you are most likely ready to proceed past the simple

TheFritzingorwiringdiagramshouldlooksimilartotheimagebelow.

Page 6: Model Railway Animation: Part 1, LEDs - Expanded By David KingModel Railway Animation: Part 1, LEDs - Expanded By David King By now you are most likely ready to proceed past the simple

ConclusionThisshouldhelpyoucreateafewmoresketchesfromitemsthatyouseeoutoneverydaylife.Asanexampleifyoumodelrailroadlayouthasawharfmaybeacoupleofnavigationlightsatornearthedockshouldbeadded.Youcouldresearchtheflashingpatternandcolourrequiredforeachoftheselights.Alsothereareotherwarninglightsthathavepatternsthatarenotsimpleon/offcyclesuchasthered/bluelightsofapolicecar.HavefunandcheckoutthevideoandwewillcontinuethisadventureinthenextissueofTheCanadian!


Recommended