import RPi.GPIO as GPIO  
GPIO.setmode(GPIO.BCM)  

# GPIO 23 set up as input. It is pulled up to stop false signals  
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)  
  
print "Make sure you have a button connected so that when pressed"  
print "it will connect GPIO port 23 (pin 16) to GND (pin 6)\n"  
raw_input("Press Enter when ready\n>")  
  
print "Waiting for falling edge on port 23"  
# now the program will do nothing until the signal on port 23   
# starts to fall towards zero. This is why we used the pullup  
# to keep the signal high and prevent a false interrupt  
  
print "During this waiting time, your computer is not"   
print "wasting resources by polling for a button press.\n"  
print "Press your button when ready to initiate a falling edge interrupt."  
try:  
    GPIO.wait_for_edge(23, GPIO.FALLING)  
    print "\nFalling edge detected. Now your program can continue with"  
    print "whatever was waiting for a button press."  
except KeyboardInterrupt:  
    GPIO.cleanup()       # clean up GPIO on CTRL+C exit  
GPIO.cleanup()           # clean up GPIO on normal exit  

///////////////////////////////////////////////////////////////////
import RPi.GPIO as GPIO  
GPIO.setmode(GPIO.BCM)  
#GPIO.setmode(GPIO.BOARD)  


GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)  

#GPIO.setup(port, sens, etat initial)  initial=GPIO.HIGH ou bien GPIO.LOW
#GPIO.setup(port, sens, resistance de tirage)  pull_up_down = GPIO.PUD.UP ou GPIO.PUD_DOWN ou GPIO.PUD_OFF
#GPIO.input(port) lire une entrée
#GPIO.output(port, 1)  dixe l'état sur une sortie # True
#GPIO.output(port, 0)    # False 	 
#GPIO.add_event_detect(port, type) GPIO.RISING ou GPIO.FALLING ou GPIO.BOTH
#GPIO.remove_event_detect(port)
#GPIO.cleanup() reinitialise toutes les E/S

def detection(channel):  
    # on affiche un petit message pour confirmer
	print "falling edge detected on 17"  
	# lecture de la pin
	input_value = GPIO.input(17)
	 GPIO.remove_event_detect(17)
     # on reinitialise les GPIO
     GPIO.cleanup()
	

	## falling edge detection

GPIO.add_event_detect(17, GPIO.FALLING, callback=detection, bouncetime=300)  

while:1

	# une petite pause entre chaque boucle, afin de réduire la charge sur le CPU
     time.sleep(0.02)

# on reinitialise les ports GPIO en sortie de script
GPIO.cleanup()
	 

GPIO.RPI_REVISION     #  0 = Compute Module, 1 = Rev 1, 2 = Rev 2, 3 = Model B+  
# What version of RPi.GPIO are we running?  
GPIO.VERSION     	 

	 

##GPIO.add_event_callback(channel, my_callback, bouncetime=200)
###RPIO.wait_for_interrupts()


*****************************************************************************************
import RPi.GPIO as GPIO
import time
 
GPIO.setmode(GPIO.BCM)
 
pir_pin = 18 #le capteur PIR est connecté au GPIO 18
buzzer_pin = 22 #le buzzer est connecté au GPIO 22
 
GPIO.setup(pir_pin, GPIO.IN) #configuration en entrée pour le PIR
GPIO.setup(buzzer_pin, GPIO.OUT) #configuration en sortie pour le buzzer
 
Try:
 
while True:
    if GPIO.input(pir_pin):
        print("MOUVEMENT DETECTE!")
        GPIO.output(buzzer_pin, True)
    time.sleep(0.5)
 
except KeyboardInterrut:
    GPIO.cleanup()
*******************************************************************************************
import time
import RPi.GPIO as GPIO

GPIO.setmode( GPIO.BCM )

GREEN_LED = 24
PIR_SENSOR = 23

GPIO.setup( GREEN_LED, GPIO.OUT )
GPIO.setup( PIR_SENSOR, GPIO.IN )

while True:
        # SI PIR sensor Actif ALORS allumer LED
        if( GPIO.input( PIR_SENSOR ) == True ):
                GPIO.output( GREEN_LED, True )
                print( "Detection PIR: "+"CA BOUGE!!!" )
        else:
                GPIO.output( GREEN_LED, False )
                print( "Detection PIR: "+"rien a signaler" )

        # attendre 100 ms
        time.sleep( 100 / 1000 )
*************************************************************************************************
import RPi.GPIO as GPIO
import time

# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)

# Define GPIO to use on Pi
GPIO_PIR = 7

print "PIR Module Test (CTRL-C to exit)"

# Set pin as input
GPIO.setup(GPIO_PIR,GPIO.IN)      # Echo

Current_State  = 0
Previous_State = 0

try:

  print "Waiting for PIR to settle ..."

  # Loop until PIR output is 0
  while GPIO.input(GPIO_PIR)==1:
    Current_State  = 0    

  print "  Ready"     
    
  # Loop until users quits with CTRL-C
  while True :
   
    # Read PIR state
    Current_State = GPIO.input(GPIO_PIR)
   
    if Current_State==1 and Previous_State==0:
      # PIR is triggered
      print "  Motion detected!"
      # Record previous state
      Previous_State=1
    elif Current_State==0 and Previous_State==1:
      # PIR has returned to ready state
      print "  Ready"
      Previous_State=0
      
    # Wait for 10 milliseconds
    time.sleep(0.01)      
      
except KeyboardInterrupt:
  print "  Quit" 
  # Reset GPIO settings
  GPIO.cleanup()


*****************************************************************************

import RPi.GPIO as GPIO
import time
import urllib

GPIO.setmode(GPIO.BCM)

GPIO_PIR = 7

print "PIR Module Test (CTRL-C pour quitter)"

GPIO.setup(GPIO_PIR,GPIO.IN)

Current_State  = 0
Previous_State = 0

try:

  print "Waiting for PIR to settle ..."
  while GPIO.input(GPIO_PIR)==1:
    Current_State  = 0    

  print "  Ready"     
    
  while True :
   
    Current_State = GPIO.input(GPIO_PIR)
   
    if Current_State==1 and Previous_State==0:
      print "  Mouvement detecté !"
      test = urllib.urlopen("http://127.0.0.1/PHP/action.controller.php?action=motion")
      time.sleep(80) 
      Previous_State=1
    elif Current_State==0 and Previous_State==1:
      print "  Ready"
      Previous_State=0
      
    time.sleep(0.01)      
      
except KeyboardInterrupt:
  print "  Quit" 
  GPIO.cleanup()

**************************************************************************************************
public function motion()
{
	$fichier_motion = fopen("motion_history.txt","r+");
	$old_date = fgets($fichier_motion);
	fclose($fichier_motion);
	unlink("motion_history.txt");
	$fichier_motion = fopen("motion_history.txt","a");
	fputs($fichier_motion,date('Y-m-d H:i:s'));
	fclose($fichier_motion);
	// Si l'utilisateur est entrain de dormir
	// CAD si un mouvement a été détecté il y a moins de 8 heures ET qu'il est encore nuit ( heure < l'heure de levé maximum)
	if((time() - strtotime($old_date)) < 8*60*60 && intval(date("H")) < $this->time_wake_up_max )
	{
	
	// ne rien faire
	}
	else if((time() - strtotime($old_date)) > 60*40)
	{
	
	// Sinon, si il y n'a pas eu de mouvement depuis 40minutes, c'est que l'utilsateur était parti
	
	// Donc => on l'accueil avec la fonction bienvenue()
		$this->bienvenue();
	}

}



http://intelligenceonline.synergize.co/news/projet

************************************************************************************

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BCM)

PIR_PIN = 7

GPIO.setup(PIR_PIN, GPIO.IN)

def MOTION(PIR_PIN):

               print “Motion Detected!”

print “PIR Module Test (CTRL+C to exit)”

time.sleep(2)

print “Ready”

try:

               GPIO.add_event_detect(PIR_PIN, GPIO.RISING, callback=MOTION)

               while 1:

                              time.sleep(100)

except KeyboardInterrupt:

               print “ Quit”

               GPIO.cleanup()  
  