STEMInnovator! Hello, STEMInnovator! STEM Innovator!STEM Innovator!
Welcometoyourbook! Welcometoyourbook!
Youarea YouareaSTEMInnovator STEMInnovator..AnInnovatorisaProgrammeranda AnInnovatorisaProgrammeranda Scientistwhousestext-basedcodetoanalyzetheworldandbuild Scientistwhousestext-basedcodetoanalyzetheworldandbuild smartsolutions! smartsolutions!
MeetYour MeetYourRaspberryPiPicoKit RaspberryPiPicoKit..Insideyouhave: Insideyouhave:
TheBrain: TheBrain:TheRaspberryPiPico,ahigh-performancemicrocontroller TheRaspberryPiPico,ahigh-performancemicrocontroller tthatrunsrealPythoncode. hatrunsrealPythoncode.
TheTools: TheTools:ThonnyPython,theprofessionalsoftwareyouwilluseto ThonnyPython,theprofessionalsoftwareyouwilluseto write,test,andrunyourprograms. write,test,andrunyourprograms.
TheLaboratory: TheLaboratory:AdvancedBotanical,Temperature,andDistance AdvancedBotanical,Temperature,andDistance sensorstocollectdatafromtheenvironment. sensorstocollectdatafromtheenvironment.
IInthisbook,youwill: nthisbook,youwill:
EngineeraPredatorDetector EngineeraPredatorDetectorttouseinfraredlightandkeepyour ouseinfraredlightandkeepyour surroundingssafe. surroundingssafe.
DesignanEarthquakeBrace DesignanEarthquakeBracettolearnhowsmartstructuresprotect olearnhowsmartstructuresprotect peopleduringnaturaldisasters. peopleduringnaturaldisasters.
CreateanAste CreateanAsteroidDistanceSensor roidDistanceSensorttoexplorethemysteriesofspace oexplorethemysteriesofspace usingultrasonicwaves usingultrasonicwaves.
EarnYour EarnYourRewards! Rewards!
AsyoumasterPythonsyntaxandcomplexelectronics,youwillearnyourExpert AsyoumasterPythonsyntaxandcomplexelectronics,youwillearnyourExpert IInnovatorStickers nnovatorStickers.
Attheendofthisbook,youwillreceiveyour Attheendofthisbook,youwillreceiveyourCertificateofInnovation CertificateofInnovationiinComputer nComputer Sciencetoshowtheworldthatyouarea SciencetoshowtheworldthatyouareaMasterofPythonProgramming! MasterofPythonProgramming!
Let’sdesignandprintthefuturetogether! Let’sdesignandprintthefuturetogether!
Thiskitbridgesthegapbetweensoftwareandhardware. Inthislevel,youwillusetheRP2040microcontrollerto buildresponsiveelectronicsystems.Youwilllearntowrite codethatcontrolssensors,displays,andmotorstosolve real-worldproblems.Bytheendofthiscourse,youwill understandhowmoderntechnology'thinks'and'acts'.
Yellow LEDs x5
Red LEDs x5
Green LEDs x5
LEARNINGOBJECTIVES LEARNINGOBJECTIVES
Attheendofthislesson,learnerswillbeableto:
IdentifythemainpartsoftheRaspberryPiPico
Explainwhatamicrocontrollerdoes LocatepowerpinsandGPIOpins
InstalltheThonnysoftware
PreparethePicoforprogramming
VOCABULARY VOCABULARY
MATERIALS MATERIALS
Apinusedforinputoroutput
Asmallcomputerthatcontrolsdevices
WHATISTHERASPBERRYPIPICO? WHATISTHERASPBERRYPIPICO?
TheRaspberryPiPicoisasmallcomputer Itiscalledamicrocontroller
Itisthebrainofyourproject.Itcan:
IIMPORTANTIDEA MPORTANTIDEA Readsensors
Ineveryproject:
LOOKATYOURRASPBERRYPIPICO LOOKATYOURRASPBERRYPIPICO
Findthesepartsonyourboard: USBport 3V3pin GNDpin GPIOpins BOOTSELbutton
TheUSBportconnectstoyourcomputer. TheGPIOpinsconnecttosensorsandmotors
IIMPORTANTIDEA MPORTANTIDEA
GETTINGSTARTED GETTINGSTARTED InstallThonny
1.Openyourwebbrowser.
2.Goto:
3.DownloadThonnyforyourcomputer.
4.Opentheinstaller.
5.Followtheinstructions.
6.OpenThonny.
7.SelectEnglish. thonny.org
Everyelectricalcircuitneeds: Power GPIOpinsuse3.3voltsonly. Ground WithoutGround(GND),the circuitwillnotwork. Neverconnecthighervoltage Thonnyistheprogram whereyouwritePython code
1.UnplugyourPico.
2.HoldtheBOOTSELbutton.
3.PlugthePicointoyourcomputerwhileholdingthebutton.
4.Releasethebutton
InstallMicroPython NowthePicoisinbootmode.
1.InThonny,lookatthe bottomrightcorner.
2.SelectMicroPython (RP2040).
3.ClickInstallMicroPythonandwaitforinstallationtofinish. YourPicoisnowreadytorunPythoncode
2.WhatdoGPIOpinsdo? STOPANDTHINK
1.WhatistheRaspberryPiPico?
INTRODUCTION
Plants,likeanimals,needwaterandmineralstosurvive.Whenwaterispouredon plantroots,itisabsorbedinroothaircellsandtransportedthroughxylem,oneof twotransporttissuesinvascularplants.Thenittranspires,orevaporates,from thesurfaceoftheleavesthroughstomata.Humiditysensorsreporttheamount ofwatervaporintheair,whichcanhelpbotanistsdecideifplantsaregetting sufficientmoistureforidealgrowingconditions.Incolderclimates,agriculturists usegreenhousestocontrolenvironmentalfactors.Ingeneral,greenhouses shouldbekeptbetween26°Cand29°Candaround80%humidity.Itisimportant tomonitorthesequantities,ascoldplantscanfreezeandhotplantscanwilt.Low humiditymaypreventwaterabsorption,andtoomuchhumiditycanresultin pestsandpathogensgrowingontheplants.Toensureoptimalgrowing conditions,greenhousetemperatureandhumiditymeterscanbemadeto measurethesevalues.
DEFINETHEPROBLEM
Twofriendswanttobuildatemperature and humidity meter to verify that their greenhouse has the right conditions for idealplantgrowth.Canyouhelp?
MEASUREYOURSUCCESS
Yourgreenhousetemperatureand humiditymetershould:
Displaythetemperatureand humidityreadingstotheserial monitor
ShowthereadingsontheLCD
TEAMROLES
Yourgreenhousetemperatureand humiditymetermust:
Useonlythematerialsprovided Includedesignideasfromevery teammember
Workwithyourteamtodeterminewhowillcompleteeachroleforthisproject.
ProjectManager
ResourceManager
ProjectCommunicator
ProjectTester
MATERIALS
VOCABULARY
Reviewthefollowingvocabularytermsandtheircorrespondingdefinitions,which youwillencounterthroughoutthischallenge.
Anelectricalcomponentthatmeasuresandreportsavalue
Ascientistwhostudiesplants(alsoknownasabotanist).
GETTINGSTARTED
TECHNOLOGYINFOCUS
LocateyourRaspberryPiPicowiththepinsfaceupandfind thefollowingports:GND,3V3,andGP16.
3V3isa3-voltpowersource.Thisportwillsupplypowerto yoursensor.
GNDisagroundpin,meaningitsendselectricitybackto theboard,completingthecircuit.
GNDisagroundpin,meaningitsendselectricitybackto theboard,completingthecircuit.
GP16isageneralpurposepin.Inthecode,itwillbesetto“input”soitcan readsignalsfromthesensor.ThePicowillthensendthesignalstoyour devicethroughtheUSBcable.
Part1:Printtemperatureandhumidityvaluestotheshell.
WIRE
Step1:PlacetheRaspberryPiPico facedownintheprototypeshieldonthe leftside.Makesureeachpininsertsinto itsrespectivehole. Theshieldmakesit easiertoconnectcomponents.
Step2:FindtheS(signal)portonthesensor.Putthefemale endofthewhitewireontotheprong,andconnectittoGP16.
Step3:FindtheV(voltage)portonthesensor. Putthefemaleendoftheredwireontothe prong,andconnectitto3V3.
Step4:FindtheG(ground)portonthesensor.Put thefemaleendoftheblackwireontotheprong, andconnectittoGND.
Note:ThereareseveralGNDportsonthePico The sensoronlyneedstobeconnectedtooneofthem. ThisallowsthePicotogroundmultiplecomponentsatonce
Step5:PlugthePicointo yourdeviceusingtheUSB cable Ifyourdevicedoesn’t haveaUSBport,youmay needaUSB-to-Lightning adapter.
Tip:Thedirectionofthesensorpinsmayvary Alwaysreadthelabelnexttoeachpinon thesensortomakesureyou'reconnectingittothecorrectportontheboard.
Step1:OpenThonny.
Step2:ClickView-> Filesinthetopleft corner.
Step3:NavigatetoDocuments/Grade9RaspberryPiPico Projects/Projects/Project 1 Temperature and Humidity.py.“.py”isthePython extensionusedforallofourPicoprograms.
Step4:SelectMicroPython (RP2040)inthebottom right-handcorner.
Step5:UploadthelibrariesinthefoldertoyourPicoby right-clickingondht11.pyandselecting“Uploadto/”. Repeatthisforthelcd128 _32.pyand lcd128 _ 32 _fonts.py,aswewillneedthemlaterto displaythereadingsontheLCD.
Step6: Clickthe“Run”buttonandreadthe temperatureandhumidityvaluesprintedtothe shell.Whathappensifyouchangethenumber intime.sleep( )andclick“Run”?
Part2:PrintingtemperatureandhumidityvaluestotheLCD.
Step1:Findthe“SCL”pinon theLCDandconnectittoGP21.
Note:theLCDwillbeblank untilyouhaveuploaded theProject1bcode. (LiquidCrystalDisplay)
Step2:Findthe“SDA”pin ontheLCDandconnectit toGP20.
Step3:Findthe“V”pinon theLCDandconnectitto VUSB.
Step4: Findthe“G”pinon theLCDandconnectitto GND.
Tip:Thedirectionofthesensorpinsmayvary.Alwaysreadthelabelnexttoeachpin onthesensortomakesureyou'reconnectingittothecorrectportontheboard
Step1:OpenProject_1b Temperature and Humi dity Meter.pyinThonny andclick“Run”.
Step2:CheckthevaluesontheLCDscreen.Are theconditionsinyourenvironmentsuitablefor idealplantgrowthinagreenhouse?
Writethecodetocheckifthetemperatureandhumidityareintherangeof theidealplantgrowthbasedonyourresearch.Indicateonthethirdlineof theLCDiftheconditionsareidealornot.
TEST
Gobacktothe'MeasureYourSuccess'sectionandcheckthe boxes.Doesyourprojectmeetallthecriteriaandconstraints?
MATHANDSCIENCECONNECTION
1.Todisplaythereadingseveryhour,whatnumbershouldbeintime.sleep( )?
2.Ifthehumidityreadingsarebelow80%,whatcouldyouaddtoyour greenhousetoincreasetheamountofwaterintheair?
3.AtesterrealizesthatGP16isn’tgivingagoodsignalandhypothesizesthatthe portisdamaged.TheywanttochangetheSwireontheDHT11toGP17instead. Whatlinewouldtheyneedtoupdateinthecode?Whatshouldtheychangeitto?
4.YouwanttosendyourdatatoafriendintheUnitedStates, wheretheyuseFahrenheittomeasuretemperatureinsteadof Celsius.TheconversionfromCelsiustoFahrenheitis:
a. If the average temperature is 22℃, what is the temperatureinFahrenheit?F(22)=?
b.TakeasetofCelsiusvaluesand calculatethecorrespondingFahrenheit valuesusingtheconversionformulain thefunctiontableprovided
C+32 9 5
ThenplottheCelsius–Fahrenheitpairsonthegraphbelow.Drawagraphto showtherelationshipbetweenFahrenheitandCelsiustemperatures.After completingthegraph,explainwhatthegraphshowsabouthowthetwo temperaturescalesarerelated.
1.HowdoesyouranimalgraphhelptheEarth?Circlethecorrect answer.
2.Whichjobstudieshownatureworks?Circlethecorrectanswer.
FEEDBACK FEEDBACK
Completethefollowingsentenceandpracticesayingtoyourfriends:
Showyourprojectto3friendsandcollectstickers!
3.OnewayImademy modeleffectivewas
1.Ibuilta 2.Ithelps
Trytowireandprogramthesolutionyourself Ifyouarehavingtrouble,look attheimagesbelowforguidance.
SAMPLESOLUTION
The code checks whether the temperature and humidity are within certain valuesusingnested“if”loops,thenprintstheresultonthethirdlineoftheLCD.
INTRODUCTION
In the phenomenon known as natural selection, members of a species that survivelongeraremorelikelytoreproduceandpassontheir traits.Asaresult,a species’ predominant DNA changes over time to favor characteristics that improvesurvival.Predatorsandbothalikerelyonavoidingdetectioninnaturein order to survive, whether they are hunting or being hunted. A PIR (passive infrared) sensor, detects movement by measuring infrared light radiating in its environment. If a species can move or hide without triggering the sensor, it may have better chance of survival. An RGB (red-green-blue) LED, or light emitting diode, is an output that can be programmed to change color based on the energydetectedbythemotionsensor.Together,aPIRsensorandanRGBcanbe used to create a predator detector that signals whether a predator is likely nearby.Thissetupcanhelppredictwhetherapredatorislikelytosneakuponits prey undetected, or whether the prey is more skilled at avoiding detection and escapingpredators
DEFINETHEPROBLEM
Aresearchgroupwantstocreatea predatordetectorwithanRGBLEDtotest whethercertainspeciesaremorelikelyto surviveinthewild.Canyouhelp?
MEASUREYOURSUCCESS
Yourpredatordetectorshould: UsethePIRsensortodetect motion.
Alerttheuserusingthecolorofan RGBLEDtoindicatethepresenceof apredator.
TEAMROLES
Yourpredatordetectormust: Useonlythematerialsprovided. Includedesignideasfromevery teammember.
Workwithyourteamtodeterminewhowillcompleteeachroleforthisproject.
ProjectManager
ResourceManager
ProjectCommunicator
ProjectTester
MATERIALS
VOCABULARY
Reviewthefollowingvocabularytermsandtheircorrespondingdefinitions,which youwillencounterthroughoutthischallenge
Asensorthatdetectsmotionbysensinginfraredradiation (heat)initssurroundings.
A component that gathers information from the environment,suchasasensor.
Acomponentthatdisplaysorrespondstotheinput,such asanLED.
TECHNOLOGYINFOCUS
APIRmotionsensorisasmalltoolthatcandetectmovementbysensing changesininfrared(heat)energy.Wecanuseitto:
Part1:DetectmotionwiththePIRsensor.
WIRE
Step1:PlacetheRaspberryPicofacedown intheprototypeshieldontheleftside. Makesureeachpininsertsintoits correspondinghole.Theshieldhelpsmake connectionseasierandmoresecure.
Step2:WirethePIR motionsensortothe
GP2rowonthelower right-handcorner:
Note:Thesewirecolorsmatchthelabeledportsontheboardforeasyidentification.
Step3:PlugthePico intoyourdeviceusing theUSBcable.
Step1:Open
Project_2a_Predator_Detector.py inThonny.EnsurethatRP2040is selectedinthelower-rightcorner.
Then,gotoTools → ManagePackages,searchfor“picozero,”andinstalliton thePico ThislibraryisrequiredforRGBLEDcontrolinPart2
Step2:Click“Run”andwaveyourhandoverthePIRmotion detector.Doesthebuilt-inLEDblink?Doestheshelldisplay “MotionDetected”?Findthepartsinthecodethatcausethese stepstohappen.
Note:Thesensorhasa2-3seconddelay,sotheresponsemaynotbe immediate.Ifnothinghappens,tryclicking“Stop”andthen“Run”again toresetthePico Thenwaveyourhandoverthesensoroncemore
Step3:Lookatline10inthecode.If there’sa#infrontoftheline,it’sa comment,meaningitdoesn’texecute. Deletethe#toactivatethe command.
Click“Run”again.
DoestheLEDinthetop-leftcornerofyourPicoblinkquicklywhenmotionis detected?
Part2:ProgramtheRGBLEDtochangecolorbasedonPIR.
WIRE
Step1:Identifythe longlegoftheRGB LEDandplaceitinto theGNDpinonthe top-leftcornerof yourprototype shield Insertthe remainingthree legsintoGP1,GP2, andGP3,inorder.
Step2:SinceGP2isnowusedbythe RGBLED,thePIRmotionsensormust bemoved.
ShiftthePIRwiresthreespotstothe leftandconnectthemtoGP5’spins:
CODE
Step1:OpenProject_2b_Predator_Detector_RGB_LED.pyinThonny.
Step2:LocatethefunctionsetColor(r, g,b)whichsendsvaluestocontrol thered,green,andblueintensitiesof theLED.NowfindthesetColor() functioninthepir handler()function. PredictwhatcolortheLEDwillchange towhenmotionisdetected Runthe codetoverifyyourprediction.
Hint:TrysetColor(0,0,255)tomakeitblue.
Step3:ChangetheRGBvaluesinthesetColor()linewithinpir_handler()to maketheLEDturnbluewhenapredatorisdetected.Runyourcodetoconfirm thechange.
WhenthePIRsensordetectsapredator,maketheRGBLEDalternate betweenredandwhite.Whenthereisnopredatordetected,turntheRGBLED green.
TEST
Gobacktothe'MeasureYourSuccess'sectionandcheckthe boxes.Doesyourprojectmeetallthecriteriaandconstraints?
MATHANDSCIENCECONNECTION
1.Aftertestingtheirmotionsensor,thegrouprecordsthatcoyotestriggerthe alarm75%ofthetime,whereashousecatstriggeritonly25%ofthetime.If¾a representsthefrequencythatcoyotestriggerthealarm,wherethevariablea standsfornumberofattempts,whatexpressionrepresentshowoftenhousecats triggerthealarmintermsofa?
2.Thoughhousecatstriggerthealarmlessfrequentlythancoyotes,coyotes possesstraitsthathelpthemsurviveinthewild,whereashousecatsare domesticated.Whatevolutionaryadvantagesdocoyoteshaveoverhousecats thathaveallowedthemtosurviveandpassdowntheirtraits,eveniftheyarenot asgoodatsneakingupontheirprey?
3. In a wildlife conservation area, motion alarms are set up to detect the presenceofpredators.Thenumberoftimesnthemotionalarmistriggeredina night is modeled by the exponential function n(t) = 5 x 2 , where t represents thenumberofhourspastmidnight
a. If the motion alarm is triggered 5 times at midnight, how many times will it betriggeredby4hourspastmidnight?8hourspastmidnight?
b.Howmanyhoursaftermidnightwillthealarmhavebeentriggered40times?
1.HowdoesyouranimalgraphhelptheEarth?Circlethecorrect answer.
2.Whichjobstudieshownatureworks?Circlethecorrectanswer.
FEEDBACK FEEDBACK
Completethefollowingsentenceandpracticesayingtoyourfriends:
1.Ibuilta 2.Ithelps
Trytowireandprogramthesolutionyourself Ifyouarehavingtrouble,look attheimagesbelowforguidance.
SAMPLESOLUTION
Inpaint,mixingallcolorscreatesblack.Inlight,mixingallcolorscreateswhite. To make white, use a command where all three color values are set to the samevalue.
C E R T I F I C A T E O F I N N O V A T I O N C E R T I F I C A T E O F I N N O V A T I O N C E R T I F I C A T E O F I N N O V A T I O N C E R T I F I C A T E O F I N N O V A T I O N