Detecting motion – PIR sensor
Ever wondered how those motion sensors work? Usually, we find them in lights that turn up when we move. Almost all of them use a simple and common sensor called a Passive Infrared (PIR) sensor.
Here, we will build one of those annoying movement-sensitive lights, using an Arduino, its built-in LED, and a PIR sensor.
Getting ready
The following are the ingredients needed to execute this recipe:
- An Arduino board connected to a computer via USB
- Jumper wires
- A PIR sensor
How to do it…
Hooking up a PIR sensor is easy:
- It has three terminals. One is the voltage input, one is the ground, and the last one is the data pin.
- Connect the ground on the PIR to one of the GND pins on the Arduino. Connect the voltage input to 5V, and finally, connect the data pin to one digital pin. Here we used pin 2.
Schematic
This is one possible implementation using pin D2 as the input:
Here is an example of how to wire it:
Code
The following code will read the value of the digital pin on...