Battery Powered ESP8266 IoT – Door Sensor

I successfully run DHT22 battery ESP8266 temperature/humidity IoT sensor so my next project is a simple IoT Door Sensor. It is up and running and sending a simple event to my HTTP server via wifi chip ESP8266 (ESP-01 in my case). HTTP server is serving simple php script, that stores the data locally and also sending events to DWEET.IO and also sending email via Amazon SNS (AWS CLI api).

Please check my previous posts that were essential for me to create this battery powered ESP8266 door sensor:


The simple fritzing sketch:



Hardware components used:

  • ESP-01
  • ATtiny13A
  • 3.3V power boost
  • N-channel MOSFET IRL2203N with 100k Ω pull down
  • wires connected to metal door connector with 100k Ω pull up
  • 2xAA batteries

The project works in these simple steps:

  1. ATtiny13A is in deep sleep every 2 seconds
  2. ATtiny13A makes HIGH Door Pull-up resistor pin
  3. If the door is closed the input ATtiny pin is LOW so only puts the Door Pull-up to LOW (to minimize power consumption by pull-up) and go again to sleep.
  4. If the door is open, the input  ATtiny pin is HIGH so the Mosfet gate is set to HIGH so power booster and ESP-01 is up that connects to the http server via WiFi, sends uptime and goes to sleep. ATtiny puts the Door Pull-up to LOW after minimum 4 seconds from the door open event.

BatteryDoorSensorWifi3 BatteryDoorSensorWifi2 BatteryDoorSensorWifi1


My http Apache server serves simple php script that stores the data:

{"door":"3504","datetime":"2016-02-27 22:11:37","user_agent":"Mihi IoT 03"}
{"door":"4399","datetime":"2016-02-28 13:12:43","user_agent":"Mihi IoT 03"}
{"door":"4419","datetime":"2016-02-28 14:25:09","user_agent":"Mihi IoT 03"}
{"door":"3488","datetime":"2016-02-28 14:34:16","user_agent":"Mihi IoT 03"}
{"door":"4414","datetime":"2016-02-28 17:42:14","user_agent":"Mihi IoT 03"}
{"door":"4386","datetime":"2016-02-28 19:10:58","user_agent":"Mihi IoT 03"}

A have also installed Amazon AWS CLI, so php is also publishing the door event to Amazon SNS (Amazon Simple Notification Service) and I have created an email subscriber to the SNS topic.


The result of the project is: The door is open -> event is stored and email is sent.

BatteryDoorSensorWifi5 BatteryDoorSensorWifi4


If anybody is interested in my ESP8266 and ATtiny13A code, feel free to leave a comment.
I will update this post with results on how long 2xAA batteries survive. Since my other temperature battery project is still up and running after 1 month (sending data every 20 minutes), this wifi door sensor IoT project should live at leased 6 months – we will see… 😎


UPDATE 2016-09-11

I’m satisfied with battery life. On 2xAA batteries it was 3 months and I’m still testing 3xAA ant now it’s 3 months and still up and running. 😎
To handle 3xAA batteries I have changed the 3.3V power regulator to this one:



Related Posts

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 ...

ESP8266 – WiFiManager and EEPROM

ESP8266 WiFiManager EEPROM My next addition to previous projects battery-wifi-iot-temp-hum-soil-moisture-sensors and battery-powered-esp8266-iot-logger is to make wifi configuration smooth and fast.

Continue reading ...

ESP8266 & NRF24L01 Breadboard Adapter

esp8266 & nrf24L01 on breadboard

You can find several breadboard adapters for ESP8266 WiFi module or nRF24L01+ RF transceiver and also several DIY manuals how to create your own, but I decided to use my new WiFi WSP8266 and NRD24L01 as soon[…]

Continue reading ...