All posts by Mariel Steiner

Using a motion sensor to turn on a light (and keep it on til everybody leaves)

USING A MOTION SENSOR TO TURN ON A LIGHT (and keep it on)

The goal of this tutorial is to use a PIR sensor to detect movement in a plaza, then turn on a secondary system (in this case, just an LED light). The key thing here is not to detect every single movement, but to turn on the light and keep it on until the PIR detects no movement for a certain period of time, at which point the light should turn off.

The parts you’ll need for this tutorial are:

Parts:

  1. PIR motion sensor
  2. Arduino UNO
  3. 3 pin stacking header
  4. Jumper wires + resistors
  5. LED light

Here’s how to set up your breadboard (and resultant circuit):

The PIR sensor has 3 pins, which should be labeled. On our PIR, the pins read
“VCC,” “OUT,” “GND” from left to right on the botton of the plate.

Connect the PIR into the breadboard so that (–) pin connects to the Gnd row,
(+) pin connects to 5V, and Out pin connects to digital pin 2.

To test the sensor, plug the (+) pin of a red LED into pin 13 and connect the (-)
pin to GND

PIR tutorial_bb

PIR tutorial_schem

Now to put in the code. Again, the important thing here is that we don’t just want the PIR sensor to measure motion, we want it to reflect when a space is active and keep the LED on for as long as there is activity in the space. So, we have to set a minimum period of time  after for the PIR to take measurements finding no motion, and then to turn off. In the code, this period is 10 seconds, but you can change it if a longer or shorter amount of time seems more appropriate to you.