Connecting & Testing the Motion Sensor

~~~~
Screen Shot 2017-09-22 at 8.16.02 PM.png
~~~~
Materials:
*Your RP (Raspberry Pi) & its charger
*A HDMI cable and a monitor, also a non-wireless keyboard and mouse
*A PIR Motion Sensor
*Three jumper cables (preferably different colors so they are easier to identify, we use red, yellow, and black)
  • Today we’re only going to connect &  test our motion sensor so the camera does not need to be connected
  • Start up your RP and connect the charger, the HDMI, and the mouse and keyboard USBs
  • Now take your motion sensor and look for three small metal spikes coming out of the side without the white half-globe on it
  • Related image
  • Now connect the cables as shown above and make sure to match the colors up correctly with the black on the left, the yellow in the middle and the red on the right
Image result for pir motion sensor raspberry pi
  • Now to connect them to the RP you are going to turn RP so that it is facing you just like in the picture above and count the metal spikes so that the red jumper is on the spike on the corner to the right, the black should be two spikes below the red one, and the yellow should be on the column to the left and down four spikes
  • Great! It’s connected!
  • Now to test it:
  • Go to your main menu and open the first option, Programming, and then the seventh option, Python 3 (IDLE)
  • Open a new program by going to File, then New File, or by pressing Ctrl+N
  • Now to test the motion sensor put in the code:
Screen Shot 2017-10-20 at 11.34.42 PM.png
Screen Shot 2017-10-20 at 11.35.41 PM.png
  • Now save it (File, Save as, or Ctrl+Shift+S), name it ‘motion-test.py’ and run it (Run, Run Module, or F5)
  • Wave your hand in front of your motion sensor and it should print out:
Motion detected
  • It may take a few seconds so be patient! And if it doesn’t work the first time try it a second time, that did the trick for me!
  • Notice how the program ends after having detected motion once? Well we want it to be continuously checking for motion so we are going to edit the code by adding in a while loop:
  • Before the line of ‘pir.wait_for_motion()’ put in the line:
while True:
  • Now save it and try running it again and the program should stay running even after it has detected motion once


Sources:





Comments

Popular posts from this blog

Connecting & Enabling the Camera

Setting Up