Why?
Me and my wife moved our bedroom from the ground floor to the souterrain and experienced that at night it was even darker than on the ground floor. That's because on the ground floor, light came in from a street-lamp outside. Furthermore there's no socket where we could've placed a night light, which would've turned on automatically when you get up, anymore. That's why I've wanted to build a motion activated night light.
Besides, I'm going to be a daddy really soon (by the time of writing this). Infants are waking up at night because they're hungry (for example). If you're not a cat, you've to turn a light on somehow. My wife thought about placing a small lamp somewhere. I've even heard about women taping a flashlight to the bedpost. But we're in the year 2018 and I had just finished the prototype (stripboard) of the motion activated night light. Therefore I've added a push button to turn on and off the "nursing light mode". The push button is also used to turn on and of the "night light always on mode".
The button turns on the light in a predefined brightness by a short button press. Another short press turns it off again "nursing mode". By holding down the button a little longer, you're able to turn on the "night light always on mode". In this mode the light stays on at a (predefined) low brightness level, instead of turning off completely.
Different modes / states
- off → LEDs are fading down to zero and stay turned off
- night light always on
- LEDs are fading down and stay on at a low brightness
- turn on and off by a long press of the push button
- alternative for "off" (when enabled)
- night light get up
- LEDs are fading up when PIR1 or PIR2 have detected a motion (for example someone is getting out of the bed)
- LEDs are fading down after three minutes (retriggering doesn't expand this time span)
- nursing (the name derived from the main purpose of this light mode)
- LEDs are fading up by a short press of the push button
- LEDs are fading down by a short press of the button
The colors / brightness for every mode is directly set within the code (see future improvements).
Under certain conditions, you can reach each state from one another. I've summarized the different combinations and conditions in the figure below.
LED-fading
Because the brightness perceived by the human eye is not linear, the LED-fading should also not be linear. I'm not going to much into detail here. To my knowledge, it was believed that the human eye has a logarithmical response (honestly, I thought so too until now where I'm looking up a reference concerning this matter). That was until Stevens's power law was introduced. I haven't looked into this any further, but you're free to do a research on your own. I'm glad to provide some links as starting points: Apparent magnitude, Stevens's power law, Power law.
Nevertheless, it is obvious that a non-linear approach is the way to go. And because I wanted the fading (PWM) to be super smooth, even when it runs very slowly, I've chosen to use 16-bit timers. I'm using these in fast PWM mode. Please check the datasheet of the microcontroller for further information regarding this.
Controller board
The prototype of the controller board...
Read more »