
PIR sensor
In the previous paragraph, we talked about PIR sensors and it is useful to describe these briefly so that we have a common base to start our project. PIR sensor stands for a Passive InfraRed (PIR) sensor. This is a class of sensors that are able to detect movement by measuring the infrared (IR) light emitted by an object. All objects especially human bodies, animals, and so on emit energy using infrared rays. This type of energy is not visible to human eyes, but we can measure it using special sensors like this one. As a matter of fact, what we really measure is a variation in the emitted energy. The passive term refers to the fact that this sensor does not produce or radiate infrared rays, but it simply detects the energy emitted. Before digging into the project it is convenient to know how it works to better understand how to use it in the right way. A PIR sensor is a quite complex sensor that uses two different components. Each component is sensitive to infrared rays, as described previously.
The following figure describes how a PIR sensor works:

When a warm body (like the cat in the picture) passes through the detection area, the first component gets excited while the second component remains idle. As the body moves and leaves the first component detection area, the first component gets idle and the second component gets excited. Using this simple principle the sensor can detect when a body is moving. At the end of this process, an event is triggered. PIRs have several configurations with different features.
The most common model is the one that uses Fresnel lenses that help to widen the detection area. The following image shows the PIR sensor that we will use in this Android Things project:

The sensor has two potentiometers:
- One to adjust the sensitivity
- The other one to control the time the signal is high when an object is detected