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:
- Battery powered ESP8266 IoT – Temperature and Humidity DHT22 logger
- ESP8266 Temperature Humidity IoT Logger
- ESP-01 programmer
- Low power (5microA) ATtiny13A project as a power switcher
- Programming ATtiny13A via Arduino
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:
- ATtiny13A is in deep sleep every 2 seconds
- ATtiny13A makes HIGH Door Pull-up resistor pin
- 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.
- 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.
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.
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
- ESP source code: gitlab.com/snippets/25926
- ATTiny13A source code: gitlab.com/snippets/25925
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: http://www.ebay.com/itm/2-in-1-DC-DC-Step-Down-Step-Up-Converter-1-8V-5V-3V-3-7V-to-3-3V-Power-Module/271873956073
Hi
Do you have some results on battery life time ?
I don’t understand something, does door sensor trigger ATtiny13A or must we wait that ATtiny13A wake up to trigger event ?
So how much time does it take to get open / close notification ?
Thank
I have it on 2xAA batteries (tesco power Hi tech) and it is up more then 2 months now and still up and running. I have 319 readings and batteries have still 3.05V. Based on my other project http://homecircuits.eu/blog/battery-powered-esp8266-iot-logger/ it should last more then 4500 readings. With average of 160 door readings a month it should last more then a year (theoretically 28months).
ITtiny13A is waked up every 2s. So every 2s it checks the sensor. If the door is open in starts wifi for 4s (this is enough for ESP to send data). If not it goes to sleep again.
Hi. Thanks for a nice project! Is it still up and running? 🙂
Yes, still up and running. 🙂 My another project http://homecircuits.eu/blog/battery-powered-esp8266-iot-logger/ is running now for 30weeks on 3xAA (powering SI7021 temp&hum sensor). In a week 22 I just removed the power regulator and added a capacitor on batteries.
Could I take a look at the code for both ATTiny13A and ESP8266 please?
I have update post with links to the source code.
Thank you Tomas. Just so you know.. it seems the pin 2 and 3 are swapped in the fritzing diagram.
I’m thinking of building something like this, and I have some ideas:
Could the door sensor itself (if N/O (normally open)) be used to wake up the ESP8266 or ATTiny13A directly?
That way the ATTiny13A would only need to wake up once a day or something to send a “I’m still alive” status message.
I think you could get years out of a battery if that is the case. (Depending on the number of opens per day)
My plan was to use it on a storage facility, so the door would open perhaps one per month 🙂
Can we connect this to a buzzer and LED strip to indicate door open ?
Instead of using the ATtiny13 as a relay why not bypass it with a simple switch.
1 http://www.esp8266.com/viewtopic.php?f=11&t=4458&start=4
2 https://www.hackster.io/noelportugal/ifttt-smart-button-e11841
https://uploads.disquscdn.com/images/39ff54a805809a125afdd09894a042a1c67681869b445ba31374938b239876f9.jpg
I found where you can use a mosfet or relay to hold power on long enough to get work done. But other the whole circuit is powered off. This would work where you need a switch closure to start something and then the mosfet or relay holds the power until everything is done. Great for a door sensor.