Introduction: IoT Door Alarm UPGRADED

Picture of IoT Door Alarm UPGRADED

In a previous Instructable I described how to make a $4 Wifi Door Alarm using a ESP8266 #IoT.

This involved ESP8266 flashing with the ESP8266 Basic platform.

This platform is a great software for beginners but has some limits:

  • It takes a long time to boot, connect to the Wifi and then run our program (about 1 minute to obtain the notification after the alarm is triggered)
  • It can get stuck and drain the batteries

As I'm a software engineer I looked for a more custom solution.

In this Instructable I will share with you another way to flash the ESP8266 and the algorithm I invented to provide several enhancements and features for the Wifi Door Alarm:

  • Speed up Wifi connection (10 seconds to obtain the notification after the alarm is triggered)
  • Go back to sleep after several unsuccessful attempt to connect to the Wifi
  • Several trigger attempt in case it didn't work the first time
  • Batteries voltage monitoring
  • Several doors can trigger the same IFTTT recipe indicating which door triggered it


  • No OTA (over the air updates)
  • Need disassembling each time we need to do an update of the software.

If you like this Instructable, please vote in the IoT builders contest!

Step 1: Install Arduino IDE

Picture of Install Arduino IDE

First we need the Arduino IDE to compile and send the new firmware to the ESP8266.

Download it from the official website and install it on your system.

Once it is installed open it and follow this tutorial to add the ESP9266 compatibility.

You can configure your IDE as the screenshot attached.

Step 2: Change Your IFTTT Recipes

Picture of Change Your IFTTT Recipes

We need to use a Maker event that is more permissive so it can be used with any door alarm in your house.

Go to you IFTTT account and edit your recipes:

  • Change the name of the trigger event to door_alarm
  • Change the email subject to Home intrusion alert: {{Value1}} door.
  • Change the email body to the following:
    The {{Value1}} door has been opened!
    When: {{OccurredAt}}

    Batteries: {{Value2}}V

  • Don't forget to push the "Update" button.

Step 3: Prepare the Firmware

Picture of Prepare the Firmware

Download the enclosed Arduino script and open it with your Arduino IDE.
There are several places where you want to put your own values:

  1. SSID: enter the name of your wifi network
  2. PASSWORD: enter the password of your wifi network
    • replace {event_name} with door_alarm
    • replace {your_maker_key} with the key given in the Maker IFTTT channel
    • replace Front with the name of the door (e.g.: Front for front door, Kitchen for the kitchen door, Garage etc.)

If you know a bit about programming you can tweak the other constants.

Step 4: Upload the Firmware

You will need to disassemble your door alarm to have access to the GPIO0, Rx, Tx, GND and Vcc pins.

Solder a wire between GPIO0 and GND.

Connect your USB programmer to the ESP8266 as described in step 2 of the previous Instructable.

Connect your USB programmer to your computer and hit the upload arrow icon on the top left corner of the Arduino IDE.

If you want to debug you can simply open the Serial Monitor clicking the magnifier icon on the top right corner of the Arduino IDE, make sure the bauds rate is set to 9600.

Once uploaded the ESP8266 will reset automatically and run the program. You will receive the notification very shortly.

Disconnect the USB from the ESP8266 and remove the connection between GPIO0 and GND.

Reassamble your door alarm and voila!

Step 5: Conclusion

Now that your Door Alarm is upgraded you can take some time to look at the algorithm.

If you think about any enhancement, or if you have any correction/suggestion in mind, feel free to post your comments below!

Thank you for reading!


adicontakt (author)2017-09-25

i am getting this error when i try to compile

"'HTTP_CODE_OK' was not declared in this scope"

ClemRz (author)adicontakt2017-09-25

Hi, it is possible that you did not import the ESP8266 libraries correctly. This constant is defined inside ESP8266HTTPClient.h


corky402 (author)2017-08-06

Hi there

Can anyone help with an error I'm getting when I'm trying to compile the code for uploading? I've attached the error log below.

Cheers in advance



Arduino: 1.6.7 (Windows 10), Board: "SparkFun ESP8266 Thing, 80 MHz, 921600"

C:\Users\John\Desktop\WIFI alarm\FNJPZPPIU9VFGO9\FNJPZPPIU9VFGO9.ino: In function 'void setup()':

FNJPZPPIU9VFGO9:57: error: 'getAvgVcc' was not declared in this scope



FNJPZPPIU9VFGO9:58: error: 'initSerial' was not declared in this scope



FNJPZPPIU9VFGO9:59: error: 'initWiFi' was not declared in this scope



FNJPZPPIU9VFGO9:62: error: 'httpGet' was not declared in this scope



FNJPZPPIU9VFGO9:64: error: 'goToSleep' was not declared in this scope



exit status 1

'getAvgVcc' was not declared in this scope

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences.

corky402 (author)corky4022017-08-07

Ah! Perfect, problem solved! Thank you very much it works perfectly now

ClemRz (author)corky4022017-08-07


The compilation errors you are showing indicate that the sketch is incomplete. Try to download it again and make sure you edit it with the latest version of Arduino IDE.

adicontakt (author)2017-07-08

I have another problem , i can"t make the IFTTT work. I read and make evrything that said in this link but i don"t get any email

ClemRz (author)adicontakt2017-07-10

Hi, have you read this?

adicontakt (author)ClemRz2017-07-10

yes , and I am stuck also , now is a different Maker on IFTTT , is called Maker Webhooks

ClemRz (author)adicontakt2017-07-10

Wow, I didn't notice that. I'll have to have a look at it.

adicontakt (author)2017-06-18

it will work with an regular switch?can you make the project to work with an instant push notification like ?

ClemRz (author)adicontakt2017-06-19

Yes you can make it work with a normally open momentary push button. It can also trigger this instapush notification. Reading the documentation there is a CURL query which you can use.

HusamA6 (author)2017-02-21

Hello dear

How are you I wish you good, I want you to help Excuse in the project subject door alarm, and I want to go into the midst of the project and its implementation in reality, is it I can I could get accurate information from you. Thank you so much

WannaDuino (author)2016-10-24

but stil i want to know, what the battery and the WHEN part of ifttt is for

i hope it are values that check my battery status and the WHEN the time its opend or where. (yes the mail tells also when ) but not at that moment.

but i am all ears friend

ClemRz (author)WannaDuino2016-10-25

Oh! I got it! Yes the bateries voltage is read internally in the ESP and sent via URL parameter to IFTTT, the same as the door name. The WHEN value is not the exact time the door is opened but the time when IFTTT receives the trigger event.

WannaDuino (author)ClemRz2016-10-26

wow i am amazed that its realy can read the voltage,
man, how do you think and come up with that. sorry but you realy are a wizard or so.
thats awesome man.
but i still dont get it or dont know how i can chech of it is good, and if i EVEN DID IT GOOD.
what are you suggest friend,(ask me for pictures , and i post it or mail me.its faster. the voltage reading I WANT REALY BAD.
if we mail than pleace by PM, then i gife mail. only if you think its oke afcorse

WannaDuino (author)WannaDuino2016-10-26

the time is not correct in my time zone. how can i change that?

it says 06:45 PM oke almost good it was 18:45 PM is that changeble?

ClemRz (author)WannaDuino2016-10-26

The timezone can be changed in your IFTTT preferences:

WannaDuino (author)ClemRz2017-02-19

you are so cool, it still works friend,

ClemRz (author)WannaDuino2016-10-26

To make sure it is working properly put new batteries and turn the alarm on. You should receive an email within 10 seconds or so. Copy an paste the body of the email here.
Then repeat with used batteries and past the email here again.
This way I will be able to tell if everything is ok.

WannaDuino made it! (author)ClemRz2016-10-26

i got it already working.

again the code part was the problem

look at my pictures 5 minutes before i finaly seen it. and tested it. in these pictures you wil see DEFENTLY what i did wrong. I REALY NEED UP SCOOLING MY ENGLISH AND CODE KNOWLAGEMEND of arduino.

but hee i am WannaDuino

in the last pic NR4 its good, but can i change ( open the door ) to

De Brievenbus is geopend ?? it means the mailbox has opend

ClemRz (author)WannaDuino2016-10-26

Hey, why don't you set ?value1=Brievenbus in the url of your code?
This way in the Subject of your IFTTT recipe you could use:
De {{Value1}} is geopend

{{Value1}} will automatically be replaced with Birevenbus.

WannaDuino (author)ClemRz2016-10-27

again thank you for all your help man.

the battery part that you made ( i am amazed that its even possible in this tiny chip.)

what can this thing do more???

i am stunned.

you rock and i hope you wil win, have again VOTED for you

i hope i understand this

so in the code i must chache it to BRIEVENBUS

and in the IFTTT receipy IS GEOPEND

that means that i must re upload the code in bootmode

i am realy liking arduino man, now even more because of you.

thats how i call this, maybe its called somthing else, but for me this is ARDUINO stuff. cool as hell.

SO EVERYBODY WHO READS THIS. VOTE for this guy. pleace

relox (author)2017-02-16

Hey ClemRz,

really great work, an easy cheap and great sensor
for IoT. Thx a lot for your time. I like to use your kind of sensor for
my tado heating system. The senors should switch of heating and turn it
on again when the window is closed. I was thinking of a variable status
to triger two different IFTTT aktions, but with every reset, the
avariable will be deleted or not?

thx a lot for your ideas and time :)

ClemRz (author)relox2017-02-16

Hi, thanks!
You can use several ways to keep a variable despite the resets and the power going off. Basically you make use of the EEPROM, here are some basic examples:

I also love this library to read/write "files":

And JSON is my favourite format for storing several variables/structures:

Good luck!

KevinV126 (author)2016-12-30

Nice work! But I wonder, how long do the batteries last?

Wouldn't it be better to have the reed switch power off/on the ESP8266, then use one of the GPIO on the ESP8266 to power the ESP8266 itself using a transistor? Something like this?

ClemRz (author)KevinV1262017-01-27


In the new version of the custom code for the ESP (see here: I added a way to monitor voltage level.

I have it running for months now. The lifespan of the batteries will depend on many things such as battery quality, times the door activates the alarm, room temperature etc.

I tried to make the circuit as simple as possible that's the reason why I chose deep sleep versus transistor.
The ESP has a very low current consumption during deep sleep and I think that most of the energy is consumed by the wifi connection anyway.

Thanks for the suggestions!

MOHAMMEDa389 (author)2017-01-14

will this project work on Esp8266 (01)?

WannaDuino made it! (author)2016-10-24

UPDATE 30min later


LOOKS THAT WHAT I WAS SAYING ABOUT EXACT TYPING IN THE CODE, IS A FACT man what a fight was that. iwas fighting with the { } and the _ as a space. NOT but also your recipy name must be exact.but what is that with the BATTERY falue. i dont get it. in ifttt i put a voltage of 3.3Volt in but every time i get the same value not changed or so.???? and by when i put a time in on that moment, also not changed. is that possible.becous you talkt about the batterys Value dropping and that we see it

ClemRz (author)WannaDuino2016-10-24


I will do some tests to see where the battery-voltage-reading issue is coming from.


WannaDuino (author)2016-10-24

look. this is myne and this picture is from the other maker here on your message bord

how to EXACTLY put the text in the code i must put in there, what is importand for me, is the symbols you use and so,(becous i am still not formiliar with arduino code langue

like this( {}_# ) looks as wizard code to me.

WannaDuino (author)WannaDuino2016-10-24

the code i mean the REAL code

not whats in the picture,(thats becous of the WRONG coding of my part) hahaha

picture is for you to see my HTTP401 message and his is HTTP200 and congratulations message, i also not have

ClemRz (author)WannaDuino2016-10-24

Hi, this might be due to the fact that you left the { } and replaced the _ with spaces. I think you got it now! ;)

astroscimmia made it! (author)2016-10-17


WannaDuino (author)astroscimmia2016-10-24

your smart to

i cant get it to work now with the update.

ClemRz (author)astroscimmia2016-10-17


WannaDuino (author)2016-10-24

i dont get any messages anymore i think it has 1 with the VALUES to do in IFTTT to do ( must that be EXACT in the code as on the IFTTT??


and in the code what and how must i put all in?(with the {} thingys or not

and with these ( # ) thingys see pictures

also i get an HTTP 4oo and now a 401 message (warning i think.

its conecting and say go to sleep/

no more gratulations? boehoeoeoeoe (thats me crying)

WannaDuino (author)2016-10-21

heee big helper

i use windows!

how is it then?

and i already as you know have the 1e IBLE build but not yet put together as you mentiond, that i need to do this upgrade (SUPERRRRRR)

how does it work then ?

need i also change the IFFF recipies i already have? i have the mail alarm, and i managed to put ALSO the sms alert in the ESP. thanx for that also.

ClemRz (author)WannaDuino2016-10-21

You will need to update the IFTTT recipies you already created, not complicated at all.

WannaDuino (author)ClemRz2016-10-22

thanxxx, big friend.
i already mentioned you in some other ible`s, to check you out.
you are good for us on INSTRUCTABLES.
I can not thank you enough.
greetings from WannaDuino (Simon ) from The Netherlands

ClemRz (author)WannaDuino2016-10-21

Hi, this IBLE is for both OSX and Windows. You shouldn't have any difficulties! ;)

WannaDuino (author)2016-10-21

and i askt you if i had to remove the gpo to ground that i solderd just as you together, but i did that, and it did not work anymore.

i think you mis understud me? i mean the gPO15 to ground.(the first 2 pins solderd together. and i reconected it with some solder at the bottom of the pcb, and now it works again.

was i mistaking or did you mis undersud me? i need to know.!!

its the gpo thats go to the switch to gpo8 (it looks like an 8)the 4th pin.

ClemRz (author)WannaDuino2016-10-21

Oh, right, the GPIO15 should remain connected to GND. I thought you mentioned GPIO0 (zero).

The switch is just here to turn on/off the main power, it should be connected to ESP VCC pin on one side, and to the +ive connector of batteries holder.

I hope you'll make it! :)

experimentool (author)2016-10-20

How are you doing the batteries voltage monitoring without using an analog pin on the esp8266?

ClemRz (author)experimentool2016-10-20

Hi, reading the ESP8266 datasheet you will find, chapter 3.9 that the ADC can be used in 2 applications:
- test the power supply
- test the input voltage of pin 6

In this Instructable we just need to test the power supply. The Arduino ESP8266 API provides a way to do so. Looking at the code you will notice this line at the beginning:
This is how you allow the ESP to look at VCC instead of Pin 6.
Then you will also notice the way we read VCC:

More info about the API:

If you need more information feel free to ask.


experimentool (author)ClemRz2016-10-20

Thank you for the information. I did not know that the battery voltage could be read without using an AD input pin. I now have it working on an esp8266-01.

WannaDuino made it! (author)2016-10-18



i only need to upgrade to this. upgrade, and i wil be happy.

but i had 2 qustions in the making IBLE of this, pleace reply friend, i realy need the brains from you. to have it 100%

so if any person needs help? message me. or check his Make ible out i have put a lot of pictures and info there also

ClemRz (author)WannaDuino2016-10-19

Thank you WannaDuino! Great job! You did it!

WannaDuino (author)2016-10-17

this guy is amazing smart

About This Instructable




Bio: I'm a web developer and I enjoy outdoors a lot
More by ClemRz:WiFibonacci ClockTepee-shaped Kid's BedMr. Potato
Add instructable to: