- Wed Mar 17, 2021 7:24 am
#90861
You certainly should be able to exploit deep sleep to get a longer lasting battery powered device.
Some notes.
1. The NodeMCU or D1 Mini are not the ideal platform to get the lowest possible current drain. Even with deep sleep there will be still be a significant current draw due to the peripheral circuitry like the usb serial. You would certainly be able to reduce the current a lot compared to the normal operational current but it will still be ~ 15 mA which will drain most batteries relatively quickly ( e.g. 1 week for a 18650). To really get a low current drain in deep sleep then you want a module like the esp-12f which will have a deep sleep drain of around 10 - 20uA. You will need a LDO voltage regulator to supply the module. E.g. if using Li-On battery then an XC6203 regulator has low drop out and a low quiescent current.
2. You need to work out the wake up strategy. There are two basic methods.
a) Use deep sleep with regular wake up at intervals to check whether something needs to be done. This is a nice simple strategy that works well for say taking sensor data at regular intervals. When the chip wakes it takes a minimum of around 300mSec before anything useful is done and around 1 second if wifi needs to be used to report something. So this only works well if the interval is greater than a minute preferably longer (e.g 5 minutes). This is because the active to deep sleep interval ratio will determine the average current draw. For an occupancy sensor this might work if you don't need too much time resolution on occupancy changes. You can also store the current state in the rtc memory and only turn on wifi and report when there is a real change.
b) Detect the occupancy change in external hardware and use the change to wake up the chip from a non-timed deep sleep. This is obviously more complex but will give you a battery drain close to the deep sleep current and therefore the longest battery life. This is the approach normally taken by say door sensors. To get the wake up signal you first need the pressure sensor as a digital signal which can be achieved using a comparator circuit. Then you need an edge detector so that you would get a wake up from both the 'sit-down' and 'stand-up' events. You can distinguish between the two wake events by also monitoring the level on a GPIO after waking. The easiest method for edge detection is to use an exclusive or logic gate and an RC delay. You can wake the device in by pulsing the reset line low. You need this pulse to be long enough to be able to discharge the internal capacitor that is normally present on the reset line. A few tens of microseconds should be sufficient.