#58 ESP8266 Sensor runs 17 days on a coin cell/transmits data to sparkfun.com and ubidots.com

#58 ESP8266 Sensor runs 17 days on a coin cell/transmits data to sparkfun.com and ubidots.com Grüezi (Hello) YouTubers,
here is the guy with the Swiss accent again. In episode #47, I looked into the sleep mode of the ESP8266. There, a viewer asked if it is possible to run an ESP from a small button cell and how long it would run. In this episode I try to answer this question as well as build a sensor which sends mails and post the measured values to several IOT platforms like data.sparkfun.com and ubidots.com. And I will use the sleep mode of the ESP to extend the battery life. In this episode, the sensor will measure and send values every two minutes. In the next episode, it will measure and send values every day at the defined time. So let’s start with a simple scenario. First, I tried to run an ESP12 with a normal CR2032, 3 V button cell. We remember that the ESP8266 uses about 80 mA when the Wi-Fi is ON. Let’s look at the datasheet of these CR cells. Even if the voltage of 3 V would be okay they are made for very small currents and cannot be used for our purpose. Fortunately other button cells exist. Lithium ion batteries LIR2450. Watchers of my “mailbag” #3 know already that I ordered and tested such batteries. They have a capacity of about 100 mAh and a nominal voltage of 3.7 V. They are able to deliver 80 mA for a time of about 10 s without any problems. So let’s try to connect an ESP07 or ESP12 module to such a battery. I use an ESP 07 because I had it available on a small PCB. I unsoldered the red LED because it is also ON when the module is in deep sleep. It would use way too much energy. The ESP12 does not have such a LED. I keep the blue LED because it’s only ON during very short periods. If we look at the datasheet of the ESP8266, we see that it works from 3 to 3.6 V. Now we have a problem. Fully charged LiPo batteries have a voltage of 4.1 V. Our ESP chip is only rated up to 3.6 V operating voltage. So we have to regulate the voltage to for example 3.3 V. If the LiPo has 4.1 V, the voltage regulator is necessary because it has to drop 4.1 – 3.3 V. If the battery is at its end, the regulator should not drop any voltage because we want to run the ESP as long as possible. And of course during deep sleep the regulator should not use any current. All linear voltage regulators need a difference between the input and the output voltage. This voltage is called “dropout voltage”. Normal linear regulators like the LM1117 with 1.2 V or the LM78L33 with 1.7 V dropout voltage cannot be used because this voltage is way too high for our purpose. In addition all regulators need a small current for their stabilization even if no load is connected. This current is called “quiescent current”. This current is 5 to 6 mA for the LM1117 or the LM78L33. Also way too high for battery operation. Fortunately better regulators exist for this purpose. For my ESP modules I use a small PCB which has a space for an HT7333 linear voltage regulator. Let’s check its values. Its dropout voltage is only 0.15 V and its quiescent current is typically 4 µA. This seems to be a much better choice for a device with a small battery. So let’s go with this one. As we saw in episode #47, the ESP draws peak currents of 350 mA. This is definitely too much for such a battery and the voltage would drop during these current spikes. I recently bought some 1’000 µF SMD tantalum capacitors. They were the biggest I was able to get. For SMD parts they are huge, but they fit nicely on my module. With this capacitor right across the supply pins of the ESP module, I have no current spikes anymore. Now we have a stable supply voltage and an ESP8266 module ready for the test. For this episode I will not attach an external sensor because I want to get the behavior of the module itself. In order to have something to transfer, I measured the supply voltage and transfer its value to the cloud. The ESP has a mode to measure VCC with the internal ADC. This can also be used to log the voltage over time or to send a mail where the sensor asks for battery replacement. Next we need a sketch to measure the voltage, send it to the cloud and sleep afterwards for a predefined time. For this episode I want to build a sensor which measures quite frequently. This is why I can use the internal clock to time the deep sleep periods. Literature says that this is not very precise, but if we just sleep for a few minutes or hours this is not so important. In the next episode, however, I will build a sensor which only measures once every day. Then the internal timer is no more precise enough and we have to use an atomic clock to get the needed precision. Stay tuned. I found a project by Rainer Ochs which I was able to use for my purpose. He wrote his sketch to monitor water levels. You find a link to his project in the comments. I used this sketch as a base and expanded it. He uses mail as his communication channel to the Internet. This has two disadvantages for a sensor which should run on batteries: First it takes about 30 seconds to send the mail, and second it is not easy to do anything with the measured values if they are distributed in your mailbox. To send mails, however, is good for some purposes. This is why I keep the mails to announce the start of the sensor: its daily “I’m still okay message”, and the request for new battery if voltage is too low. For the rest I want to use IOT cloud services. In episode #48 I used MQTT and io.adafruit.com as a service. Today, I will use data.sparkfun.com
and ubidots.com as services. Like that you get a library of different possibilities for your projects. Sparkfun as Adafruit recently added an IOT service. It can store data of several fields. To create a stream, you go to data.sparkfun.com and create this stream. Give it a name and the description and add as many fields as you want. I strongly suggest to download the JSON file because you need this data later and if you do not have it, you cannot come back to this page. Now you can save it and get various keys and URLs. Now you are ready to communicate with this service. To store a value you only need one HTTP request. You find it in my code. Make sure that every character matches. Even a forgotten space can make a difference and the whole thing does not work. It took me some time to get it right, but now you should be able to just copy-paste. The same applies to you ubidots.com. This is also a nice service and also free of charge if you just want to try with one sensor. If you want to send mails from your device, you can use the SMTP service of your own mail account, but this is not recommended because currently the ESP does not use secure connections. So I use a free mail service called “SMTP2GO”. This is a nice service and you find the sketch for the ESP in my code. The only trick you need: the service expects your credentials in so-called “base64 format”. Fortunately a web service exists to convert your username and password to this format. In this episode, I will focus on the current consumption and will not cover the software aspects. However you already find a link in the description of the code. In future episodes I will cover also the coding part. For now we have a sensor which sends the actual VCC voltage to two IOT services and deep sleeps afterwards for two minutes. Do not forget to connect the GPIO16 (or D0) on the NodeMcu boards to the reset pin. Otherwise the ESP will not wake up and the deep sleep will last forever. After wake up, the ESP07 connects to the Wi-Fi network and calls two HTTP requests. This takes about 8 seconds. The biggest part of the time is needed to establish the connection to the access point. During these 8 seconds, the ESP draws about 80 mA. During the deep sleep, the ESP chip itself should only use about 15 µA. In my configuration with the voltage regulator it consumes about 70 µA at 4.1 V and 40 µA at 3.5 V battery voltage. Let’s assume it’s 16 µA in average. We know that the battery has about 100 mAh which is
100 mA × 3’600 s=360’000 mAs. One cycle uses
80 × 8 + 100 × 0.06 mAs=647 mAs. The battery therefore should last about
360’000 / 647=556 cycles. There are 30 cycles/h so the battery should last about 18.5 h. Let’s check in reality. To visualize, you can export the values of data.sparkfun.com to a service called analog.io. And here we see that the sensor transmitted the data for about 26 hours. More than expected. If we would send a message every hour, the formula would be
80 × 8 + 3’600 × 0.06 mAs=856 mAs. The battery should then last only
360’000 / 856=420 cycles. But this is 420 hours or 17 days. Just for fun I replaced the LiPo cell with two AA batteries. Their capacity is about 2’200 mAh and because their voltage does not exceed 3.6 V we do not need a voltage regulator. So they should last at least 25 times longer than the small button cells, which means in scenario 1: 26 × 25 h=650 h or 27 days And in the second scenario, it should last
25 × 17 days=425 days, which is way more than one year. Great! Thanks for watching. I hope this episode was useful or at least interesting for you. Bye.

100 thoughts on “#58 ESP8266 Sensor runs 17 days on a coin cell/transmits data to sparkfun.com and ubidots.com

  1. lol i read ubidiots.com instead of ubidots.com when clicking. great content as always. i'll have those HT7333's in my mind to enhance some projects. thanks!

  2. Hi Andreas. Excuse the ESP newbie question, but i assume you are using the standard AT firmware with the Arduino IDE?

  3. Hi Andreas, I want to use either a coin battery or AA battery to power a Wemos D1 mini, is it correct to connect it to across the 5V and Gnd terminal and what is the value of the capacitor across 5V and Gnd. Thanks

  4. Is system RTC for esp8266 makes possible battery powered ?? .. Mine only last for a week, without RTC.. how can i send you my source code?


  5. Is system RTC for esp8266 makes possible battery powered ?? .. Mine only last for a week, without RTC.. how can i send you my source code?


  6. Do you have to tie the D0 pin to reset, because when i do that with your code, the esp8266 still resets… 🙁

    can you help?

    thank you.

  7. Just a tip to lower the consumption even more – before wifi.begin(), run also wifi.config() with static IP, gateway, DNS and subnet. Also put channel and BSSID/AP mac into the wifi.begin(). These two adjustments should decrease the time it takes the ESP to join your wifi network from 3-5 seconds to about 500 milliseconds.

  8. almost a year late… but great video, thanks so much i learned a bit, time to start researching everything deeper

  9. Many thanks for the info about HT7333. Will use it in weather station outdoor with one 18650 LiPo battery. Greetings from Russian viewers)

  10. Thanks, your discussion on the regulator for these boards was rely useful, I using 3.6V Ni-MH as backup power, but it solve the same problem.

    One thing you forgot to mention was the 0 ohm short (located under your cap). needs to be removed when a regulator is used in normal operation. Thanks again.

  11. Great video. Is there a way to connect faster then 8 seconds.
    I read somewhere you can preset the wifi channel and use static ip and it should reduce dramatically the connect time.
    Unfortunately not sure which APIs to user for this purpose.


  12. Would it be possible to Log Temperature every 2 Minutes, but only send all results as a batch once every hour?
    And would that reduce batterydrain by a lot or not much?

  13. Hi Mr. Andreas, I am now working on a project with an ESP-WROOM-02 module and I also need to send data to dat.sparkfun.com.
    So, I create a text stream and copy the code from the Arduino sketch and bootload and run the code. But I don't know how to see the data coming in on the web page. Sorry, Mr. Andreas, I am very very new to web service and this question may sound stupid for you. Thanks and waiting for your reply.

  14. Thank you very much for this awesome and very helpful video! I'm going to give the HT7333 a try now! I hope the module is not too tiny so I'll be able to solder wires to the pins. Do you use a special soldering iron for SMD parts? Greetings from Germany, btw! I don't mind the Swiss accent at all. I like the fact that you speak slowly in the video, so it's easy for me to follow. 🙂

  15. Hi, do you know if ESP has a sleep mode where the receiver is on, and if something is received, ESP wakes up?

  16. actually this calculations a little wrong. for example 2aa batteries has maybe 2200mah but voltage is going to 1v for 2200mah capacity . that means total voltage is 2v and esp8266 can't connect wi-fi And measure something in this voltage. and it will change what you measured.

  17. Hi Andreas, you use also the quite big white board to solder the ESP on it. Do have found in the meantime a smaller version that has the size (width) of the wemos shields? I see still only on aliexpress the white boards from the video. I really like the already included pullup resistors and the place to solder the voltage regulator. All great. Just a little big too big for my outdoor housings.

  18. 17 people have pressed the dislike button,, Seriously?! the guy is giving you free knowledge and you give back a dislike!

  19. Thank you very much for the videos. Just a question: If I use a 18650 battery with the HT7333, the esp will be powered with 3.3V if the battery voltage is higher from 3.39V,right? In this case, the ESP.getVcc() method will always return the same value and it would not be possible to accquire the "real" battery state, right? As there is no regulation below 3.39V, the voltage will start decreasing further and then it would be possible to warn the user with a battery low message, for example at let's say 3V. Is this the way you are doing it? Great job on the videos. You are my guru already! Greetings from south Brazil!

  20. Did a similar thing with a lifepo4 cell and small (4cm*6cm) solar panel.
    The idle power usage while the esp sleeps is so low that I had to purposely keep the thing awake to stop the cell overcharging.
    Surprised it actually matches its datasheet power usage after you disconnect any external circuitry.

  21. Hi, Great video.
    I have been trying to get my NodeMCU to run on batteries for a while now, but using deep sleep I cannot get et lower than 9mA i deepSleep. I do not understand how you accomplish so low power consumption. Do you have any hints?

  22. When I connect GPIO16 to RST on my ESP12-E board, it keeps resetting. If I remove the wire it works, but it cannot wake from sleep. I also tried with a 1k ohm resister. Any ideer why this happens?

  23. Mr Andreas i have experienced with my 2.4 ghz signal module of a commercial rc tx that have a good concrete penitration though my wifi router doesn't have, both seems to have 5dbi antennas could you plz explain, what are the main controlling factors of 2.4 ghz frequency range? How it could be amplified to get more range? Does the more range would make it more penetrable???

  24. Great video, really helpful! Anybody got another idea for a regulator like the HT7333 but fits on a SOT-223 footprint instead of SOT-89?

  25. Thank you for the great videos, they seriously are very inspiring!
    With respect to battery runtime I am still trying to figure out which is the best minimal setup for a bare ESP12F module (using FTDI for programming). I understand that you need the following pins connected: CH_PD/EN => Pullup; GPIO0 => Pullup (for running; GND for programming); GPIO15 => Pulldown. And, for stability reasons: GPIO02 => Pullup; RST => Pullup; Electrolytic capacitor 1000uF between VCC and GND (as pointed out in one of your videos).
    What are the best values for the external resistors (sometimes I read 10k and sometimes “the smaller the better”) if I am looking for minimal energy consumption and/or stability? Some pins have internal pullup/-down resistors would they be a better choice than external ones? And does the maximum voltage level of a capacitor does have any influence on energy consumption?
    I know, a lot of questions, but maybe you can help shed some light?

  26. There is several ways to set up the email so that the communication between the ESP and the email server only lasts a second or two.

  27. Very useful and very interesting … and I think I learned my first Swiss German word. Gruezi! Mit Hilfe von Bernhard Hofman 🙂 Groetjes!

  28. Much appreciate your great work. Unfortunately Phant of sparkfun is no longer in operation. I will try with adafruit service and Supercap, solar panel combination for power. Please make some video on energy harvesting for sensors. Danke 😉

  29. Why do you use a bare ESP-12 Module? Can i do the same with a development board (like the Wemos D1 Mini)? When i power it via the 3.3V pin the regulator should not waste energy!?

  30. WOW!!! 4uA and such low dropout!! How did you find this? I searched extensively on DigiKey dot com and could only get down to 105uA quiescent with dropouts less than 200mV.

  31. Really enjoyed this video and found it very informative, its fantastic to be able to learn like this. Thank you Mr Spiess

  32. Andreas, I intend to use a small bit your video, talking about it in my video. Do you have any issues with that? I am specifically talking about your video and will link it.

  33. Hi .Thanks for your video channel. I am learning alot.. I tried to setup a stream at data.Sparkfun.com but it transfers me to the main webpage of sparkfun and I don't see anyplace to create the stream.



  34. Hello Andreas, thanks very much for your videos and knowledge sharing, so much appreciated. I want to realize a wireless keypad with BLE and I was wondering if it’s possible to augment battery life using ESP 32 deep sleep. Do you know if it’s possible to wake up the ESP-32 pressing a digit while not loosing the input? Thanks!

  35. So button cell capacity understated, or spec sheet current draw overrated?
    Almost twice the time running, one of them must be wrong……

  36. Hi Andreas – I've always wanted to know how to develop a circuit and s/w that allows me to check voltage of my batteries and warn me if I need to change batteries. Have you ever done such a video tutorial ? if not would it be an interesting one to do ?

  37. Video is a little old, but, THANK YOU VERY MUCH for all the time you put in to give so much knowledge back to the WORLD. Always enjoy you r videos lessons.

  38. That could last more, if you add an energy buffer like a super cap. The peaks of current caused by transmission/reception are way too high for that battery's capability to handle them. Every time you transmit/receive, its capacity reduces. By adding a capacitor to the battery, you take that energy from it (assuming it's charged) instead of the battery until the capacitor's voltage goes below the requirements of your system. Capacitor's capacity depends on the duty cycle you need for you application. The longer you want to the cap to handle the TX/RX the bigger the cap and also more costly.

  39. Hi Andreas, would you still recommend a 1000uF capacitor on the power line? All the datasheets that I can find for these capacitors show a leakage current of at least 40uA which would seem to negate the advantage of using the efficient HT7333. Perhaps a 300 or 100uF power line capacitor would be sufficient? It would be great if you could do a video about this.

  40. Always good!! Very informative and detailed, I didn't know much though, sorry. Thank you. I am learning new things watching your hard works.

  41. Great video and battery life calculator But, I don't understand how i know discharge safety in % for battery life accuracy while calculating battery life. Will you please explain me little bit more. I am using 2*1.5V AA size battery with ES12E module. This module interface with other host MCU and send data to server using AT command. How i calculate discharge safety in percentage.

  42. Putting your username and password for anything into a third party service is not a great idea – perhaps better to use a local base64encode function

  43. Hi Andreas, Hope you are keeping well..

    I am not a technical person your explanations in this video is very easy to understand. I watched on ESP 8266 more than 100 video really its very helpful in my project.

  44. Hallo Andreas,
    erstmal Danke für deine super lehrreichen und sympatischen Videos hier.
    Ich bin aktuell auf der Suche nach einem Fenster Sensor welcher mit einem ESP8266 (Deepsleep) und MQTT umgesetzt wurde. Man findet hierzu sehr viel, auch gute Sketches, allerdings irgendwie nicht ganz in Kombination das was ich suche. Ich hätte gerne einen Fenster Sensor welcher sowohl den Status Offen, als auch den Status Closed über ein Magnet Reed Kontakt an einen MQTT Broker versendet. Das ganze mit Deep Sleep und gerne mit einer AA Zelle. Du hast nicht zufällig sowas schon umgesetzt und ein Sketch bzw. einen Schaltplan mit Komponenten dafür parat dafür parat ?
    Ganz liebe Grüße

  45. Great video… as usual !
    I'm thinking of running an ESP from a battery also, so you are a great inspiration.
    However, I know almost nothing in passive components. I understand there is a need of a capacitor for removing peaks of current, but I can't find those huge 10 000 uF capacitors. Is it possible to put an électrolytic one instead ? In the video you said there are huge. Is a 300 uF enough ?

  46. Sali Andreas , ich bin eine großes Fan vom deine Videos, habe sehr viel gelernt. Leider kann ich die LDO HT7333 hier nicht beschaffen.Kannst Du bitte eine alternative LDO empfehlen?
    Gruess Örs

  47. Thanks for the subtitle, if more videos of you had subtitles the success of this channel that already is very good would be even more. How would you like more subtitles in Portugues

  48. Hello, anyone watching this in 2019
    I believe the now preferred LDO regulator is the Holtek HT7833. The HT7830 might be good for using a little bit more of the battery's full capacity by going as low as 3.6 volts

    If anyone knows of a better option for single (18650) lithium ion operation, please let me know

  49. Hi Andreas, Thank you for the video. I like the content that you post. I have query on the sleep time itself, what is the maximum time we can put 8266 to sleep, the maximum that am seeing is 72 minutes with micropython, have you used a different timer lets say for 8 hours or more? Thank you

  50. This is a great video , thank you for posting.
    The quiescent current appears to be very large. It would be great if we could power this device for a period of 1 year.
    any ideas ?

  51. Great video Andreas, one suggestion regarding voltage regulator: a simple silicon diode would have a junction drop voltage of around 0.7 volts, which is what you need to reduce from the 4.3v battery. No need for regulator…

  52. Hi Andreas, I'm currently working in a IoT project. I want to publish a msg using mqtt per day and go to deep sleep esp12 module. Most important part is I want to publish another msg whenever external interrupt occur. I am new for the ESP and MQTT world. Can you (or anyone )please help me to fulfill my task.

  53. I don't know if someone else has already suggested this, but if you have a website you can write your own code (in PHP, for example) for sending emails, and program the ESP to send the HTTP request to that page (which is quite fast, and therefore consumes little battery) and go to sleep, then, whatever time the webserver requires for actually sending the email is not a problem the ESP should care about (as long as it is shorter than the interval between two requests, otherwise the ESP would overload the webserver).
    You can use a pre-shared key/protocol for encrypting your data, so that only your ESP will be able to send commands to that page, and only that page will be able to decrypt the content of the string sent by the ESP, even without SSL

  54. Really value the video — learning a ton. Can you guide me on function call sendSparkfun(SPARKFUN_BATTERY, rtcValues.other, rtcValues.battery)? the function on github just listed calling sendSparkfun (byte ubidotsType). Can you describe the signature for ubidotsType?

  55. Hi Andreas, thank you for the video. I examined the datasheet of ht7333. In the application circuit, there is a capacitor between Vout and ground. And we also have a capacitor as a decoupling capacitor. How should be the connection?

  56. Thx rus subtitles. Ставлю лайк за русские субтитры, к сожалению в других Ваших видео они не работают. С удовольствием просмотрел бы и другие видео.

Leave a Reply

Your email address will not be published. Required fields are marked *