0

I am working with a surveillance camera project with a motion sensor and a buzzer on Raspberry Pi, but when I run the code below:

from gpiozero import MotionSensor
from gpiozero import Buzzer
from picamera import PiCamera
from datetime import datetime
import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode (GPIO.BCM)
buzzer_pin = 24
led_pin = 18
GPIO.setup (24, GPIO.OUT)
GPIO.setup (18, GPIO.OUT)
camera = PiCamera()
pir = MotionSensor (4)

while True:
    pir.wait_for_motion()
    filename = datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264")
    camera.start_recording(filename)
    GPIO.output (buzzer_pin, True)
    GPIO.output (led_pin, True)
    sleep(1)
    GPIO.output (buzzer_pin, False)
    pir.wait_for_no_motion(filename)
    GPIO.output (led_pin, False)
    GPIO.output (buzzer_pin, True)
    sleep(1)
    GPIO.output (buzzer_pin, False)
    camera.stop_recording()

I get the follwoing output:

Traceback (most recent call last):
  File "/home/fisher/Motion_sensor.py", line 22, in <module>
    pir.wait_for_no_motion(filename)
  File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 192, in wait_for_inactive
    return self._inactive_event.wait(timeout)
TypeError: unorderable types: str() > int()

When the motion is detected, and the camera keeps recording until I remove the video file.

Any idea how to fix it? Thanks.

  • This is only tangentially related to the Pi. It just seems to be an error of understanding Python. – joan Mar 27 '18 at 8:05
  • try pir.wait_for_no_motion(int(filename)) @KarrarSavior – scitronboy Mar 27 '18 at 17:25
  • I tried pir.wait_for_no_motion(int(filename)) instead and got the following output: Traceback (most recent call last): File "/home/fisher/Motion_sensor.py", line 24, in <module> pir.wait_for_no_motion(int(filename)) ValueError: invalid literal for int() with base 10: '2018-03-28_02.58.33.h264' – Karrar Savior Mar 28 '18 at 1:13
2

The error message tells you exactly what is wrong.

pir.wait_for_no_motion(filename)

It seems to be expecting an integer argument but you are passing a string.

0

I tried pir.wait_for_no_motion(int(filename)) instead and got the following output:

Traceback (most recent call last): File "/home/fisher/Motion_sensor.py", line 24, 
in <module> pir.wait_for_no_motion(int(filename)) ValueError: invalid literal 
for int() with base 10: '2018-03-28_02.58.33.h264

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.