The motion sensor included in your Photon kit uses passive infrared (PIR) light to detect movement.
The motion sensor has a built-in 3-wire female JST connector. If necessary, attach a male JST connector, and plug it into different numbered rows on a breadboard. Then use jumper wires to connect the rows to the Photon. To make it easier to remember which wire is which, use corresponding black, white, and red jumper wires to match the motion sensor wires.
NOTE: The motion sensor requires 5V of power, so connect it (directly or indirectly) to the V-USB pin.
The first part of Experiment 9 in the online SparkFun Photon Experiment Guide shows how to connect the motion sensor. Here is the connection diagram from Experiment 9:
The motion sensor does not require any special code library.
In the global variables, you should declare which pin is being used as the motion sensor data pin. The example below declares a variable called "motionPin" (but you could use a different variable name).
If you are using multiple motion sensors, then be sure to give each motion sensor a unique variable name. Use variable names that will make sense when someone reads your code.
Within the setup()
function, you have to include a statement to set the pin mode for the motion sensor data pin variable:
If you are using multiple motion sensors, be sure to set the pin mode for each motion sensor's data pin variable.
Code for checking the motion sensor would be placed within the loop()
function or within a custom function.
The motion sensor can be checked by using a digitalRead()
statement.
If the sensor is currently detecting motion, digitalRead()
will return a value of LOW
.
Often, a local variable is used to store the result of the digitalRead()
, so that your code can use this result to make decisions based on whether motion is detected.
Think about what your Photon app should do if motion is detected:
turn on a light
make a sound with the speaker (a tone with a frequency of 2000Hz works well)
send a notification to your web app
etc.
Motion Sensor
Photon Pin
Black - Data
any I/O pin
White - Ground
GND
Red - Power (5V)
V-USB (5V)