Knock Knock – an Arduino Doorbell Telegram Notifier
by mayrs in Circuits > Arduino
1844 Views, 23 Favorites, 0 Comments
Knock Knock – an Arduino Doorbell Telegram Notifier
![knock_knock.jpg](/proxy/?url=https://content.instructables.com/FQG/RMJ8/LGRZQCT0/FQGRMJ8LGRZQCT0.jpg&filename=knock_knock.jpg)
![doorbell.gif](/proxy/?url=https://content.instructables.com/FUX/RTFX/LGRZQAPP/FUXRTFXLGRZQAPP.gif&filename=doorbell.gif)
In order to monitor my doorbell – an old mechanical one that is loud but only hearable in one room – I needed a solution. I wanted to use the least amount of third party code. Secondly, because passwords are involved and privacy is important to me, I needed a solution to hook into an existing system that does not need to have my data stored in an IFTTT like website. I wanted to have a local, anonymized solution. But the setup and maintenance effort should be minimal. It also had to be non intrusive as I did not want to open the doorbell or hook into it physically.
This contraption is positioned close to a doorbell and will send a Telegram message once the doorbell rings.
The device is an external addition thus does not interfere with the doorbell circuit making this an easy add-on for any situation where the doorbell hardware must not be altered. It is also a good beginners Arduino electronics project as the device is encapsulated in a box that only works with low voltages. Being battery powered it can be activated on demand. To make the most out of the 1400 mAh battery the device goes into deep sleep after one hour and can be easily reactivated via the push button.
Supplies
![parts.png](/proxy/?url=https://content.instructables.com/F8H/BR08/LGRZQAS5/F8HBR08LGRZQAS5.png&filename=parts.png)
Hardware
- D1 mini NodeMcu
- Battery shield
- Lithium polymer battery
- Sound sensor
- Rocker switch
- Push button
- USB panel mount cable
- Junction box
Tools
- Shrink tubing
- Small wires
- Soldering iron, solder
- Cutter knife
- Wire cutter for electronics
- Small/medium phillips screwdriver
- Power drill & 3.5 mm drill bit or a hole punch
- Dymo labelwriter
- VHB tape
- Hot glue gun & hot glue
Software
- Latest release of Arduino IDE
- The project code
Skills
- Patience :)
- Endurance for at least 2-3 hours
- Dexterity
Hardware Setup
![wiring_diagram.jpg](/proxy/?url=https://content.instructables.com/F89/5F9F/LGRZQAX2/F895F9FLGRZQAX2.jpg&filename=wiring_diagram.jpg)
![knock_knock_1.jpg](/proxy/?url=https://content.instructables.com/F34/ZVZE/LGRZQAQW/F34ZVZELGRZQAQW.jpg&filename=knock_knock_1.jpg)
![knock_knock_2.jpg](/proxy/?url=https://content.instructables.com/FH6/H85K/LGRZQAJY/FH6H85KLGRZQAJY.jpg&filename=knock_knock_2.jpg)
![knock_knock_3.jpg](/proxy/?url=https://content.instructables.com/FYR/47B7/LGRZQAQX/FYR47B7LGRZQAQX.jpg&filename=knock_knock_3.jpg)
![knock_knock_4.jpg](/proxy/?url=https://content.instructables.com/FTL/BTJI/LGRZQAQY/FTLBTJILGRZQAQY.jpg&filename=knock_knock_4.jpg)
![knock_knock_5.jpg](/proxy/?url=https://content.instructables.com/FDV/QW6K/LGRZQAS3/FDVQW6KLGRZQAS3.jpg&filename=knock_knock_5.jpg)
- Strategically mount the rocker switch and the push button in the junction box. Use a cutter to cut openings in the box and pressfit both devices.
- Strategically route the USB panel mount cable to the surface of the junction box (used to charge the system without opening the box). The linked model is secured with screws.
- Strategically mount the battery in the junction box (VHB tape works well).
- Desolder the female JST connector on the battery shield and solder extension cables between the female JST connector leads and the battery shield terminals. This is a good point to check polarity of the JST connectors and the battery: some batteries have the JST connector soldered on the other way!
- Wire the rocker switch in between the positive lead going from the female JST connector to the positive terminal of the battery shield (ensure enough wire for routing).
- Wire the push button in between RST and GND of the microcontroller (ensure enough wire for routing).
- Strategically wire the sound sensor to A0, 3V3 and GND of the microcontroller (ensure enough wire for routing).
- Drill small holes to the back of the junction box and hot glue the sound sensor to that position with the microphone facing the backside of the box.
- Mount the battery shield on the D1 mini NodeMcu.
- Connect the USB panel mount cable to the battery shield.
- Connect the battery to the female JST connector.
- Tidy up all cables and ensure correct spacing when closing the box.
✅ You're done setting up the hardware.
Telegram Setup
![botfather.png](/proxy/?url=https://content.instructables.com/FNK/3YWK/LGRZQAND/FNK3YWKLGRZQAND.png&filename=botfather.png)
The setup follows these instructions. For simplicity I tried to compress it even more in the following step by step list:
- Create a Telegram bot using @botfather (FAQ).
- Username: @<NAME>Bot
- Disable Allow Groups?
- Turn on Group Privacy
- The bot Token will be available once the bot is created. Write it down, you'll need it in a later step.
- Create a private group.
- Group name: MyPrivateGroup
- Group Type: private
- Warning: Do not edit special permissions for users as this will convert the group into a supergroup which does not work with this code.
- Temporarily enable Allow Groups? on the bot.
- Add the bot to the group.
- Immediately deactivate Allow Groups? on the bot after adding it to the group.
- Post a test message into the group via the app or the browser (required to get the next step running). Start message with a / in order for the bot to be able to read it (Group Privacy is turned on by default).
- Retrieve group chat_id by visiting https://api.telegram.org/bot<BOT_TOKEN>/getUpdates in the browser and hitting enter.
- Let the bot send a test message via visiting https://api.telegram.org/bot<BOT_TOKEN>/sendMessage?chat_id=<GROUP_CHAT_ID>&text=Test in the browser. The message should appear in the group chat.
✅ You're done setting up the Telegram infrastructure.
Setup Arduino Code
![passwords_h.png](/proxy/?url=https://content.instructables.com/FHE/BDI2/LGRZQAS6/FHEBDI2LGRZQAS6.png&filename=passwords_h.png)
- Download and install the latest release of Arduino IDE.
- Download the latest release of knock-knock-arduino-doorbell-telegram-notifier.
- Open Arduino/knock_knock/knock_knock.ino.
- Rename the file Arduino/knock_knock/passwords_template.h to passwords.h or copy its content to a new file named passwords.h in the same folder.
- Enter your WiFi and Telegram credentials (from step 2) in password.h.
✅ The code should now be able to connect to your WiFi and access your Telegram bot.
Flashing the Code
![flashing.png](/proxy/?url=https://content.instructables.com/FCU/KCOG/LGRZQAQV/FCUKCOGLGRZQAQV.png&filename=flashing.png)
- Open Arduino/knock_knock/knock_knock.ino.
- In the Tools menu select the board LOLIN(WEMOS) D1 R2 & mini for flashing. There is a tutorial on how to install ESP8266 boards in Arduino IDE.
- Set Upload Speed: 921600 and CPU Frequency: 80 MHz.
- Connect to board via USB (not to the battery shield USB that is routed to the outside of the enclosure!).
- Choose the correct USB Port for uploading.
- Hit Upload in the Arduino IDE and wait for the process to successfully finish.
- Unplug the USB cable and close the box making sure that all cables are spaced correctly.
✅ If all went well your microcontroller is now running the software. As it's powered via the USB cable it will already start running and may produce actual Telegram messages.
Running Knock Knock for the First Time
![attach_knock_knock.gif](/proxy/?url=https://content.instructables.com/F9C/4E93/LGRZQAM8/F9C4E93LGRZQAM8.gif&filename=attach_knock_knock.gif)
![turn_knock_knock_on.gif](/proxy/?url=https://content.instructables.com/FUK/2XO0/LGRZQATG/FUK2XO0LGRZQATG.gif&filename=turn_knock_knock_on.gif)
![wake_up_knock_knock.gif](/proxy/?url=https://content.instructables.com/FN3/YJNQ/LGRZQAUN/FN3YJNQLGRZQAUN.gif&filename=wake_up_knock_knock.gif)
![charge_knock_knock.gif](/proxy/?url=https://content.instructables.com/FN1/ZJ6W/LGRZQANE/FN1ZJ6WLGRZQANE.gif&filename=charge_knock_knock.gif)
If everything works correctly the device should now be able to detect your doorbell. Place the device near your doorbell and position the sound hole in the back so that it's closest to the doorbell emitting the sound. Activate the rocker switch and it will send a Telegram message once the software is booted as well as once the doorbell rings.
The algorithm for detecting the sound is super simple. For me it works like a charm.
And this is how the program should flow:
- Activate rocker switch.
- System boots and broadcasts readiness via Telegram.
- Code runs.
- It reports a ringing doorbell via Telegram.
- It reports the upcoming shutdown after RUNTIME_BEFORE_UPCOMING_DEEP_SLEEP_NOTIFICATION_IN_MILLISECONDS of runtime via Telegram.
- It reports going to deep sleep after RUNTIME_BEFORE_DEEP_SLEEP_IN_MILLISECONDS of runtime via Telegram.
- It goes into deep sleep after RUNTIME_BEFORE_DEEP_SLEEP_IN_MILLISECONDS of runtime.
- It can be woken up from deep sleep via the push button (code starts again at #2).
- The power is cut via deactivation of the rocker switch.
The device can be charged via the USB port on the outside of the case. Unfortunately, as the D1 mini nodeMCU has only one analoge input, the battery status cannot be surveilled.
Fine Tune the Arduino Code
![settings_h.png](/proxy/?url=https://content.instructables.com/FI3/QT67/LGRZQATD/FI3QT67LGRZQATD.png&filename=settings_h.png)
The system can be fine tuned according to your needs by adjusting the properties in Arduino/knock_knock/settings.h.
You can find a description of the properties in the README.md.
Fine Tune the Sound Sensor
![adjust_gain.png](/proxy/?url=https://content.instructables.com/FSB/V7OW/LGRZQCLK/FSBV7OWLGRZQCLK.png&filename=adjust_gain.png)
The GY-MAX4466 sound sensor has an on board trimmer potentiometer that can be adjusted. From what I understand it's used to adjust the gain. All you need is a small phillips screwdriver (even a flat screwdriver would work) to turn the trimmer. For now I left it as is (all the way to the left). This could be handy for future algorithm improvements – anyone who wants to implement Fast Fourier Transform in this project?
Read More in the Github Project
![more_on_github.png](/proxy/?url=https://content.instructables.com/FV1/O3SV/LGRZQCLO/FV1O3SVLGRZQCLO.png&filename=more_on_github.png)
There's even more infos, links in the code and e.g. an explanation about anonymization in the README.md. Have a look at the code, play with it, extend it. You can add different sensors to it. Exchange the sound sensor for a PIR sensor to detect movement, or an air quality sensor to measure and notify for bad home office air quality … have fun!
Share Your Results
![favor_share_imadeit.jpg](/proxy/?url=https://content.instructables.com/F9E/WEZ0/LGRZQCLL/F9EWEZ0LGRZQCLL.jpg&filename=favor_share_imadeit.jpg)
I'd be happy to see your creations!
Comment in this tutorial or on Github.
Consider hitting the "I Made It!" button.