Brewslee
Posts: 9
Joined: Sun Mar 04, 2018 12:42 pm

How can I use my PIR Sensor?

Sun Mar 04, 2018 12:53 pm

Hi!
I have a raspberry pi 3, a raspberrry pi camera, 3 female jumper cable and a PIR sensor.

How can I use my PIR sensor? I already connected it with the cables on board but I don't really understand how I can activate this device. I also tried to follow the explaination from the parent detector but I still don't know how to use it.
I want that it records a video when someone comes in range of the PIR sensor.

Can someone help me?
Thanks for your effort! :D
Last edited by Brewslee on Mon Mar 05, 2018 4:20 pm, edited 2 times in total.

User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: How can use my PIR Sensor?

Sun Mar 04, 2018 10:18 pm

https://projects.raspberrypi.org/en/pro ... mputing/13
Well you have to write a program or script that can wait for the sensor to "trigger" and then do what you want to do.

Your question was rather generic so this answer is pretty generic...

Brewslee
Posts: 9
Joined: Sun Mar 04, 2018 12:42 pm

Re: How can use my PIR Sensor?

Mon Mar 05, 2018 1:02 pm

topguy wrote:
Sun Mar 04, 2018 10:18 pm
https://projects.raspberrypi.org/en/pro ... mputing/13
Well you have to write a program or script that can wait for the sensor to "trigger" and then do what you want to do.

Your question was rather generic so this answer is pretty generic...
Hi!
Thank you very much for your help. It was my first post so I wasn't really sure how to ask my question. I will look into this link. How could I rephrase my question so it isn't generic?

User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: How can use my PIR Sensor?

Mon Mar 05, 2018 1:21 pm

Ask specific questions, be detailed about what you have done/tested so far.
Did you manage to follow the instructions from the guided example and get the same results ?
Do you understand how/why the example works?
t I don't really understand how I can activate this device.
The sensor doesnt really need to be "activated" or turned on, it just need power and then it will report back detected motion by the digital IO pin.
But if you mean "activated" as "triggered" then it should react to you waving a hand over it.

Brewslee
Posts: 9
Joined: Sun Mar 04, 2018 12:42 pm

Re: How can use my PIR Sensor?

Mon Mar 05, 2018 4:04 pm

topguy wrote:
Mon Mar 05, 2018 1:21 pm
Ask specific questions, be detailed about what you have done/tested so far.
Did you manage to follow the instructions from the guided example and get the same results ?
Do you understand how/why the example works?
t I don't really understand how I can activate this device.
The sensor doesnt really need to be "activated" or turned on, it just need power and then it will report back detected motion by the digital IO pin.
But if you mean "activated" as "triggered" then it should react to you waving a hand over it.
Thank you very much for your explanation. I tried to follow the instruction as good as I can but I stumbled upon a problem. I wired the PIR like the instruction shows but when I put the code in python 3 I got an error.

Code: Select all

Traceback (most recent call last):
  File "/home/pi/Desktop/motion detector.py", line 1, in <module>
    from gpiozero import MotionSensor
  File "/usr/lib/python3/dist-packages/gpiozero/__init__.py", line 58, in <module>
    from .devices import (
  File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 18, in <module>
    import pkg_resources
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1467, in exec_module
  File "<frozen importlib._bootstrap>", line 1570, in get_code
  File "<frozen importlib._bootstrap>", line 656, in _compile_bytecode
ValueError: bad marshal data (invalid reference)
>>> 
what can I do to prevent this error?

User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: How can I use my PIR Sensor?

Mon Mar 05, 2018 6:56 pm

According to google you either have a corrupt library or using the wrong version of python.
The last case is most likely.

Brewslee
Posts: 9
Joined: Sun Mar 04, 2018 12:42 pm

Re: How can I use my PIR Sensor?

Tue Mar 06, 2018 2:06 pm

topguy wrote:
Mon Mar 05, 2018 6:56 pm
According to google you either have a corrupt library or using the wrong version of python.
The last case is most likely.
I wrote it in python 3. How can I check if my library is broken? I tried to open python 2 but it doesn't start.
Thanks for your help, you're really the top guy ;)

User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: How can I use my PIR Sensor?

Wed Mar 07, 2018 10:26 am

We are getting outside the limits of my Python knowledge so I can only suggest that you try to reinstall gpiozero library.
Maybe post here how you installed it so maybe someone else can give more information.

If you still get the problem maybe start a new thread in the Python subforum with a subject more suitable.

Brewslee
Posts: 9
Joined: Sun Mar 04, 2018 12:42 pm

Re: How can I use my PIR Sensor?

Wed Mar 07, 2018 5:33 pm

topguy wrote:
Wed Mar 07, 2018 10:26 am
We are getting outside the limits of my Python knowledge so I can only suggest that you try to reinstall gpiozero library.
Maybe post here how you installed it so maybe someone else can give more information.

If you still get the problem maybe start a new thread in the Python subforum with a subject more suitable.
Thank you very much for all your help. I installed gpiozero again but the error still occured. I think I will do as you said and make a new post in the python section.

Brewslee
Posts: 9
Joined: Sun Mar 04, 2018 12:42 pm

Re: How can I use my PIR Sensor?

Sat Mar 10, 2018 8:08 am

topguy wrote:
Wed Mar 07, 2018 10:26 am
We are getting outside the limits of my Python knowledge so I can only suggest that you try to reinstall gpiozero library.
Maybe post here how you installed it so maybe someone else can give more information.

If you still get the problem maybe start a new thread in the Python subforum with a subject more suitable.
Hi topguy! I restored my system and now it works fine. Thank you for your help! :D
I think you were right that my library was broken.
Do you know what I could do to prevent another broken libary on my new system?

User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: How can I use my PIR Sensor?

Sat Mar 10, 2018 10:08 pm

Do you know what I could do to prevent another broken library on my new system?
No, since I dont know why it was broken in the first place. Just be careful with your SD card and try to mostly do safe shutdowns.

Return to “Troubleshooting”