Door Unlocker. Wouldn’t it be great if you could…
By: David Klempfner
Tags: DIY, Programming, IoT, Electronics, Arduino

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

With this?

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

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.

The final product

Benefits

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. Carry fewer things — Instead of carrying around 2 keys (main entrance and unit)+ phone, you only need to carry around 1 key + phone. Be notified— You can connect a small buzzer to the ESP32 which plays a tune when someone has opened the door via the URL. 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. Unlock from anywhere — The main door can be opened via phone from anywhere, without the need to access the unit intercom. COVID19 safe — No need to press the buttons at the front door.

Features

When you access the URL, the intercom button will be activated for 500ms. If the password is correct, a tune is played for 2 seconds to notify anyone in the unit that someone has unlocked the door. There’s a switch to deactivate the tune in case it gets annoying. 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. 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.

Issues and resolutions

Here are some issues and resolutions:

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

Security

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

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

Hardware

Total = $62.80AUD

Hardware you should already have:

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

Software

USB to UART Bridge VCP Drivers drivers Arduino IDE

The process

There are five parts to this:

Modify the intercom Set up the ESP32 Set up the software Set up internet access 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.

Inside of the intercom.

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:

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.

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.

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.

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.

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.

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.

Setting up the software

Drivers

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

Arduino IDE

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.

Tone32.h library

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.

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

Static or dynamic IP address?

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”:

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.

Smoke test

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

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:

and this in the serial monitor:

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.

Get your router’s IP address

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

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

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

Access your router’s settings page

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

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.

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.

The URL

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.

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.

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.

Switch for the buzzer.

Power supply port.

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 :)