Safety and scope
Keep the sensing side of this project at low voltage. Powering the light itself is a separate matter: switching mains wiring should be done by a qualified electrician, or you can use a certified, ready-made switch or plug rated for the load. Never open mains equipment unless you are qualified. If you solder, use eye protection and ventilation. Lights that come on automatically can help prevent falls at night, but they are a convenience and not a safety system.
What a motion sensor actually senses
The most common sensor in home projects is a passive infrared sensor, often called PIR. All warm objects give off infrared radiation. A PIR sensor contains elements that compare the infrared level across different zones in its view. When a warm body, like a person or an animal, moves from one zone to another, the balance changes and the sensor outputs a signal. “Passive” means it only receives; it does not send anything out.
Because it detects change in infrared, it notices movement across its field of view far better than movement straight toward it. A person who is sitting still may stop being detected, and this is the cause of the familiar problem of lights switching off while someone is reading.
Other types exist. Microwave and radar sensors send out a signal and measure reflections, and can sometimes detect small movements through thin materials. Ultrasonic sensors do something similar with sound. Each has different strengths and different false trigger patterns, so check the data sheet for any model you choose.
From detection to light
A simple setup has three parts: the sensor, a controller that decides what to do, and a switch for the light.
- The sensor outputs a signal when it detects movement.
- The controller, which could be a hub or one of the microcontroller boards you build with, sees the signal.
- The controller tells the switch to turn the light on, starts a timer, and turns it off when the timer runs out without new motion.
Many ready-made products combine these parts. If you build your own, a transistor switch can drive a low-voltage LED strip, while mains lighting should go through a properly rated device.
Getting the timer right
The timer is the setting people tune most. Too short, and lights go out on someone who is still there. Too long, and they stay on needlessly. A short time suits a hallway or cupboard. A longer time suits a room where people sit quietly. Each new detection should restart the timer so a light stays on while you move around.
Consider also adding a soft finish, such as dimming for a few seconds before switching off, which gives a warning and avoids sudden darkness.
Dealing with false triggers
False triggers fall into two groups: the light comes on when nobody is there, or it fails to come on when someone is. Common causes and fixes:
- Heat sources. Radiators, vents, sunlit windows and appliances can change the infrared pattern. Move the sensor or aim it away.
- Pets. Animals trigger PIR sensors. Some sensors have pet-immunity settings, which usually work by raising the threshold for smaller or lower sources. Results depend on the animal, so test.
- Air movement. Drafts that move curtains or warm air across the sensor can trigger it.
- Outdoor conditions. Moving branches, passing cars and changes in sunlight can cause activations. A narrow field of view and a shield around the sensor can help.
- Electrical noise. An unstable power supply can make a sensor trip on its own. A clean project power supply and a short settling time after power-up help. Many sensors need a warm-up period after power is applied before readings are reliable.
- Reflections and glass. Some sensors can be influenced by sunlight through windows.
When the problem is a missed detection, look at placement. Mount the sensor so people cross its field rather than walking straight at it. Check the height and angle recommended in the documentation.
Using more than one condition
Combine motion with other information to reduce nuisance activations. A light level reading means the light will only come on when the room is dark. A time window can restrict activation to nighttime. In bedrooms, a dim low-level light is often less jarring than full brightness. The brightness and color you choose should suit the room, which is where good room lighting choices come in.
You can also require two events, such as motion in the hallway followed by motion in the room, before triggering a light. This adds delay, so use it only where false triggers are a real problem.
Testing and tuning
Test in the real location, at the real times of day, and with the household. Keep a short log of unwanted activations and what you changed. Adjust one setting at a time so you know which change helped. When you add a second sensor, check that the two do not conflict.
Also test what happens if the controller or network fails. A light that depends on an internet connection to respond to motion is less reliable than one that works with local control, and the room should still have a working manual switch.
Privacy
A motion sensor records no images, but a log of movements still reveals when people are home and which rooms they use. Treat that data as personal. Store it locally where you can, and delete old records you do not need.