United Kingdom
Asked — Edited

Using Pir On Digital Port

Hey guys.

I need a little help with a small PIR sensor I picked up. Operating voltage is 4.5 v upwards so have it plugged in to D0 as analog won't be enough to power it (tried it on ADC0 but voltage meter shot up to 220). Could someone offer me a Short script example for me to work from to test if the sensor is working? I had a quick look on the forum but the very few entries I found were regarding ADC.

Many thanks.

PIR sensor

User-inserted image


ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

PRO
Canada
#1  

Hey @Steve G

PIR sensors emit a high or low signal based on whether there is a change in passive IR in the area or not. They are a digital sensor so a simple script like "getDigital(D0)" will work to see if an event has occurred.

United Kingdom
#2  

Wow. Simpler than I thought. Thanks Jeremie. I'll give it a try.

#3  

@Steve.... PIRs are digital.... If that is a cheap (no offense eBay Chinese one) it may not work very well... Don't forget to use a 5V regulator.... I buy Parallax PIRs... Although more expensive they work perfectly and have a wide voltage range...

United Kingdom
#5  

Quote:

getDigital(D0)

Err, what did I do wrong?

PRO
Canada
#6  

Sorry Steve I forgot to mention you'll need to either assign it to a variable or place it in a condition

ex:

If (GetDigital(D0) = 1)
  Print(One)
EndIf

@RR I believe that unit has a 5V reg on it, I have one like it

#7  

Thanks @Jeremie...

@Steve... getDigital(D0) needs to be used like Jeremie said...or you can use a variable...


$movement=getDigital(D0)

United Kingdom
#8  

@Jeremie.

Thanks bud. All sorted now.:)

@Richard.

Yes mate, it was a "cheap as chips" one from China, but it actually works, now. Had to turn the sensitivity right down to min, otherwise it stays open. I figured as it was less than a pint of beer, it was worth a gamble. (5v reg was connected;) )

Here's what I used...


:start
If(getDigital(D0)=1)
Print ("On")
Elseif(getDigital(D0)=0)
Print("Off")
Sleep (2000)
Goto(start)
Endif

Thanks again guys.:D

#9  

@Steve... awesome man... This is more efficient as you have 2 digital reads without a delay between them...


repeatuntil(1=2)
$move=getDigital(D0) #only one digital read needed
If($move=1)
Print ("On")
sleep(5000) #give the pir time to reset...
Else
Print("Off")
Sleep (250) #speed it up or movement can happen and be gone before the next read
endif
endrepeatuntil


#10  

@Steve... you can use the waitforchange command as well if you wanted.... You can modify my script in post #10 to use waitforchange instead...

United Kingdom
#11  

Thanks Richard. The script I threw togeather was just for a lil testing, but the one you just posted will come in very useful indeed.

Here's a quick vid of the PIR in action.

#12  

@Steve... Nice.... Sorry buddy, I am getting as bad as Rich as I am trying to be more efficient... :D

United Kingdom
#13  

@Richard.

It's all good. Nothing wrong with a bit of efficiency, lol.

#14  

@Steve... To be honest, I do like the challenge... But you my friend, don't need much if any help anymore... Both of us will be leaning from other guys now...

United Kingdom
#15  

@Richard.

Lol, I wouldn't go that far. I still have some potential questions I may need to ask about a couple of other items I want to incorporate (if I can't sort it myself that is).

Germany
#16  

@Steve G @Richard R

Can someone help me ?

Im a newbie. I want to use my HC-SR501 Mini PIR Infrared Modul. How I connect this modul on the Digital Port ? the pir board has an GND, Output 3,3V and Vcc (5v-20v ) connector. the EZB 4.2 has Sig, Vin and Ground connector.. and after I use the right pins.. how I can read the parameters and how I can use this modul?

I want the same like this video:

thanks a lot

PRO
Belgium
#17  

asimo

this topic is two years old.this is what i found.

sensors