As you can read in the earlier postings I am trying to make my home smarter and smarter. The first step was the installation of connected switches in combination with Home Assistant. Now it is the turn to add some logic behind this simple devices. The first idea is to react on the people around. So we need something like a presence detector. At the moment there are multiple possible technologies. Let's have a quick look at all of them.
A simple way to detect objects and persons is to use sonar-technology. These devices ping continuously and try to find the reflection of the sent sound waves. The time between the sent out signal and the received reflection determines the distance to the reflecting object or person. Most of the devices translate this difference in time into voltage levels. Some of them also provide advanced interfaces like i²c. The program has to check the distance in a loop and detect changes. So if we want to detect presence you have to be in motion.
In the near past some cheap "radar"-sensors became very popular. Basically they work the same way like the visual sonar. Instead of sound waves they use electric microwaves. Whenever we want to use a sensor like the RCWL0516 in combination with the ESP8266 we have to watch out for stable pins and lines. The fact that the ESP8266 works with microwaves (when it communicates via WiFi) also passes vibes to the pins. So we have to stabilize at least the power line and may also integrate a pulldown-resistor from the dataline to GND.
PIR stands for passive infrared. This means that the sensors work on a visual detection. PIR-sensors have two subsensors with a material that reacts on infrared rays. So basically both subsensors should receive round about the same amount of infrared rays and the difference should be very small or zero. Whenever a person moves in front of the sensor there is a difference between both values. In difference to the sonar it is not possible to determine the distance between the person and the sensor. This is not possible because we have no idea about the temperature of the moving body and the isolation of the transmitting medium (for example air). This is at least true for the cheap sensors, which are built to detect motion.
All of these possibilities have one fact in common: You have to be in motion to be detectable. This might be an acceptable solution if you want to activate lights when you enter a room or deactivate them when you are passive for a given amount of time. This might be a good solution for your lab. But I am not sure if it the best solution for the living room or the bed room. Especially if you want to read a book or something similar. So I am going to search for a better fit for this requirement.
One of the next postings will handle a possible use-case for one or more of these sensors in combination with a smart home. And I think another will handle smarter ways to detect presence.