Battery Powered ESP8266 IoT – Temperature Sensor

Since my latest ESP8266 temperature humidity IoT logger project is up and running I have decided to cut the last wire – power. There are more approaches how to make ESP8266 running on a battery, but why not to have a unique one… 😎
The idea is to use only 5µA AtTiny13A (5 microA 2-3V) during the idle time to decouple all other components from batteries! So really 0 power usage from all other components (power regulator, DHT22 sensor,..), since the more components the more idle power consumption. All other circuits should wake up only during limited time and then again turn off.

I have combined knowledge mostly from two my previous projects:

  1. ESP8266 wifi temperature and humidity sensor on 5V USB power project – see details
  2. Low power (5microA) ATtiny13A project as a power switcher project – see details

This is my latest version of the wiring that I used:

ESP8266 DHT22 battery sketch

Parts list:

  • ESP8266 ESP-01 Wifi Module
  • DHT22 with 10kΩ
  • 3.3V Voltage Regulator – step up (booster)
  • AtTiny13A
  • N-channel MOSFET IRL2203N with 100kΩ
  • 2xAAA batteries with battery case

My AtTiny13A programmer and ESP01 programmer from my previous posts helped me to easilly program ESP8266 and AtTiny13A:
AtTiny13A programmerESP01-development_board-final

The project is up and running. I used double AA batteries. Sending data every ~20 minutes.:
ESP8266 battery DHT2ESP8266 battery DHT1ESP8266 battery DHT5

ESP8266 battery DHT4ESP8266 battery DHT3

Updated version with capacitors:

Logs from my server:

{"temp":"24.60","hum":"46.40","voltage":"1023","milis":"4701","datetime":"2016-01-31 16:35:58"}
{"temp":"24.10","hum":"48.90","voltage":"1023","milis":"4794","datetime":"2016-01-31 16:48:38"}
{"temp":"24.00","hum":"49.30","voltage":"1023","milis":"3795","datetime":"2016-01-31 17:09:59"}
{"temp":"23.70","hum":"47.10","voltage":"1023","milis":"4722","datetime":"2016-01-31 17:31:22"}
{"temp":"0.00","hum":"nan","voltage":"1023","milis":"4705","datetime":"2016-01-31 17:52:44"}
{"temp":"23.80","hum":"48.20","voltage":"1023","milis":"5252","datetime":"2016-01-31 18:14:06"}
{"temp":"23.70","hum":"47.90","voltage":"1023","milis":"4738","datetime":"2016-01-31 18:35:27"}
{"temp":"0.00","hum":"nan","voltage":"1023","milis":"4732","datetime":"2016-01-31 18:56:49"}


  • temp and hum are DHT22 temeperature and hunidity values
  • voltage is raw value from ESP8266 GPIO reading. Should get 0 if not sure which voltage will be provided to this pin. – only experimental
  • milis is a ms that ESP8266 needs to send data to the server
  • datetime is added timestamp on the server side

I will do real battery life measurements and I will compare different batteries as power source (AA, AAA, CR2032,..). IoT data logger is configured to send data via wifi every 20 minutes for the test. This post will be continued!

Problems I had to solve:

  • Which battery to use – using 2xAA since CR2032 3V nor 2xAAA were not able to power ESP
  • DHT22 needs time to get values – waiting 2s after the mosfet is on. In general in these steps: wifi.begin, wait till 2s uptime, read DHT, wait for wifi connect, send data to server, go to the light sleep
  • power for N-Channel Mosfet – looks stable from 2xAA
  • Step up or step down voltage regulator – I used step-up to squeeze the batteries
  • Shorten the ESP8266 connection time (static IP,..) – used static IP and optimized mentioned DHT22 readings
  • Read battery level – ESP01 has only GPIO (not ADC). I will add the second ATtiny13A or ATtiny85 to get analog batteries voltage and transfer the digital value to ESP-01 – not implemented now

I will post the source code, once it’s stable and proven.
UPDATE 2016/11/02:
I have stopped using DHT22 because it is slow (2s) and spent lot of time to fine tune the code and still it is not final (although it’s up and running more then 9 months now). The ESP needs to be up for 8s to get reliable data with compare to 4s with SI7021 sensor used in battery-wifi-iot-temp-hum-soil-moisture-sensors.
But anyway the ESP8266 code for DHT22:
ATtiny code to wake up 20min for 8s:
ESP8266 for SI7021 (it reads also data from ATTiny85 serial, that you can remove):

ESP Battery life

2 x Tesco AA batteries

UPDATE: After adding 2 capacitors (100uF and 10uF) in parallel with DHT22 the readings are stable.
After 28 days, the batteries are 2,85V with 1985 temperature/humidity readings.
After 50 days, the batteries are 2.77V with 3544 temperature/humidity readings.
After 3months, the batteries are 2.69V with 4409 temperature/humidity readings
So finnaly after 69days, the batteries are 2.62V with 4655 temperature/humidity readings. So the project works more than 3 months on 2x Tesco AA batteries 😎

3 x Ikea AA batteries

Check project version with only SI7021 temperature and humidity sensor with 3xIkea AA batteries and with ATtiny85 for battery level measurements.
After 50 days the interim batteries voltage level is 4.08V with WiFi transferring and 4.34V (1.44V each!) during sleep mode. The project is still up and running after 3171 measured and transferred data:
The project is up and running after 21 weeks.


Bellow is a widget combination of all of my IoT data from I2C on my cubieboard, ESP8266 on battery, ESP8266 on USB and also Yahoo data. Also check my another ESP8266 battery IoT door sensor project.


Related Posts

Battery Powered Wifi IoT – Temperature, Humidity & Soil Moisture Sensors


I have just made a prototype of ESP8266 (ESP-01) IoT temperature & humidity SI7021 sensor and also 2x three pin soil moisture sensors with only 0.006mA (6µA) current drain during the sleep.

Continue reading ...

ESP8266 Temperature Humidity IoT Logger


I learned how to program ESP8266 so I created my first temperature IoT ESP8266 project. I used DHT22 as a temperature and humidity sensor and also I did some testing of power consumption using LIGHT SLEEP[…]

Continue reading ...

Programming ESP-01 (ESP8266)


I was inspired by several DIY projects. The ESP8266 WiFi 802.11 b/g/n Module is a self contained SOC with integrated TCP/IP protocol stack that can give any microcontroller access to your WiFi network. The ESP8266[…]

Continue reading ...
  • Andreas Steinel

    Nice work!

    I wanted to try something similar, but with and ATtiny85 and I wanted to readout the DHT with the microcontroller (also powerup/powerdown before powerup ESP). Voltage measurement can – as you suggested – also be done on the micro itself using the internal voltage reference (maybe it should be calibrated before, also raw temperature measurement inside is possible IIRC to compensate the ADC temperature drift) . I wanted to emulate a i2c client device on the tiny as-well, so that I can add more sensors to the ESP-01 module and have an very easy access protocol between the ATtiny85 and the ESP-01. In the end the ESP can send the leave-i2c-command to the tiny and it’ll powerdown. This should save more energy. I often also rework the arduino libraries to squeeze more deep sleep time out of it, but you’ll end up not using any library at all.

    a problem I encountered it, that I had to reread the DHT at least once to get a good reading. Did you encounter similar problems?


    • Tomas

      I’m considering also other way: ESP-07 with ATtiny13A and now I have added to my plans your ESP-01 + ATtiny85 combination.
      Either use ESP-01 only for wifi and utilize ATtiny85 for i2c/ SPI sensors and timing. Or ESP-07 for wifi/sensors and ATtiny13A only to reduce power. So thanks for sharing your idea.

      The reason why I have not posted the code is just because DHT22 reading (I had zero or nan values randomly). I have now DHT22 reading in loop until I have valid number and I send loop count to the server. The count is 1 or 10 (200ms dellay), so adding 2sec uptime in about 50% (but with 100% valid reading value now). So no once but 10 times with 200ms dellay, which corresponds to DHT22 specification 0.5 Hz sampling rate (2s).
      As of now my ESP01 uptime is 3778ms to 7340ms (depends on wifi and DHT). After a week my 2 AA batteries went down from 3,2V to 3,05V so it looks promising till now (398 readings).
      Regarding the battery reading I have now plans to add one more ATtiny13 powered from voltage regulator (3.3V) so I can directly read batteries (max 3,2V) so I will not have to use voltage divider and internal reference. Or I will just wait for ESP-07 and will read it there. Or as now I just use my multi-meter time to time 😉

    • Tomas

      I have added 2 capacitors (100uF and 10uF) in parallel with DHT22. The reading of DHT waits for 2s (while wifi is connecting) and then the value is correct at the first time.The total ESP8266 uptime is now max 5s. After 2 weeks the batteries are 2,96V after 910 readings.
      Now I also consider to use I2C Si7021 for temp and humidity sensor.

      • Andreas Steinel

        Yes, I order some Si7021 from China too. Much better footprint and hopefully easier and faster integration 😀

      • Tomas

        Si7021 worked good! Now the readings are not ~5.5s but ~3.5s. Saving 2 seconds of ESP8266 up-time will increase the battery life even more.

  • Adam Milton-Barker

    Hi mate do you mean 10k or 100k pull ups, your text says 100 and your schematics says 10k also is this mosfet ok ?–220AB/dp/B00LX6LIBA/ref=sr_1_1

  • lordprize

    Hi Tomas, thank you for taking the time to write all of this. I wanted a project to test the quality of cheap PCB manufacturers and I used this project. The result is public: – I can post pictures of the PCB as soon as it arrives.

    I have a request: Could you perhaps publish the source code? I’m sure most people won’t mind if it is not completely stable yet. I know I won’t mind because it would save me from writing everything from scratch :)

  • Tomas

    If you use only 2xAA batteries that is 3.1V, than the 3.3 voltage regulator is mandatory. If 3xAA batteries are used, 4.5V should be OK for ESP8266, but I have not tried it.

    ESP8266 code for DHT22:
    ATtiny code to wake up 20min for 8s:
    ESP8266 for SI7021 (it reads also data from ATTiny85 serial, that you can remove):

  • Tomas
  • Nicolas

    Hi Thomas,
    Thank you for this post.
    Have you thought about replacing HTTP protocol by MQTT to send data (temp, humidity…) to your server?
    It should be faster and less battery power consuming.
    What do you think about that?

    • Tomas

      Yes it should be also better if you have more nodes. I was also thinking to use MQTT in next version and Node-Red to process data.

  • Drasko DRASKOVIC

    great post!

    Which proved to be better and more reliable – 2 AAA solution with boost (step-up) or 3 AAA with buck (step-down)? How long did 2 AAA last and how long 3 AAA can last?

    • Tomas

      2xAA took more then 3 moths
      3xAAA with step down took more then 4 moths then I took off step down and it’s now connected directly to batteries for additional 6 weeks and still up and runnig !!! then I can put step-up to get even more weeks (hopefully).
      3xAAA test was broken by accident so I will have to wait.. but testing is now taking too much time… :)
      The problem with step-down is that they do not work under 3.3V. My little step up/down is not working if the battery voltage is close to ~3.3 V (not sure how to deal with it, so I do it manually now).
      Ideally it would be great to have step up/down working continuously from 4.5V down to ~2.8V, but I have no clue how.

      • Drasko DRASKOVIC

        How often do you measure per day and what is the time of each measurement?

        I ahev saw this recently: It is based on Realtek RTL8710, and it has ARM Cortex-M3 inside. Noramlly deep-sleep current should be much smaller than ESP8266 – it is advertised to be ~10uA in comparing to ESP’s ~80uA. Also, active power is ~90mA, while AFAIK ESP can be over 120mA.

        This should probably give better result in your low-power project.

      • Tomas

        I measure temp and hum every ~20min and it tooks less then 4 seconds.
        For the power measurement graph I use my other project and there is ATtiny85 for the measurement that measure each wifi wake up (I have removed moisture sensors from it).
        That PADI chip looks great. I will let others to test it and post some results.. :)

  • CommonSenseApplies

    Tomas – well done. You solved a problem for me with the delay before reading on the DHT22. Thank you. Also had a question. The ESP8266 has a deep.sleep mode, why use the AtTiny to do the sleep? Does it cut out the step up/down so less power is consumed?

    Thanks again, very well done.

    • Tomas

      Yes, it cuts out also step up/down and also DHT or other sensors and resistors if used. It was for me easier to use AtTiny13a than spend time to fine tune deep sleep on ESP-01. Mostly to remove LED and wire pins on ESP-01 described e.g.: and the result would be 78 microAmp and with AtTiny13A the current is even 10 times less.

      • CommonSenseApplies

        Good point, I am convinced. I have a probe that I use outside and use it with deep.sleep. It works OK for me but removing the LED and soldering in the jumper so it will wake up was a pain and the wire breaks free from time to time if the module is handled. I think the answer is the AtTiny. Thanks for posting this and thanks for getting back to me. Nicely done on the build and the logic behind it. Plus this is a good excuse to get more hardware…..

  • Nicolas

    I have a very noob question (i’m not familar with mofset), sorry for that…
    I plan to replace the IRL2203N because it’s difficult to find it (or it’s too expensive).
    Could someone explain me how to choose a correct N-channel Mofset?

  • CommonSenseApplies

    Tomas – why do you use the MOSFET at all? I am not challenging your design I am trying to understand it. The ATtiny acts as the switch to the MOSFET, which in turn acts as a switch to the step up voltage regulator. I looked through the specs of the ATtiny13a and can not find anything on what is the safe current level (or max) for the output pins. I realize that using the ATtiny as the switch (removing the MOSFET) would mean changing the wiring from switched on neg to pos. Is the MOSFET design a more safe (from the ATtiny’s perspective) and more standardized approach?

    • Tomas

      I’m not an expert, but ESP can drain ~200mA and somewhere I have found: Absolute Maximum Ratings: DC Current per I/O Pin ….. 40.0 mA. So with resistors, you can power LED but not more. E.g. check this

      • CommonSenseApplies

        Thank you, makes sense. Your design is working well for me – thank you sharing it.

  • Angel Ornelas

    Hello, I have a problem trying to make this circuit works, the Attiny wakes up and switch the MOSFET to enable the 3.3V to feed the components, the ESP-01 reads the sensor, but when it tries to connect to a network it disables the 3.3V and then it turns off itself and the other components, anyway the attiny is still powered up and then sleeps again, I’m using the N-channel MOSFET, but what can be the problem? May the circuit doesn’t supply enough current to maintain the ESP-01 working with Wi-Fi functions?

    • schleppschlappen

      I have the same Problem, did you find a solution?

  • Ujica Septimiu

    Hello. Do you think that I can use one of this regulators: with 3 AA batteries for a similar project?

  • ehthyar

    hi Tomas.. I used IRF540N instead of IRL2230. ( .. Rds is 44mOhm..

    I am successfully able to power ON or OFF an LED from MOSFET output with its gate controlled by Attiny85.

    However if I connect MOSFET’s drain PIN to ESP8266 GND even with gate pin made high by Attiny, ESP8266 doesnt switch ON. What might be wrong here?

    If I connect ESP8266 to power source’s GND directly it powers ON.

  • ResearchIt

    I was looking at some of these circuits and ran across and idea I found on a video. That is not using an ATTiiny but having a switch and a mosfet or relay. The thought is totally disconnecting power altogether. If the switch(door sensor or mailbox sensor) is momentarily switched the processor fires up and turns on the mosfet. It then processes any notifications etc and turns off the mosfet or relay and again power is removed.