DIY Zone Door Sensor to send push notification using esp8266 Reviewed by Momizat on . Sensors with Push notification is always fun. In this article we will Connect a door sensor to wifi using ESP8266, so that, we can send push notification to our Sensors with Push notification is always fun. In this article we will Connect a door sensor to wifi using ESP8266, so that, we can send push notification to our Rating:
You Are Here: Home » IOT » DIY Zone Door Sensor to send push notification using esp8266

DIY Zone Door Sensor to send push notification using esp8266






Sensors with Push notification is always fun. In this article we will Connect a door sensor to wifi using ESP8266, so that, we can send push notification to our mobile, when somebody opens or close the door.

Bellow will be the flow of our project.

Door sensor——–>  Node MCU—– > Our Server Side Code—– > instapush——> android application

Let’s start one by one.

Door Sensor:

Inside a door sensor, there are reed switch, which make a close connection when somebody place a magnet near to it.

my-electronics-lab-door-sensor

If you don’t have a door sensor Click here To purchase.

Node MCU:

NodeMCU is a esp8266 based breakout board, having USB to TTL on board for programming. Below is the pinout of NodeMCU board.

my-electronics-lab-NodeMCU

 

Note: On Board GPIO number like D0, D1, D2, etc are not the real GPIO in node MCU board.

The  GPIO number , given in the above image inside red box,  are the real gpio pins to use in your arduino sketch. If you are new to ESP8266 wifi programming, you can follow my previous tutorial.

Circuit Diagram:

my electronics lab door sensor sch

If you will see the schematic, you will see D1 that is GPIO5 is connected to the Door Sensor.  With a Pull Down Resistor which is connected to D1 to GND. So when the magnet part of door sensor comes closer to the reed switch, D1 i.e GPIO5 goes high.

[InsertAddForPost_square]
Let’s write Code to detect The door is pressed and send notification to the server:

If you will see the above code, I have calling two php file , which are hosted on my server.

sendDoorCloseNotification.php and SendDoorOpenNotification.php.

[InsertAddForPost]
This two file request to the instapush server. In this project we are using instapush to send notification to mobile phone. If you have no idea about android programming or GCM, then I strongly suggest use instapush, this is best free application to test push notification.

You can download the both Php file and the library for Instapush Here or you can read the documentation directly from the Instapush server here.

 

 

About The Author

I am a maker, who loves to think, hack and build new electronics stuff, I always find time to document , share my knowledge with others. I am graduate in BTech(Electronics and Communication Engineering).

Number of Entries : 41
  • Aldo

    thanks a lot….Big Man!!

    • You are welcome, subscribe to our youtube channel and blog for more tutorials like this

  • Shyam

    Hey! I am trying to make This project and I have occur one problem in the codes it show me one error that is “unexpected symbol near #” how can I fix that pls help me.

    • Can you please more clear on your error, which code arduino or php, which line, please be more specific,

    • Shyam

      I have edit the code my ssid”lovely printer” and my password is “[email protected]” and I also edit the php codes and I copy php codes and paste into my c code and when I upload my code they show me that error and that is “unexpected symbol near #” i upload my code through explorer and I also flash my ESP before uploading the code.

  • Shyam

    Which value resistors did you use?

  • Shyam

    Pls tell me how can I host the php files in my server

  • Rakesh

    Thanks sir

  • Pramod Kumar

    Hi, when I execute the code, if( digitalRead(pirPin)==HIGH)
    SendDoorOpenNotification(); I get a message as follows on the serial monitor . Requesting URL : / test / SendDoorOpenNotification.php. Open
    I am not getting a notification on my mobile. I registered in the instapush site, made the changes in the key in the php files and added the files to the arduino IDE. I have downloaded and installed the APP on my mobile and have logged in.

    What am I missing? Could you let me know?

  • Pramod Kumar

    Hi, I am not getting the mobile notification, even after making the changes in the php files and logging into the app on my mobile.

    if( digitalRead(pirPin)==HIGH)
    SendDoorOpenNotification();

    I get the message on the serial monitor, but not on the mobile.

    Could you let me know what I am missing?

    Thank you.

    • satya sankar

      Please, debug step by step, look for php code, look for response, are you sure you are getting web request and response successfully. ? may be some server side issue , step by step approch is needed.

  • Peeter S

    Hi,

    your script and scheme works fine when i have esp8266 connected 1) with usb cable and to computer. (power supply from pc-s usb).

    2) When i use usb cable with switch cable (like this: http://www.ittgroup.ee/en/wires/662-mikro-usb-cable-with-switch.html?search_query=Mikro+USB+cable+with+switch+&results=1)
    and 5V supply comes from wall-plug (and not from computer usb) then it doesn’t work.
    Then led starts to blink when reed switch is away from magnet (door is open) and openclosenotification.php makes hundreds of writings on harddisk…

    any idea why is that so? Cable issues? May be need other resistor (instead 1K)?
    Or this isn’t about resistor value?

    please info about this if u know some help…

  • Peeter S

    Hi

    i have connected circut diagram and uploaded the code.
    When i supply /connect circut with computer via USB cable it is working fine.
    No mobile notification used, only php files will write info to logfile.
    SendDoorOpenNotification and SendDoorCloseNotification will write data to logfile once per each opening and closing. All correct.

    But, when i connect /supply circut with USB cable with switch and from wall outlet,
    then SendDoorOpenNotification gives hundreds of times in minute that door is open, led blinks randomly and writings number. Its like reed switch status is changed many-many times in minute or even in seconds.

    Any idea why this is so? Need to replace resistor from 1K to higher (2K)?
    Anyone experienced the same?

  • Kush Manchanda

    Hi, do I have to make my own server for this ?
    Please help
    and also after rebooting my ESP-01 , the program is lost and I have to flash it again . HELP

    • My Electronics Lab

      Hello, yes you need to host on a php server, you can host it for free on hostinger.in , and you are loosing code after reboot, I never faced this issue, give more input, so that i can clear about it.

      • Kush Manchanda

        Thanks so much for replying .
        Yes It was getting into flash mode after reboot I sorted that out.
        I am a noob at php , so I should just host those files on that server and use which address in the host part ?

        • My Electronics Lab

          No sound means? 🙂

          • Kush Manchanda

            No sound on push notifications .
            Also I am not getting push notifications , but it does show in My Instapush app “What’s going on today ” and not on my homescreen . Help Please.

      • Brundha Sholaganga

        hi,what files we need to upload the instapush.php also?

  • Sheikh

    Hi, I’d like to add another switch to the sketch, is it possible? If yes, then how would I go about doing that. Nice post btw, thanks!

  • negrito

    Hi Satya, Nice project! Can you alter the code, so I can use the same
    principle for my mailbox with a Microswitch instead of a Magnetic Reed Switch? To receive one message when the postman open the hatch and put some mail in my mailbox.

    Kind regards,

    • adicontakt .

      it will work easy with anykind of switch without changing the code

  • Jitendra

    Nice Project. Very neat and clean. I have one query. In the schematic, you have used Pull Down resistor. Which is more recommended in case of magnetic sensor (i) Pull up resistor or (ii) Pull down resistor. ? Also what is the recommended resistance. ?

  • Nitin Gautam

    Thanks Satya. I want to put wireless power source what are all options

    • Nitin Gautam

      Satya can you please reply?

    • My Electronics Lab

      Hello, Yes can add 9V battery with a regulator, that should work.

Scroll to top