Door Unlocker

David Klempfner
May 18, 2020 · 11 min read

Wouldn’t it be great if you could replace this:

Image for post
Image for post

With this?

Image for post
Image for post
Website

The first photo is of the key I use to open the main entrance door to the block of units I live in. The second photo is a website I can use to unlock the main entrance door.

This tutorial will show you how to unlock the main entrance door with your phone, or any device that has a browser and an internet connection, by activating the button in your intercom that buzzes people in, thereby doing away with the need for a key.

Think of it as a remote control for your intercom’s button.

How it works

Image for post
Image for post

By the means below you can use your phone to access a website connected to the unit’s wireless network. The system communicates with the ESP32 (WIFI enabled microcontroller) and requires a password at the end of the URL.

Image for post
Image for post
The final product
  1. Save money — The key to your unit is cheap and easy to copy. The problem is with the main entrance door key. It can only be copied via the real estate agent and costs a lot of money ($50AUD). If you have 5 people who you’d like to give a spare key to, you’d have to spend $250. Or, you could spend $60 and give them all the URL to unlock the door.
  2. Carry fewer things — Instead of carrying around 2 keys (main entrance and unit)+ phone, you only need to carry around 1 key + phone.
  3. Be notified— You can connect a small buzzer to the ESP32 which plays a tune when someone has opened the door via the URL.
  4. Convenience — Family, Airbnb people, babysitters, cleaners etc can access your apartment in your absence, without fear of the expense of lost keys. After they leave, the password can be changed.
  5. Unlock from anywhere — The main door can be opened via phone from anywhere, without the need to access the unit intercom.
  6. COVID19 safe — No need to press the buttons at the front door.
  1. When you access the URL, the intercom button will be activated for 500ms.
  2. If the password is correct, a tune is played for 2 seconds to notify anyone in the unit that someone has unlocked the door.
  3. There’s a switch to deactivate the tune in case it gets annoying.
  4. If you have a dynamic IP address, the code will check every 6 minutes to see if your IP address has changed. If it has, you’ll receive an email with the new IP address. Your IP address is what makes up the URL used to unlock the door, so it’s important to be notified.
  5. If someone puts in a bad password 3x in a row, they’ll be locked out for three minutes, and a different tune will play from the buzzer to notify you.

Here are some issues and resolutions:

  1. If your phone battery dies, you’ll need to borrow a device that has a browser and internet connection. You should have the URL backed up somewhere accessible.
  2. The password is sent as plain text in the URL. Make sure you don’t access the URL while on a public wifi, otherwise anyone on that wifi could see the URL and your password.

Hackers will have a hard time getting access for the following reasons:

  1. They need to know your IP address. This can only be found if the hacker is on your wifi, or if you are both connected on the internet, for example through a direct file transfer using MSN messenger.
  2. They also need to know your password. If you use a long password with numbers and characters, then it will take them a long time to brute force the password.
  3. The hacker could attempt brute force by trying all IP combinations until it gets a response (“Incorrect password”), but if you have a dynamic IP address, your address would most likely change by the time they got to the right combination.
  4. If you put in a bad password 3x in a row, you’ll be locked out for three minutes. This prevents any brute force attempts from succeeding. A monotone will be played from the buzzer so if you’re home, you’ll know someone has attempted a bad password 3x in a row.

With all these together, along with the fact that a hacker would have to know where you live, and that you even have this device set up, there is no reason to worry. Even if they got access, the worst they could do is access the building, not your unit.

To be on the safe side, do not access the URL when on public wifi!

What you’ll need

  1. ESP32 — $14.50 (or $39.95 from Jaycar)
  2. Plug to socket jumper leads — $5.95
  3. Relay — $3.95
  4. Schottky diode — $0.80
  5. Buzzer — $4.95
  6. Switch — $2.95
  7. 2 x socket — $2.50
  8. Male plug — $1.45
  9. Female header strip — $2.50
  10. Heatshrink — $1.45
  11. Jiffy box — $3.45
  12. 4.5V Power supply for ESP32 — $19.95
  13. Wire — $1.35

Total = $62.80AUD

Micro USB cable (most people have this already if they have a phone charger), soldering iron, solder, multimeter, wire strippers, wire cutters, screw drivers, drill, computer, wifi router and the admin password (found on the back).

  1. USB to UART Bridge VCP Drivers drivers
  2. Arduino IDE

The process

There are five parts to this:

  1. Modify the intercom
  2. Set up the ESP32
  3. Set up the software
  4. Set up internet access
  5. Put it in a box

Modify the intercom

Please note: It may be advisable to obtain permission from your Strata Management committee before modifying the intercom.

Open the intercom, find the button that unlocks the main entrance door, and solder a wire to each of the two pins. On the other end of the wire, solder the male plug.

Most intercoms run on extra-low voltage (ELV), and therefore you can’t switch off the power to it, but because the voltage is so low, there’s no need to worry about electric shock. Check with an electrician to make sure your intercom is on ELV.

Image for post
Image for post
Inside of the intercom.
Image for post
Image for post
Wires attached to the button’s pins.

The relay will be used to short circuit those wires together, thus turning on the button.

Set up the ESP32

Here’s a schematic to help you follow along:

Image for post
Image for post

In the following diagrams, I’ve used heatshrink to cover exposed metal. This is highly recommended, although not essential, you could also use sticky tape.

Connect the relay to the female socket, and the diode to the relay.

Using 2x 40mm wire, solder the two pins on the relay which are furthest apart, to the outermost pins on the female socket. This makes up the circuit that will be closed when a voltage is applied, which will activate the intercom’s button.

Cut two lengths of 40mm of the plug to socket jumper leads, keeping the female side. Solder these two wires to the two pins left on the relay.

Image for post
Image for post

Don’t put the heatshrink up as high as I did in the above photo, otherwise it’ll be hard to solder on the diode.

Solder the diode to the relay, across the two pins that power the coil. You can put the diode either way around. Read this to understand why the diode is necessary.

Image for post
Image for post

Connect the switch, the buzzer and the power supply socket:

Cut 3x 40mm of the plug to socket jumper leads, keeping the female side.

Solder one to the middle pin in the switch, one to each of the outer pins of the other female socket. This will be the socket for the power supply.

Solder 40mm of wire from the positive terminal of the buzzer to either side of the switch. Solder another 40mm of wire from the negative terminal of the buzzer to the ground terminal of the female socket.

Image for post
Image for post
How the switch, buzzer and power supply socket connect to each other.

Connect everything to the ESP32:

Connect the ground terminal wire (the side that sticks out) of the power supply socket to the GND terminal in the top left of the ESP32.

Connect the other wire of the socket to the Vin pin next to it.

Image for post
Image for post

Connect the wire from the switch to the RX2 (GPIO16) pin. This will control the buzzer tune. The switch will be used to turn on/off the buzzer in case it gets annoying.

Connect the wire from the relay which is connected to the cathode of the diode (marked with a stripe), to the TX2 (GPIO17) pin, and the other wire to the GND pin just a few pins down.

Image for post
Image for post

Cut the 40-pin female header strip so you’re left with 13. Cut off the exposed metal on the header strip. Attach this to the remaining pins for insulation. Use the rest to insulate the other exposed pins.

Image for post
Image for post

Setting up the software

Install the USB to UART Bridge VCP Drivers, then plug in your ESP32 and make sure you can see it in Device Manager:

Image for post
Image for post

Then follow the instructions here to add the ESP32 board to the Arduino IDE.

In the Tools menu, make sure you select “ESP32 Dev Module” for the board, 115200 for the “Upload speed” and whatever com port number is assigned in Device Manager.

Download the library by clicking on the “Clone or download” in this link and download the.zip file. Include the library in the Arduino IDE by going to Sketch -> Include library -> Add .ZIP library.

You’ll need to install this library. This is to help lock out the user for three minutes when there has been 3x bad password attempts.

Before you upload the code, you need to know if your IP address is going to change (dynamic), or stay the same (static).

To find out, open cmd and type ipconfig /all.

Find your wifi adapter, and check if it has “yes” next to “DHCP Enabled”:

Image for post
Image for post

If it has yes, then you have a dynamically assigned IP address.

Follow the steps in Static IP Address Code, or Dynamic IP Address Code and then come back here when you’re done.

Once the code has been uploaded, make sure it eventually looks like this in the serial monitor:

Image for post
Image for post

You can see the IP address of the ESP32 listed there (10.1.1.172), your IP address will most likely be different to mine.

Open up your internet browser and go to http://<IPAddress>:301/passwordToOpenDoorFromTheCode.

eg. http://10.1.1.172:301/87

You should see this website appear:

Image for post
Image for post

and this in the serial monitor:

Image for post
Image for post

If you see this, congrats! Everything is working as expected!

The favicon.ico requests are normal. You can read more about that on Google.

Go ahead and try an incorrect password at the end of the URL. It should say “Password is incorrect”.

Plug in the cable from your intercom, into the socket attached to the relay in the ESP32. Connect your power supply to the other socket.

Get someone to go down to the main entrance door and give it a test!

If you have access to your wifi from the main entrance door, then you can skip the next section.

Accessing it from the internet

Only accessing the device from wifi increases the security, because a hacker would not only have to know your IP address and your password, they’d also need to know your wifi SSID and password.

However, most people don’t get a wifi signal from the main entrance. This step will show you how to access the ESP32 from the internet.

Open command prompt by pressing the Windows key and entering “cmd”.

Type “ipconfig” and hit enter, it should display something like this:

Image for post
Image for post

Your router’s IP address will be listed next to “Default Gateway”.

Enter that IP address in your web browser to go to the router’s settings page.

Image for post
Image for post

Find the Port Forwarding link and click on it. Add a new port forwarding rule for your ESP32.

Set the “Destination IP” to be the IP address of your ESP32, which was displayed in the serial monitor output when you ran the code in the Arduino IDE.

The LAN and WAN ports should be whatever you set in the code. This should be 301 if you copied the code I provided.

Image for post
Image for post

What does this do?

When your router receives an HTTP request with the port specified as 301 (or whatever you set), your router will forward that request to your ESP32 based on the Destination IP address.

This means you can access your ESP32 from the internet.

Google “what is my IP” to find out your public IP address.

Once you have the IP address, you can type this into your browser along with the port and password.

eg: http://27.33.123.126:301/87

That should turn the switch on in your intercom for 1/2 a second, and play a tune for about 2.5 seconds.

Give the URL to anyone who needs access to your building :)

Put it all in a box

Drill three holes, two on the sides near the bottom of the box, and one on a long side in the centre.

Image for post
Image for post

Carefully screw in the sockets on opposite sides, and the switch into the middle hole.

Think about what side the power supply will be coming from before installing the sockets and the switch.

Image for post
Image for post
Installing the ESP32 and the peripherals.

Once you’re done, screw in the lid of the box. For a nice touch, you can add labels for the sockets and the switch.

Image for post
Image for post
Switch for the buzzer.
Image for post
Image for post
Power supply port.
Image for post
Image for post
Port for the intercom’s switch.

And that’s it! Using velcro tape, attach this box to the wall near your intercom and plug in the cables, and you’re done!

If you have any questions please reach out :)

The Startup

Medium's largest active publication, followed by +773K people. Follow to join our community.

David Klempfner

Written by

I’m a software developer who is passionate about learning how things work behind the scenes.

The Startup

Medium's largest active publication, followed by +773K people. Follow to join our community.

David Klempfner

Written by

I’m a software developer who is passionate about learning how things work behind the scenes.

The Startup

Medium's largest active publication, followed by +773K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store