Smart IoT Intercom Buzzer¶
Old apartments will usually have an intercom buzzer system that uses simple analog signals. A D1 Mini can be connected to these systems to provide a remote unlock function so that we can open the door without a key. This is achieved by setting up a simple web server that triggers a relay to open the door when a client accesses a it (and provides a password/secret phrase).
Pre-flight checks¶
It's a good idea to check everything first and have a brief idea of what we are working with.
Below is the wiring diagram provided by the system's manufacture, I've simplified and highlighted the voltages.
If your system is not similar to the wiring below, it's probably best not to proceed unless you're 100% sure what you're doing, proceed at your own discretion.
12VDC (Green L1/RL/11
and L2/RL/L2/14
are 12VDC, they're used for voice transmission, therefore the voltage fluctuates, which is not great. We don't want to fry our board by accident if voltage suddenly rises. It's also worth noting that these 2 wires not have a lot of power, and voltage drops significantly if we try to use it to power the D1 mini.
List of components¶
Buck converter (step-down converter) x 1 *
D1 Mini (or any ESP8266/ESP32 board) x 1
2N700 N Channel MOSFET x 1 *
SRD-03VDC Relay x1 * **
* Components can be replaced with the alternatives below.
** If you switch out the D1 Mini for another board, make sure your relay uses the same voltage as the GPIO pins on that board.
Alternatives¶
Buck converter is not needed if you're using external power.
5V USB Charger
2N700 MOSFET and SRD-03VDC Relay can be replaced by a single relay shield.
D1 Mini Relay Shield
D1 Mini and be replaced with another ESP8266/ESP32 board, but check the spacing inside the intercom to make sure there's enough room.
Arduino Sketch¶
// Include libraries for ESP8266 to connect to wifi and set up a webserver
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
// Credentials for your Wifi
#define SSID "WIFI_SSID"
#define PASS "WIFI_PASSWORD"
// State the pin to use to trigger the relay
// check online to ensure pin is usable, some pins cannot be connected when booting
// https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/
// as this board will be inside the intercom, it'd be inconvenient to reset after power outages if the wrong pin is used
int pin = D1;
// Create a webserver instance
ESP8266WebServer webserver(80);
// Function to handle unclocking the door (triggering the relay on and off)
void unlock() {
// Pseudo security measures, will only trigger relay if a specific secret phrase is provided as an argument in the URL
if(webserver.hasArg("secretPhrase")) {
// Trigger the relay
digitalWrite(pin,HIGH);
// Wait 1.75 secs to ensure the relay has switched
delay(1750);
// Door is opened, turn of the relay
digitalWrite(pin,LOW);
Serial.println("Door unlocked");
}
Serial.println("Correct URL");
// Provide some message in text/html format
webserver.send(200, "text/html", "Door has been opened (?)");
}
void setup() {
// Set your signal pin to output and set it to low
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
// Start serial so we can find the ip of the board easily
Serial.begin(115200);
Serial.println();
// Connect to Wifi
WiFi.begin(SSID,PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
}
// Print the board's IP when connected
Serial.println();
Serial.print("Connected! IP address: ");
Serial.println(WiFi.localIP());
// Run unlock function when client navigates to http://ipaddress/unlock
// do note that door won't actually unlock unless the secret phrase is also provided
// to unlock: http://ipaddress/unlock?secretPhrase
// "/unlock" can be replaced with "/" or any other page
webserver.on("/unlock", unlock);
// Start the web server
webserver.begin();
}
void loop() {
// Handle Clients
webserver.handleClient();
}
Now open serial monitor, and try connecting to the IP of the board, play around with the page and arguments and watch the the log to make sure everything is running correctly.
Serial commands can be deleted if everything is working as it should and you don't need debug info.
Reserve and Static Address¶
Since the relay only gets triggered if you access the webserver, you'd need to know the IP address for the D1 Mini, AND make sure it doesn't change.
Log in to your router and you should find something called DCHP IP reservation / Reserve address
or something among those lines, as each router have different UI and naming convention, consult the help guide/user manual for your router.
Note
If you can connect to your home wifi at the door, then you may skip the rest of this section. Or continue if you want to unlock your door remotely from anywhere.
Since the IP that we have been using up till now is provided by the router (192.168.x.x), and not the ISP, it would not work when not connected to the router wifi. To connect to the D1 Mini outside our network, we need a static IP from the ISP.
After obtaining a static IP, we still cannot access the D1 Mini with that static IP, since modem/routers have firewalls that'll block connections initiated from an external connection To solve this, we simply port forward port 80 to the D1 Mini.
Again, as each router have different UI and naming conventions, consult the help guide/user manual for your router to figure out how to do port forwarding. Also, as each ISP have a different method of obtaining/applying for static IP, contact your ISP to set up a static IP.
Wiring Diagram¶
Now we simply wire up everything as below. Where EL
is the connection for the button to unlock the door on the intercom.
If you're wondering why we need the 2N7000 MOSFET, it's because GPIO pins do not output enough current to trigger the relay. A 3V relay will usually require 120~150mA to trigger, but a GPIO pin can only output 30~50mA max. The 3.3V pin on the other hand can output 500mA, so that's the pin to use when triggering the relay. BUT the 3.3V pin is constantly on when powered, therefore we use a MOSFET to break the circuit for the relay, so that we can control when the relay triggers. A MOSFET is basically like a relay.
If you're now wondering why we need a relay and not just use a MOSFET to bridge EL
and the negative terminal, pay attention to the wire coloring I've used. EL
is highlighted Brown
For convenience sake¶
Once everything is wired up and working as it should. The URL (http://staticIPfromISP/unlock?secretPhrase) can be saved as a bookmark or home screen shortcut on your phone to streamline the process.
Additionally, you can configure Bixby Routines / IFTT / Siri Shorcuts, so that the door automatically unlocks when you get near. This can simply be done by setting up a location based trigger, or a NFC tag.
Ready made solutions¶
There are already products on the market that does the same thing, like the SONOFF or eWeLink Wifi relay switches that are super easy to wire up and also offer voice assistant integrations. However, you'll be relying on their services, tho currently provided free of charge, but can change anytime in the future.
The pro of self made solution is that you don't rely on some other company's services, and you can also use the D1 Mini to do other things on top of door switching. Like using a GSM module/shield to forward your intercom to your phone; or use it to host a simple website on top of it unlocking for your door...etc.
D1 Mini can also connect to voice assistants similar to ready made solutions, but that's something for another day.