else-like clause when PIR motion sensors not sensing using Raspberry Pi
<p>I'm working on a Raspberry Pi project which displays a different video-loop depending on which of the 3 PIR motion sensors are "sensing motion". When no sensors are sensing anything, I want to display an additional video. So all in all there are 4 videos: left, middle, right, not-active.</p>

<p>Using Python 3.4.2 , I have managed to get videos playing when sensors are activated, but I am having difficulties getting a video to play when none of the sensors are active. I thought it would be a simple 'else' like clause, but apparently it is not. I've tried many different methods, but have ran out of ideas. Can someone help me integrate a "no motion detected" return to the code? The code is as below:</p>

<pre><code>''' Import required stuff '''
import RPi.GPIO as GPIO     #GPIO
import time                 #for delay
import subprocess           #for omxplayer

''' GPIO setup '''
GPIO.setmode(GPIO.BCM) #GPIO setmode
PIR_PIN_L = 23         #define left pin
PIR_PIN_R = 24         #define right pin
PIR_PIN_M = 25         #define middle pin

GPIO.setup(PIR_PIN_L, GPIO.IN) #set left pin
GPIO.setup(PIR_PIN_R, GPIO.IN) #set right pin
GPIO.setup(PIR_PIN_M, GPIO.IN) #set middle pin

'''Definitions '''
def MOTIONL(PIR_PIN_L):                  #define motion on left
    print("Motion Detected on Left!")    #output if motion detected

def MOTIONR(PIR_PIN_R):                  #define motion on right
    print("Motion Detected on Right!")   #output if motion detected

def MOTIONM(PIR_PIN_M):                  #define motion in middle
    print("Motion Detected at Middle!")  #output if motion detected

''' Initiation '''
print("PIR Module Test (CTRL+C to exit)")
time.sleep(4)
print("Ready")

''' Sensing '''
try:
    GPIO.add_event_detect(PIR_PIN_L, GPIO.RISING, callback=MOTIONL)
    GPIO.add_event_detect(PIR_PIN_M, GPIO.RISING, callback=MOTIONM)
    GPIO.add_event_detect(PIR_PIN_R, GPIO.RISING, callback=MOTIONR)

    while 1:
        time.sleep(100)

except KeyboardInterrupt:
    print("Quit")
    GPIO.cleanup()
</code></pre>

<p>I've replaced the video parts with <code>print("Motion detected ...")</code> for simplicity. If you can add a <code>print("No motion detected")</code> when no sensors are activated, it would be very helpful.</p>

<p>I managed to solve the issue, and thought I'll post it in case someone wants to use it. Note that the code has been changed quite considerably. It still uses very low CPU. The only difference is that this code is more efficient at picking up motions, but at the cost of higher false readings. That may be fixed by adjusting the knobs on the PIR sensor. The same concept can be applied to the code above. </p>

<pre><code>''' Import required stuff '''

import RPi.GPIO as GPIO     #GPIO
import time                 #for delay

''' GPIO setup '''

GPIO.setmode(GPIO.BCM) #GPIO setmode 
PIR_PIN_L = 23         #define left pin
PIR_PIN_R = 24         #define right pin
PIR_PIN_M = 25          #define middle pin

GPIO.setup(PIR_PIN_L, GPIO.IN) #set left pin
GPIO.setup(PIR_PIN_R, GPIO.IN) #set right pin
GPIO.setup(PIR_PIN_M, GPIO.IN) #set middle pin

'''Definitions '''

def MOTIONL():                          #define motion on left 
    if GPIO.input(PIR_PIN_L)==1 :       #trigger condtion left being active
                 print("Motion Detected on Left") #output
                 time.sleep(3)          

 def MOTIONR():                           #define motion on right
    if GPIO.input(PIR_PIN_R)==1 :        #trigger condtion right being active
                 print("Motion Detected on Right") #output
                 time.sleep(3)    

def MOTIONM():                           #define motion in middle
    if GPIO.input(PIR_PIN_M)==1 :        #trigger condtion middle being active
                 print("Motion Detected on Middle") #output
                 time.sleep(3)    
def NOMOTION() :
    if GPIO.input(PIR_PIN_L)==0 and GPIO.input(PIR_PIN_R)==0 and     GPIO.input(PIR_PIN_M)==0 :
    #above trigger condition is no sensor being active
                 print("No Motion Detected") #output
                 time.sleep(3)    

''' Initiation '''

print("PIR Module Test (CTRL+C to exit)")
time.sleep(4)
print("Ready")

''' Sensing '''

try:

               while 1:  #calls defined functions simulatanously
                              NOMOTION()
                              MOTIONR()
                              MOTIONL()
                              MOTIONM()

except KeyboardInterrupt: #CTRL and C will reset shell
               print("Quit")
               GPIO.cleanup()
</code></pre>

<p>the <code> print </code> commands can be replaced with whatever function you wish to call.</p>

python python-3.x raspberry-pi3