Raspberry Pi
Tutorial de Rapberry Pi en español.
- Juan Antonio Villalpando -
Volver al índice del tutorial
____________________________
7.- Sensor de proximidad HR 501. Detector de movimiento.
GPIO2 es SDA
GPIO3 es SCL
______________________________
1.- Conexión.
- Ponemos el potenciómetro de ajuste del tiempo totalmente a la izquierda y el de sensibilidad a mitad de recorrido.
- Lo alimentamos con 5 V. El terminal de datos lo conectamos al pin 8 del Raspberry.
- Conectamos un LED al terminal 10 del Raspberry.
|
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
pir = 8
led = 10
GPIO.setup(pir, GPIO.IN)
GPIO.setup(led, GPIO.OUT)
print ("Iniciando el sensor. . .")
time.sleep(2)
print ("Activo")
print ("Pulsa Ctrl+c para terminar.")
try:
while True:
if GPIO.input(pir) == True: # Si está en alto, hay movimiento.
print ("Movimiento detectado.")
GPIO.output(led, True)
time.sleep(3)
GPIO.output(led, False)
time.sleep(0.1)
except KeyboardInterrupt: # Ctrl+c
pass
finally:
GPIO.output(led, False)
GPIO.cleanup()
print ("Fin del programa.")
|
- Tam
- Otro ejemplo en vídeo:
https://www.instructables.com/id/Raspberry-Pi-Motion-Sensing-Camera/
___________________________________________________
|