I want to use a motion sensor to output to the terminal when motion is detected.
What i am using
・ Raspberry Pi ZERO WH
・ Motion sensor HC-SR501
In this question, as the title suggests, during the program
wait_for_motion () wait_for_no_motion ()
I would like you to teach me how to operate and how to use.
I hope the content i am trying is just for reference.
The program will be executed and it will be in a standby state.
If i move your hand in front of the sensor, the detection will be output to the terminal.
It seems that it is done correctly so far, but after that, even if nothing is moved in front of the sensor, the detection will continue to be output at regular intervals.
(It seems that the wiring etc. are done properly. Also, I tried multiple sensors and all the results are the same)
→ I thought there might be something wrong with the program.
What I tried
from gpiozero import LED from gpiozero import MotionSensor green_led = LED (17) pir = MotionSensor (4) toggle_pin = 22 green_led.off () counter = 0 def main_loop (): global counter while True: pir.wait_for_motion () print ("Motion Detected") green_led.on () counter = counter + 1 print (counter) pir.wait_for_no_motion () green_led.off () print ("Motion Stopped") if __name__ =='__main__': main_loop ()
I googled to death, but I couldn't find the information I was looking for because I couldn't search and speak English. (Reference etc.)Supplementary information (FW/tool version, etc.)
Here(Completely reproduced) with reference to the video of
version: Python 2.7.16
Answer # 1
I have solved it myself, so I will describe it.
The video I referred to and the one on Amazon were different from the one I had.
It seems that there are some pieces, and the pin and the trigger part of continuous detection and single detection are also slightly different.
If you purchased from Amazon etc., you may not know which data sheet to look at, so you may have to do your best to find it.
wait_for_motion (timeout = None) #Pause the script until the device is activated, or the timeout is reached. wait_for_no_motion (timeout = None) #Pause the script until the device is deactivated, or the timeout is reached.
↑ From the state of processing, probably wait for the detected or undetected state, or if you set a timeout, keep executing this state until that time is reached (?). I think that's what it means.
Thank you to those who sent us the reference.
I hope it will be helpful for those who are worried about the same part.
- python - i don't know how to adapt the sample code
- python - i don't know how to put out the sum of the matrix
- python - i don't know how to do css select in bs4
- python - i don't know how to deal with the error
- python - i don't know how to fix the type error
- python - [beginner] i don't know how to write a bat file i want to run py
- php - i don't know how to use try ~ catch and pdoexception
- i don't know how to write python
- python - i want to know how to not plot data with a value of 0 in matplotlib
- [wordpress] i don't know how to move pages
- i don't know how to pass opencv path
- python - how to use numpyinterp
- c # - i don't know how to call aync/awit
- how to use python 2d array
- facebook - i don't know how to set the callback url to the app!
- python - i don't know the cause of the error
- c - i don't know how many times it has been run
- python - i want to know how to keep outputting to csv
- [vba] i don't know how to log in automatically from the next time [keep login]
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- xcode - pod install [!] no `podfile 'found in the project directory