enter image description hereenter image description hereI am new to RPi and trying to trigger a camera with a motion detector. The motion detector reads High (1) all the time, so pictures are taken continuously. I had the IR detector working with an LED before I moved on to this, so I am pretty sure it should work. I am including some code and my breadboard setup. Would appreciate advice.

import RPi.GPIO as GPIO
import picamera,time
import datetime
import pygame
from pygame.locals import *

pir_sensor = 11

camera = picamera.PiCamera()
camera.iso = 800

picpath = '/home/pi/Pictures/ggIRPics/'

def uniquename(extstring):
    translation = {ord(":"): None, ord(";"): None, ord("-"): None, ord("  "): None, ord("."): None}
    dt = picpath + 'Pic' + str(datetime.datetime.now())
    tempstr = dt.translate(translation)+extstring
    return tempstr

GPIO.setup(pir_sensor, GPIO.IN)

current_state = 0

    while True:
        current_state = GPIO.input(pir_sensor)
        print('GPIO pin %s is %s' % (pir_sensor, current_state))
        if current_state == 1:
            print('GPIO pin %s is %s' % (pir_sensor, current_state))
except KeyboardInterrupt:
  • 1
    Are you sure the pin state is 1 all the time? in your try except code block the statement to capture a picture is not indented with current_state==1 so regardless of what the state of the pin is, it will take a picture. – Nalaurien Jun 14 '17 at 21:02
  • Thanks. Good catch but that is a mistake in the post. The actual code is all indented properly under the if statement. The print statement before the if and the one after the if always return a 1. I corrected the code above to reflect the problem. – Glenn Jun 15 '17 at 0:43
  • What was the IR led sensor project that was working before, is it online? – Nalaurien Jun 15 '17 at 1:54
  • Ok, a few things to check, I can't see exactly where your wires are going to but I'm assuming yellow red black going up in the picture is the IR sensor. So first question: Is the ground rail on that side (the one connected to the black wire) connected to a ground? I see ground connected on the right side of the board, not the left (note: right and left ground rails are not connected). That might send the full 5v down the yellow wire. Question 2, what is the resistor for? is it required by the IR sensor? Because its not attached to a LED now. Third question, is the sensor rated for 5v or 3.3v? – Nalaurien Jun 15 '17 at 15:43

I found a tutorial that answered all the issues. The wiring is simple but the problem was probably in the timeout potentiometer. Many tutorials mention the potentiometers, but this is the first I found that specified the actual range of values. Once triggered, the On signal can last as long as 250 seconds, depending on the setting.


Thanks for the help

  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year. – Ingo Jan 31 '20 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.