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

Hardware

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

Skills

  • Patience :)
  • Endurance for at least 2-3 hours
  • Dexterity

Hardware Setup

wiring_diagram.jpg
knock_knock_1.jpg
knock_knock_2.jpg
knock_knock_3.jpg
knock_knock_4.jpg
knock_knock_5.jpg
  1. 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.
  2. 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.
  3. Strategically mount the battery in the junction box (VHB tape works well).
  4. 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!
  5. 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).
  6. Wire the push button in between RST and GND of the microcontroller (ensure enough wire for routing).
  7. Strategically wire the sound sensor to A0, 3V3 and GND of the microcontroller (ensure enough wire for routing).
  8. 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.
  9. Mount the battery shield on the D1 mini NodeMcu.
  10. Connect the USB panel mount cable to the battery shield.
  11. Connect the battery to the female JST connector.
  12. Tidy up all cables and ensure correct spacing when closing the box.

✅ You're done setting up the hardware.

Telegram Setup

botfather.png

The setup follows these instructions. For simplicity I tried to compress it even more in the following step by step list:

  1. Create a Telegram bot using @botfather (FAQ).
  2. Username: @<NAME>Bot
  3. Disable Allow Groups?
  4. Turn on Group Privacy
  5. The bot Token will be available once the bot is created. Write it down, you'll need it in a later step.
  6. Create a private group.
  7. Group name: MyPrivateGroup
  8. Group Type: private
  9. Warning: Do not edit special permissions for users as this will convert the group into a supergroup which does not work with this code.
  10. Temporarily enable Allow Groups? on the bot.
  11. Add the bot to the group.
  12. Immediately deactivate Allow Groups? on the bot after adding it to the group.
  13. 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).
  14. Retrieve group chat_id by visiting https://api.telegram.org/bot<BOT_TOKEN>/getUpdates in the browser and hitting enter.
  15. 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
  1. Download and install the latest release of Arduino IDE.
  2. Download the latest release of knock-knock-arduino-doorbell-telegram-notifier.
  3. Open Arduino/knock_knock/knock_knock.ino.
  4. 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.
  5. 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
  1. Open Arduino/knock_knock/knock_knock.ino.
  2. 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.
  3. Set Upload Speed: 921600 and CPU Frequency: 80 MHz.
  4. Connect to board via USB (not to the battery shield USB that is routed to the outside of the enclosure!).
  5. Choose the correct USB Port for uploading.
  6. Hit Upload in the Arduino IDE and wait for the process to successfully finish.
  7. 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
turn_knock_knock_on.gif
wake_up_knock_knock.gif
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:

  1. Activate rocker switch.
  2. System boots and broadcasts readiness via Telegram.
  3. Code runs.
  4. It reports a ringing doorbell via Telegram.
  5. It reports the upcoming shutdown after RUNTIME_BEFORE_UPCOMING_DEEP_SLEEP_NOTIFICATION_IN_MILLISECONDS of runtime via Telegram.
  6. It reports going to deep sleep after RUNTIME_BEFORE_DEEP_SLEEP_IN_MILLISECONDS of runtime via Telegram.
  7. It goes into deep sleep after RUNTIME_BEFORE_DEEP_SLEEP_IN_MILLISECONDS of runtime.
  8. It can be woken up from deep sleep via the push button (code starts again at #2).
  9. 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

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

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

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

I'd be happy to see your creations!

Comment in this tutorial or on Github.

Consider hitting the "I Made It!" button.

Happy building✌️