Electronic – Microcontroller wake-up strategies (ESP8266)

esp8266microcontroller

At work, we have a remote battery operated magnetic door detector that send a signal to our alarm system whenever we open a door. The battery lifespan is almost a year.

I tried to replicate that system at home. I constructed a really simple circuit around the esp8266 Thing. It is a simple battery operated door detector that ping my cellphone each time my son open his door when he is trying to fall asleep.

The code routine is simple enough: upon activation, the esp pings a specific IP and then go to deep sleep. The wake up is done through the DTR pin. When the door is closed I keep the DTR line up. Once the door open, the DTR line is released and the program execute once and go to sleep. Closing the door reset the DTR line and it is ready for another cycle.

I also removed the power LED indicator to increase the battery lifespan. My system works fine at the end of the day. But, the battery lifespan is somewhat limited (before I removed the LED it was a couple of days. Now, it is lasting longer, but I didn't note the new lifetime of the battery). The battery is a 1200 mAh rechargable LiPo. Following up on that project, I have a couple of questions:

  1. Is this the proper way to do such a thing?
  2. Is there a more industry standard way? (with the esp8266 or any microcontroller in general).
  3. Any other power management tips that might be useful to know?

Best Answer

anrieff is right, the power consumption is still high. Some things to look at:

DTR interrupt is really edge triggered or the Thing wakes up many times as long as DTR is low?

It seems that the highest consumption is at wake up, you might make some delay to disable door open detection for a specified time after the last one. I don't think that an alarm each 5 seconds is needed.

How to figure out the power consumption without cutting wires:

  • Take off the battery and measure the voltage, better with a higher precision voltmeter.
  • Connect the voltmeter to the Thing power
  • Connect the battery and write down the voltage at various stages until the deep sleep. You can also see how long it takes to go to deep sleep.
  • take off the battery and load-it with resistor of various values until you get the values in the previous step
  • From the resistor values you can get the current consumption.

It's not very accurate but you can get a clue where your battery is used and if the consumption is in the range you expect to be.

Update because I didn't answered to questions 1 and 2

  1. In my opinion not but the fast development comes with a cost. I would use something else like a wireless ring bell to bring the signal to a wall adapter powered Thing.

  2. Yes but to complicated for such simple task

Update following the comment

  1. Depends on the meaning of "such thing"

1a. Such thing = quick fix using what you have handy. Answer = yes.

1b. Such thing = professional wireless door opening sensor. Answer = no , Friendly advice, don't look at a toy store like Sparkfun for such things. Neither their products or tutorials have nothing to do with the development of reliable professional products.

  1. Yes, see here an article about low power wireless technologies used today, you can find links to products and development boards and compare the power requirements for each solution. As you see using the home AP is the worse from the lifespan point of view.

  2. Answered above

Edit to add some more strategies:

If the switch closed is long enough then power your board through the switch, on power on send the ping then goto deep sleep.

If the deep sleep is still consuming to much or the event is to short then use a hardware monostable triggered by the switch to get a fixed powered time for the Thing.

You can also set in hardware a "dead window" where the switch is ignored after a trigger to avoid multiple events in a short time.

Using interrupts is a good way, tough i see the pin you're using has something to do with the hardware reset, using long reset is not good since many devices are still consuming much while kept in reset.

Still, for high reliability products you cannot use only wake-up on interrupt. At some point an EM glitch might bring the microcontroller in a state where to disable the interrupts or ignore them. From this point your device is dead and only a hardware reset can help.

For that the watchdog was invented, if you not take action to reset the watchdog by software he will wakeup/reset the device after a specified time. The time is usually set in the flash memory and protected from software errors and EM glitches. That way even something went wrong you can allways have your program running again and, eventually report the error and take action.

It's allways a good practice to send an "alive" signal from time to time from the same reason.

Going further than your project if the sensor isn't as friendly as a door switch and requires power for himself than you can either set a timer interrupt to wake up , power the sensor and get the data, or use a hardware pulse generator that powers both from time to time. Here is where a good device will let you play with the system clock to minimise the power consumption when processing power is not needed. Not the case of the Thing.