Você está na página 1de 14

Home

About

Projects

Learn

Library

Blog

Store

Forums ladyada.net

Search

PIR motion sensors


Pyroelectric ("Passive") InfraRed sensors

April27,201211:17

Overview FSR Photocell Temp. Tilt PIR T-Couple IR decode Thermistor DHT BMP085 TSL2561 Buy sensor Forums

WhatisaPIRsensor?
PIRsensorsallowyoutosensemotion,almostalwaysusedtodetectwhetherahumanhasmovedinoroutof thesensorsrange.Theyaresmall,inexpensive,lowpower,easytouseanddon'twearout.Forthatreason theyarecommonlyfoundinappliancesandgadgetsusedinhomesorbusinesses.Theyareoftenreferredtoas PIR,"PassiveInfrared","Pyroelectric",or"IRmotion"sensors. PIRsarebasicallymadeofapyroelectricsensor(whichyoucanseeaboveastheroundmetalcanwitha rectangularcrystalinthecenter),whichcandetectlevelsofinfraredradiation.Everythingemitssomelow

levelradiation,andthehottersomethingis,themoreradiationisemitted.Thesensorinamotiondetectoris actuallysplitintwohalves.Thereasonforthatisthatwearelookingtodetectmotion(change)notaverage IRlevels.Thetwohalvesarewiredupsothattheycanceleachotherout.IfonehalfseesmoreorlessIR radiationthantheother,theoutputwillswinghighorlow. Alongwiththepyroelecticsensorisabunchofsupportingcircuitry,resistorsandcapacitors.Itseemsthat mostsmallhobbyistsensorsusetheBISS0001("MicroPowerPIRMotionDetectorIC"),undoubtedlyavery inexpensivechip.Thischiptakestheoutputofthesensoranddoessomeminorprocessingonittoemita digitaloutputpulsefromtheanalogsensor. Formanybasicprojectsorproductsthatneedtodetectwhenapersonhasleftorenteredthearea,orhas approached,PIRsensorsaregreat.Theyarelowpowerandlowcost,prettyrugged,haveawidelensrange, andareeasytointerfacewith.NotethatPIRswon'ttellyouhowmanypeoplearearoundorhowclosethey aretothesensor,thelensisoftenfixedtoacertainsweepanddistance(althoughitcanbehackedsomewhere) andtheyarealsosometimessetoffbyhousepets.Experimentationiskey!

Somebasicstats
ThesestatsareforthePIRsensorintheAdafruitshopwhichisverymuchliketheParallaxone.Nearlyall PIRswillhaveslightlydifferentspecifications,althoughtheyallprettymuchworkthesame.Ifthere'sa datasheet,you'llwanttorefertoit Size:Rectangular Price:$10.00attheAdafruitshop Output: Digitalpulsehigh(3V)whentriggered(motiondetected)digitallowwhenidle(nomotion detected).PulselengthsaredeterminedbyresistorsandcapacitorsonthePCBanddifferfromsensor tosensor. Sensitivityrange:upto20feet(6meters)110x70detectionrange Powersupply:5V9Vinputvoltage, BIS0001Datasheet (thedecoderchipused) RE200Bdatasheet (mostlikelythePIRsensingelementused) NL11NHdatasheet (equivalentlensused) ParallaxDatasheetontheirversionofthesensor Morelinks! AgreatpageonPIRsensorsfromGLOLAB\\ NYUsensorreport

Howdoesitwork?
PIRsensorsaremorecomplicatedthanmanyoftheothersensorsexplainedinthesetutorials(likephotocells, FSRsandtiltswitches)becausetherearemultiplevariablesthataffectthesensorsinputandoutput.Tobegin explaininghowabasicsensorworks,we'llusethisrathernicediagram(ifanyoneknowswhereitoriginates plzletmeknow). ThePIRsensoritselfhastwoslotsinit,eachslotismadeofaspecialmaterialthatissensitivetoIR.Thelens usedhereisnotreallydoingmuchandsoweseethatthetwoslotscan'see'outpastsomedistance(basically thesensitivityofthesensor).Whenthesensorisidle,bothslotsdetectthesameamountofIR,theambient amountradiatedfromtheroomorwallsoroutdoors.Whenawarmbodylikeahumanoranimalpassesby,it firstinterceptsonehalfofthePIRsensor,whichcausesapositivedifferentialchangebetweenthetwohalves. Whenthewarmbodyleavesthesensingarea,thereversehappens,wherebythesensorgeneratesanegative differentialchange.Thesechangepulsesarewhatisdetected.

[Citationneeded]

ThePIRsensoritself

LeftimagefromMuratadatasheet TheIRsensoritselfishousedinahermeticallysealedmetalcantoimprovenoise/temperature/humidity immunity.ThereisawindowmadeofIRtransmissivematerial(typicallycoatedsiliconsincethatisveryeasy tocomeby)thatprotectsthesensingelement.Behindthewindowarethetwobalancedsensors.

ImagefromRE200Bdatasheet Youcanseeabovethediagramshowingtheelementwindow,thetwopiecesofsensingmaterial

ImagefromRE200Bdatasheet Thisimageshowstheinternalschematic.ThereisactuallyaJFETinside(atypeoftransistor)whichisvery lownoiseandbufferstheextremelyhighimpedenceofthesensorsintosomethingalowcostchip(likethe BIS0001)cansense.

Lenses
PIRsensorsarerathergenericandforthemostpartvaryonlyinpriceandsensitivity.Mostoftherealmagic happenswiththeoptics.Thisisaprettygoodideaformanufacturing:thePIRsensorandcircuitryisfixedand costsafewdollars.Thelenscostsonlyafewcentsandcanchangethebreadth,range,sensingpattern,very easily. Inthediagramuptop,thelensisjustapieceofplastic,butthatmeansthatthedetectionareaisjusttwo rectangles.Usuallywe'dliketohaveadetectionareathatismuchlarger.Todothat,weuseasimplelens suchasthosefoundinacamera:theycondensesalargearea(suchasalandscape)intoasmallone(onfilmor aCCDsensor).Forreasonsthatwillbeapparentsoon,wewouldliketomakethePIRlensessmallandthin andmoldablefromcheapplastic,eventhoughitmayadddistortion.Forthisreasonthesensorsareactually Fresnellenses:

ImagefromSensorsMagazine TheFresnellenscondenseslight,providingalargerrangeofIRtothesensor.

ImagefromBHlens.com

ImagefromCypressappnote2105 OK,sonowwehaveamuchlargerrange.However,rememberthatweactuallyhavetwosensors,andmore importantlywedontwanttworeallybigsensingarearectangles,butratherascatteringofmultiplesmall areas.Sowhatwedoissplitupthelensintomultiplesection,eachsectionofwhichisafresnellens

Hereyoucanseethemultiplefacetsections

ThismacroshotshowsthedifferentFrenellensesineachfacet! Thedifferentfacetingandsublensescreatearangeofdetectionareas,interleavedwitheachother.Thatswhy thelenscentersinthefacetsaboveare'inconsistant'everyotheronepointstoadifferenthalfofthePIR sensingelement

ImagesfromNL11NHdatasheet Hereisanotherimage,morequalitativebutnotasquantitative.(NotethatthesensorintheAdafruitshopis 110not90)

ImagefromIRTEC

ConnectingtoyourPIR
MostPIRmoduleshavea3pinconnectionatthesideorbottom.Thepinoutmayvarybetweenmodulesso triplecheckthepinout!It'softensilkscreenedonrightnexttotheconnection.Onepinwillbeground,another willbesignalandthefinalonewillbepower.Powerisusually35VDCinputbutmaybeashighas12V. Sometimeslargermodulesdonthavedirectoutputandinsteadjustoperatearelayinwhichcasethereis ground,powerandthetwoswitchconnections. Theoutputofsomerelaysmaybe'opencollector'thatmeansitrequiresapullupresistor.Ifyou'renot gettingavariableoutputbesuretotryattachinga10Kpullupbetweenthesignalandpowerpins. AneasywayofprototypingwithPIRsensorsistoconnectittoabreadboardsincetheconnectionportis0.1" spacing.SomePIRscomewithheaderonthemalready,theonesfromAdafruitdon'tasusuallytheheaderis uselesstoplugintoabreadboard. Bysolderingin0.1"rightangleheader,aPIRiseasilyinstalledintoabreadboard!

MostpeoplewanttopositionPIRsinaparticularlocationandoftentimesthatsfarfromtheotherelectronics, inwhichcasewireswillworkjustfine.

TestingyourPIR
OnceyouhaveyourPIRwiredupitsagoodideatodoasimpletesttoverifythatitworksthewayyou expect.Thistestisalsogoodforrangetesting.Simplyconnect34alkalinebatteries(makesureyouhave morethan3.5VDCoutbutlessthan6Vbycheckingwithyourmultimeter!)andconnect groundtothepin

onyourPIR. Powergoestothe +pin.ThenconnectabasicredLED(redLEDshavelowerforwardvoltages thangreenorbluesotheyworkbetterwithonlythe3.3voutput)anda220resistor(anyvaluefrom100 to1.0Kwilldofine)tothe outpinasshown.Ofcourse,theLEDandresistorcanswaplocationsaslongas theLEDisorientedconnectionandconnectsbetween outand ground

NowwhenthePIRdetectsmotion,theoutputpinwillgo"high"to3.3VandlightuptheLED! Onceyouhavethebreadboardwiredup,insertbatteriesandwait3060secondsforthePIRto'stabilize'. DuringthattimetheLEDmayblinkalittle.WaituntiltheLEDisoffandthenmovearoundinfrontofit, wavingahand,etc,toseetheLEDlightup!

Retriggering

OnceyouhavetheLEDblinking,lookonthebackofthePIRsensorandmakesurethatthejumperisplaced inthe Lpositionasshownabove. Nowsetupthetestingboardagain.YoumaynoticethatwhenconnectingupthePIRsensorasabove,the LEDdoesnotstayonwhenmovinginfrontofitbutactuallyturnsonandoffeverysecondorso.Thatis called"nonretriggering".

NowchangethejumpersothatitisintheH position.Ifyousetupthetest,youwillnoticethatnowtheLED doesstayontheentiretimethatsomethingismoving.Thatiscalled"retriggering"

(ThegraphsabovearefromtheBISS0001datasheet,theykindasuck) Formostapplications,"retriggering"(jumperinHposition)modeisalittlenicer.Ifyouneedtoconnectthe sensortosomethingedgetriggered,you'llwanttosetitto"nonretriggering"(jumperinLposition).

Changingpulsetimeandtimeoutlength
Therearetwo'timeouts'associatedwiththePIRsensor.Oneisthe"Tx"timeout:howlongtheLEDislit afteritdetectsmovement.Thesecondisthe"Ti"timeoutwhichishowlongtheLEDisguaranteedtobeoff whenthereisnomovement.Thesearenoteasilychangedbutifyou'rehandywithasolderingironitiswithin reason. First,letstakealookattheBISSdatasheetagain

DeterminingR10andR9isnttootough.UnfortunatelythisPIRsensorismislabeled(itlookslikethey swappedR9R17).YoucantracethepinsbylookingattheBISS001datasheetandfiguringoutwhatpinsthey areR10connectstopin3andR9connectstopin7.thecapacitorsarealittletoughertodetermine,butyou

can'reverseengineer'themfromtimingthesensorandsolving! ForthesensorintheAdafruitshop: Txis=24576*R10*C6=~1.2seconds R10 =4.7Kand C6=10nF Likewise, Ti=24*R9*C7=~1.2seconds R9=470KandC7=0.1uF Youcanchangethetimingbyswappingdifferentresistorsorcapacitors.Foranicetutorialonthis,seeKeith's PIRhackingpage

Projectexamples

AsimpleroomgreeterthatplaysthesupermariobrothersthememusicwhentriggeredbyaPIRinahacked airwickfreshenerunit.

AUSBpoweredsingingandblinkingMariomushroom(there'savideoonthesite!)

RainUmbrellas

TestingaPIRsensorforinterfacingtoMax/MSPforaninteractivegarden

AhomemadesecuritysystemusingPIRsensors(whichisbuiltintoaStartTrekpanel!)

PIRsensor+Arduino+Servo=automaticcatdoor!

A2PIRmotiontracker byLuckyLarry

APIRbasedremotecameratrigger(alsobyLuckyLarry!)

AninterestinghackwherebythePIRsensorisused'raw'totrackmovement

ReadingPIRsensors
ConnectingPIRsensorstoamicrocontrollerisreallysimple.ThePIRactsasadigitaloutputsoallyouneed todoislistenforthepintofliphigh(detected)orlow(notdetected). Itslikelythatyou'llwantreriggering,sobesuretoputthejumperinthe Hposition! PowerthePIRwith5Vandconnectgroundtoground.Thenconnecttheoutputtoadigitalpin.Inthis examplewe'llusepin2.

Thecodeisverysimple,andisbasicallyjustkeepstrackofwhethertheinputtopin2ishighorlow.Italso tracksthe stateofthepin,sothatitprintsoutamessagewhenmotionhasstartedandstopped. / * *P I Rs e n s o rt e s t e r * / i n tl e d P i n=1 3 ; i n ti n p u t P i n=2 ; i n tp i r S t a t e=L O W ; i n tv a l=0 ; v o i ds e t u p ( ){ / /c h o o s et h ep i nf o rt h eL E D / /c h o o s et h ei n p u tp i n( f o rP I Rs e n s o r ) / /w es t a r t ,a s s u m i n gn om o t i o nd e t e c t e d / /v a r i a b l ef o rr e a d i n gt h ep i ns t a t u s

p i n M o d e ( l e d P i n ,O U T P U T ) ; p i n M o d e ( i n p u t P i n ,I N P U T ) ; } S e r i a l . b e g i n ( 9 6 0 0 ) ;

/ /d e c l a r eL E Da so u t p u t / /d e c l a r es e n s o ra si n p u t

v o i dl o o p ( ) { v a l=d i g i t a l R e a d ( i n p u t P i n ) ; / /r e a di n p u tv a l u e i f( v a l= =H I G H ){ / /c h e c ki ft h ei n p u ti sH I G H d i g i t a l W r i t e ( l e d P i n ,H I G H ) ; / /t u r nL E DO N i f( p i r S t a t e= =L O W ){ / /w eh a v ej u s tt u r n e do n S e r i a l . p r i n t l n ( " M o t i o nd e t e c t e d ! " ) ; / /W eo n l yw a n tt op r i n to nt h eo u t p u tc h a n g e ,n o ts t a t e p i r S t a t e=H I G H ; } }e l s e{ d i g i t a l W r i t e ( l e d P i n ,L O W ) ;/ /t u r nL E DO F F i f( p i r S t a t e= =H I G H ) { / /w eh a v ej u s tt u r n e do f S e r i a l . p r i n t l n ( " M o t i o ne n d e d ! " ) ; / /W eo n l yw a n tt op r i n to nt h eo u t p u tc h a n g e ,n o ts t a t e p i r S t a t e=L O W ; } } } Don'tforgetthattherearesometimeswhenyoudon'tneedamicrocontroller.APIRsensorcanbeconnected toarelay(perhapswithatransistorbuffer)withoutamicro!

Thispagewasautogeneratedfrom http://www.ladyada.net/wiki/tutorials/learn/sensors/pir.html Pleaseeditthewikitocontributeanyupdatesorcorrections.

Você também pode gostar