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?
  • \$\begingroup\$ 1) Did you measure the current consumption in deep-sleep? 2) I think the ESP8266 Thing (and the related ESP32 Thing) had a HW bug in that they didn't pull-up the /CS pin of the flash chip, and it was consuming more than 50% of the power in deep-sleep (~1mA) \$\endgroup\$ – anrieff May 4 '18 at 1:20
  • \$\begingroup\$ I didn't measure the current because I didn't want to cut my battery wires and I don't have an adapter at the moment to bridge the battery and the Thing together. However, I will try to find a part to make the bridge or simply bring my Thing at work and power it up through a power supply to measure out the current in both states just to see if the HW bug was solved. However, my version of the Thing doesn't have an integrated FTDI chip on board (It's either FTDI or battery charger). \$\endgroup\$ – Simon Marcoux May 4 '18 at 1:24
  • \$\begingroup\$ Also how do you sense the door state? Reed switch? \$\endgroup\$ – anrieff May 4 '18 at 1:36
  • \$\begingroup\$ Yes and no (if you want to be pedantic: no. Otherwhise, yes). I use an alarm system magnetic contactor with NC/NO/Common terminals for increased flexibility (I find it quite useful to get all 3 states because I can be lazy and forego pull up or pull down resistors). \$\endgroup\$ – Simon Marcoux May 4 '18 at 1:43
  • 1
    \$\begingroup\$ Why use battery power in the first place? \$\endgroup\$ – skillz21 May 4 '18 at 3:22

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.

| improve this answer | |
  • \$\begingroup\$ 2. I'm interested in the complicated version since the goal here is to take away work ready knowledge out of that project. To answer your question regarding DTR. No if DTR is low, the program will execute once and go to deep sleep. Pulling the DTR high will completely paralyse the microcontroller until it is pulled low again. It is therefore not edge triggered. As previously stated: the consumption was reduced by a lot when I removed the status LED that was always on. \$\endgroup\$ – Simon Marcoux May 4 '18 at 11:39
  • \$\begingroup\$ @SimonMarcoux you should make your question more readable instead of downvoting, I quote "if you have a good way to prevent him ... you can disregard the rest of the question", this doesn't show much professional interest in the question. I will edit my answer accordingly \$\endgroup\$ – Dorian May 4 '18 at 12:36
  • \$\begingroup\$ Regardless of the wireless, what I'm more interested about is how do you usually control the sleep/wake up of microcontroller on an industrial level of quality. I understand that other communication protocols are designed to be energy efficient. A yes or no isn't totally helpful in that regard. regarding my cornball dad joke: fair point, I will remove it. \$\endgroup\$ – Simon Marcoux May 4 '18 at 21:27
  • \$\begingroup\$ @SimonMarcoux Actually it wasn't a bad joke, I'm a dad to, just misleaded me about your interest. Strategies for low power usage and wake-up are too be used with suited devices whwere the gain of using them is signifiant. I will edit to add more \$\endgroup\$ – Dorian May 5 '18 at 6:04
  • \$\begingroup\$ @SimonMarcoux Thank you, I designed some ultra ow power modules in the real life job. \$\endgroup\$ – Dorian May 6 '18 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.