Javadoc link

pir

A passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view. They are most often used in PIR-based motion detectors.

Arduino schéma ( you can also use an other compatible controler )

 

Result :

 

Example code (from branch develop):
#file : Pir.py (github)
#########################################
# Pir.py
# description: PIR - Passive Infrared Sensor
# categories: sensor
# more info @: http://myrobotlab.org/service/Pir
#########################################
 
from datetime import datetime
 
# start the service
pir = Runtime.start('pir','Pir')
pir.setPin('23')
 
# start a micro controller
mega = Runtime.start('mega','Arduino')
 
# start a speech synthesis service
mouth = Runtime.start('mouth','LocalSpeech')
 
# connect the micro controller
mega.connect('/dev/ttyACM1')
mega.attach(pir)
 
# attach the pir sensor to the micro controller
pir.attach('mega')
 
# subscribe to the pir's publishSense method - callback will be python onSense
python.subscribe('pir', 'publishSense')
# enable the pir
pir.enable()
 
# callback method - change state of pir this method will be called
def onSense(data):
    print('onSense', data, str(datetime.now()))
    mouth = Runtime.getService('mouth')
    if data:
        mouth.speak('I see you')
    else:
        mouth.speak('where did you go?')
    
Example configuration (from branch develop):
#file : Pir.py (github)
!!org.myrobotlab.service.config.PirConfig
controller: null
enable: true
listeners: null
peers: null
pin: null
rate: 1
type: Pir