Phase 1: (in loop)
With a new sketch, create a function called “motionRead” which takes in two integers: pin and wait and returns an integer. In loop, use this new function (wait=1000) and print the return value to the serial out.
2 sec to sense
11 sec to stop sensing
Phase 2: (in loop)
add to setup:
pinMode(motionLedPin, OUTPUT);
pinMode(armedLedPin, OUTPUT);
digitalWrite (armedLedPin, HIGH);
![IMG_3480](http://portfolio.newschool.edu/shiqishen/files/2015/02/IMG_3480-1hgx3gp-1024x768.jpg)
Phase 2.5
The other should reflect the “armed” state of the device. It should normally be on but turn off immediately when the sensor is triggered. It will delay the appropriate number of seconds until the device is in a rearmed state then re-light.
Video
Phase 3
Include everything currently in loop() in an if(true) statement.
This will obviously still run it every loop. (to be fixed later)
Declare a global integer above tick() called “pace” and initialize it to 500.
In tick(), print “tick”
and delay “pace” ms.
![IMG_3721](http://portfolio.newschool.edu/shiqishen/files/2015/02/IMG_3721-26qeblg-1024x768.jpg)
Video
Video
Phase 4
Remove the line which prints the result from motionRead()
Change it to an if statement that calls winFunction() if the result is true, and calls failFunction() if not.
Video
Video
Phase 5 and 6: Adding random and setting up two potentiometers, one that controls pace and one that controls how easy the game is by regulating the wait function.
![IMG_1678](http://portfolio.newschool.edu/shiqishen/files/2015/02/IMG_1678-1mwcz1b-1024x768.jpg)
What are the devices pros/cons?
How could this be creatively applied to other projects?
The PIR sensor needs to have total stillness in front of it. Otherswise is will feel movement, even if it is not you interacting with it. or just by holding it the part that has no sensor. It also takes a long time to reset.
It could be used for the trash bin project for example, for sensing if there is something thrown into it. But it seems to be not very long range. Some store in China use it at the front door, when anyone walks in they will play the audio track “Welcome!”
I did this project with Kim. With Kate joining us in the last phases.