To reduce the power consumption of the NodeMCU we can set the module into sleep mode between actions. For an IoT node it is possible to query a sensor and go into sleep mode until the next query have to come. The power consumption will be reduced by the ration between duration of normal operation and sleep mode.
If you we have a current consumption of about 65 mA for an operational time of 5 sec and go into sleep afterwards for 60 s with a current consumption of measured 108 uA then we will get a mean value of about 5 mA. A sleep periode of 120 s would reduce the mean value of current consumption to 2.7 mA.
For 5 mA current consumption we can expect the following life times of the different battery types:
Battery Type | Capacity | Hours | Days |
---|---|---|---|
CR1212 | 18 mAh | 3.6 h | 0.15 d |
CR1620 | 68 mAh | 13.6 h | 0.57 d |
CR2032 | 210 mAh | 42 h | 1.75 d |
NiMH AAA | 900 mAh | 180 h | 7.50 d |
Alkaline AAA | 1250 mAh | 250 h | 10.42 d |
NiMH AA | 2400 mAh | 480 h | 20.00 d |
Alkaline AA | 2890 mAh | 578 h | 24.08 d |
Li-Ion * | 4400 mAh | 880 h | 36.67 d |
As the deep sleep resets the NodeMCU on wakeup, and as we also want our code to start automatically on power up, we have to modify the file “init.lua”. It is calling the file "myfile.lua", but setting up a timer. This gives us three seconds to interrupt the “autostart”, which is quite helpful during development (or to change SSID settings).
Output of "myfile.lua" after restart:
NodeMCU 0.9.5 build 20150318 powered by Lua 5.1.4
set up wifi mode
> IP unavaiable, Waiting...
IP unavaiable, Waiting...
Config done, IP is 192.168.1.21
Running myfile.lua....
NodeMCU Version 0.9.5
ChipID 16687614
FlashID 1458415 Flashsize 4096
Flashmode 0 Flashspeed 40000000
Remaining heap size is: 17440
NodeMCU running 4 sec from last restart
Going to sleep for 60 sec...