1

I have set this up with the PIR sensor and a night camera.

I have been able to write a simple(ish) program (P1) so it so that when motion is detected, it saves an image – the filename of the image is the date and time when it is recorded. The program keeps running until i is interrupted with CTRL C.

I have modified this program (P2) so that when it detects motion, it start a video recording, also onto a file whose name is the date and time. Using time.sleep(10), I can get it to stop recording after 10 seconds.

I would like to be able to change the program so that it keeps recording until the motion stops but I don’t understand the detall of the camera control to do this, and would appreciate some help with this.

The relevant part of P2 is

When motion is detected, an image is saved

The filename is the current date and time

A beep is played when motion is detected

 while True:


      while GPIO.input(motionsensorpin):

Update filename to current date and time

           filename = '{:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now())+'.h264'

Play a beep sound

           pygame.mixer.music.play()
           print(filename)

Save an image to the current filename

           camera.start_recording(filename)
           time.sleep(10)
           camera.stop_recording()     

Any help gratefully received.

-1

Why reinvent the wheel check motionEye it does all that and more

9
  • where is the fun in that? :) – rob Jan 16 '18 at 16:45
  • Simple answer is that I didn't know about MotionEye. I'll look for it and have a go. There is so much information out there about Raspberry PI that it is not easy to find the right bit. That's the great thing about these forums. But I also think Rob has a point - it's more fun to do it yourself. So I would still appreciated help to modfy my code to solve the problem. Thanks all. – epzcaw Jan 16 '18 at 17:24
  • I've now had a look at MotionEye, and discovered that it is a complete package. I doing this project mainly for fun, and to improve my programming. So I would still be grateful for any help in where I go next with my code. – epzcaw Jan 16 '18 at 17:40
  • Fair enough, I'd assumed the objective was a security camera. I'm not familiar with the programming language you're using, is it python ? – Bra1n Jan 16 '18 at 18:01
  • Yes, Python. I think I need to understand more about how the camera software works. BTW - not convinced I could use it as a real security camera - would need a weatherproof box! – epzcaw Jan 16 '18 at 21:12

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.