This compact battery powered unit is designed to be placed under a bed with the idea that when someone emerges from the bed in darkness, the built in LEDs will switch on automatically providing a soft floor level illumination and without the full glare of having the mains ceiling lights being switched on. Considerable design effort has gone into preserving battery life which should be around 1 year with “normal” use. Basic construction details and software (see appendix) are supplied for anyone wishing to create a similar project but the design should also be easily modifiable as required.
EDIT 1
I've updated the schematic and the .ino file but not the main .pdf which still shows the original design.
The changes are to improve the battery life. The PIR sensors are now powered via a high side switch directly from the 6v battery pack instead of via the silicon diode (0.7v drop) used to supply the MCU. The PIRs become unstable when the voltage drops below about 3.3v so eliminating that 0.7v drop should allow a longer useable battery life.
The code has also been changed to put the ATTINY1614 into sleep mode during the post switch on stabilisation time of the PIR sensors (about 10 seconds). This change was implemented in the finite state machine fsm(). The frequency of this switching depends on the stability of the ambient light level and, although there is some hysteresis built in, the frequency of this switching could be significantly higher that the theoretical minimum of 2 switches per day. Thus this change should contribute to a longer battery life.
Thanks. I learned a few new things from your code already.
Did not realize that the 1614 has a few extra features over the 814. fancier VREF and 2 ADC
Nice way to measure VCC. I will certainly use that.
BTW. the calculations in the VCC function seem to take a lot of flash.
when I compile your code I get:
Sketch uses 3172 bytes (19%) of program storage space. Maximum is 16384 bytes.
Global variables use 38 bytes (1%) of dynamic memory, leaving 2010 bytes for local variables. Maximum is 2048 bytes.
When I add: const uint32_t precalc = (1023 * 1.1 * 1000ul * 64);
Sketch uses 2586 bytes (15%) of program storage space. Maximum is 16384 bytes.
Global variables use 38 bytes (1%) of dynamic memory, leaving 2010 bytes for local variables. Maximum is 2048 bytes.
It saves 586 bytes.
I had assumed that the compiler would do that with all those constant numbers in the formula.
I'm pleased that you could find something useful there.
Thank you for taking the time to analyse the Voltage Measurement function and initiating an interesting discussion about its efficiency. It didn't occur to me to check the resources it was consuming because I wasn't near the limit.
As you'll see from the comments, I lifted that from another site. All I did was modify it to use ADC1 as a quick fix because running it against ADC0 interferes the latter's configuration rendering analogRead() and probably a lot more unusable.
In general, I buy the top parts in a range (i.e. not the "sawn off" parts with half the RAM, half the flash, half the peripherals etc.) because, on the hobby scale, the cost implication is insignificant. I, incidentally, panic bought a stack of ATtiny1614s during the shortage and am working slowly through them.
If you are porting this application to a microcontroller (in the tinyAVR series) with only one ADC then the voltage measurement function has to be changed to point to ADC0 and, after use, the function init_ADC0() should be called to restore the original configuration of the ADC so it is, once again, usable by Arduino functions such as analogRead(). It would also be a good opportunity to apply the flash saving optimisation also mentioned in this thread.
Hello,
I've been working in a very similar project, the same concept, but with the Attiny3224, 1 or 2 PIR sensors (AM312), 1 photoresistor and 1 led. It's simpler for the moment, not so professional and still a prototype, but it works fine.
I just wanted to comment the different power saving approach.
After some tests I decided to simply put the MCU to sleep all the time (power-down mode), with the PIR sensor to wake up.
Sleeping the power consumption is just 12µA, including the PIR sensor. With 2 PIR sensors it is 22µA.
With this approach the process is very simple:
sleep all the time
on PIR wake up => check the ambient light
if it's dark => switch on the led (15 seconds min), otherwise back to sleep.
I don't need the timer for anything and I don't switch off the PIR sensor. I power the photoresistor with one digital pin just when sensing ligth.
I power the board with just one small AAA Lithium battery: 3.7V, 350mAH. I don't need power regulation.
I read the VDD reference to correct the LED PWM and photoresistor readings a little bit, to compensate the light level when the voltage is lower.
It is sleeping 99.8% of the time. The LED consumes about 5mA, but it's off most the day.
I calculate that it can run more than 500 days with one PIR sensor and 380 days with two. With just one small AAA battery. We will see.
I have to say that working with the Attiny 1/2 series MCU's is a lot of fun. This little monsters are simple and full of nice features. In the final PCB probably I will put the Attiny412.
If anyone wants more details, we can comment!
I have used that approach also, namely simply having the PIR devices permanently powered and deciding at processor wakeup whether to switch on the leds or not based on the ambient light. With low power consumptions PIRs that is also a viable solution. The more PIR sensors you have, however, the better the saving potential if the sensors are powered down during high ambient light conditions. Having said that, I did no real scientific checks to see if 3 sensors is the break even point.
What I have noticed is that once the battery voltage drops to around 3.3 volts the AM312 sensors become unstable and prone to false triggering so you may have problems with a 3.7 volt cell. I may modify the AM312 sensors to replace the regulator with a 3.0 version to see if I can extend the usable battery life.
Once it developes past the prototype stage then I suggest you publish the project, or at least a link to it, in this exhibition gallery. Others may well benefit.
Everything counts. Each PIR sensors draws about 10µA. The MCU plus rest of the board draws 2µA in sleep mode. And about 1.8mA when it wakes up. But all this is still relatively low in any case.
I have Nordic's Power profiler, that's a wonderful tool. It helps a lot also for debugging. If something subtle is not correct in the code, or you forget to disable something in the MCU, it becomes visible immediately in the current scope.
In my case I'm using one small white LED for the moment, it draws only 5mA. It's enough to illuminate the room when it's dark, you can move around without problems. Anyway I will put two LEDs probably, to spread better the light.
I also have to find some kind of diffusor over the LED, or paint, otherwise the light is too sharp.
At the beginning I tested it a bit just on the desktop and seemed to work fine down to ~ 2.9V, but I'm not sure. Now I have checked the LDO with the tester and with Vin=3.0V in Vout it's also 3.0V. But could be not so reliable. Otherwise I will replace it by the 3.0 or 2.8 version.