Smart DoorBell

by jeremzan in Circuits > Arduino

76 Views, 3 Favorites, 0 Comments

Smart DoorBell

F0M3KKCLTU3M058.jpg

Hi all I'm Jeremy and I did this project with Dor, we hope you're gonna enjoy it !

In this Instructable, we'll show you how to build a Smart Door Notification System that alerts you via Telegram whenever someone is at your door, using ESP32, Blynk, and Make.com. This system is perfect for homeowners looking to add a layer of smart technology to their door without expensive, off-the-shelf solutions.

This is the explanation video before you dive into the project. Enjoy :

https://drive.google.com/file/d/1zKr1tUHYo0eXff9EV8kb30IXCR6gtgf1/view?usp=share_link

Supplies

Screenshot 2024-03-14 at 14.35.09.png
Screenshot 2024-03-14 at 14.37.16.png
Screenshot 2024-03-14 at 14.37.30.png
Screenshot 2024-03-14 at 14.38.02.png
Screenshot 2024-03-14 at 14.36.34.png
  • ESP32 Development Board
  • Microphone
  • Piezo Element
  • Jumper Wires
  • Breadboard
  • Blynk.io Account
  • Make.com Account
  • Google Account
  • Telegram Account

Setting Up the Hardware

WhatsApp Image 2024-03-13 at 20.20.25.jpeg
WhatsApp Image 2024-03-14 at 14.56.08.jpeg
WhatsApp Image 2024-03-14 at 14.56.04.jpeg

1. Connect the microphone to pin 34 of the ESP32.

2. Attach the piezo element to pin 35.

3. Power the ESP32 with a USB cable to upload the required code that will

follows in the next section.


Software Requirements

  1. Create a Blynk account on “blynk.io”
  2. Create a Make account on “Make.com”
  3. Create a Google account to use google sheets
  4. Create a Telegram account
  5. Write the ESP32 code to read sensor data and send notifications.

ESP32 Code

#include <ArduinoJson.h>

#define BLYNK_TEMPLATE_ID “your-blynk-template-id”

#define BLYNK_TEMPLATE_NAME “your-blynk-template-name“

#define BLYNK_AUTH_TOKEN “your-blynk-auth-token“

#define BLYNK_PRINT Serial

#include <WiFi.h>

#include <WiFiClient.h>

#include <BlynkSimpleEsp32.h>

char ssid[] = “your-wifi-name“;

char pass[] = “your-wifi-password“; //Leave as follows if no need for password : “”

const int soundSensorPin = 34; // Sound sensor pin

const int piezoSensorPin = 35; // Piezo sensor pin

// Parameters for running average for the sound sensor

const int numReadingsSound = 50;

int readingsSound[numReadingsSound];

int readIndexSound = 0;

long totalSound = 0;

int averageSound = 0;

unsigned long previousMillis = 0; // Last time sensors were updated

const long interval = 5000; // Interval at which to read sensors (milliseconds)

int threshold = 100; // Threshold for detecting significant sound, adjust based on your needs

void setup() {

 Serial.begin(115200);

 Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

 // Initialize all sound sensor readings to 0

 for (int i = 0; i < numReadingsSound; i++) {

  readingsSound[i] = 0;

 }

}

void loop() {

 Blynk.run();

 unsigned long currentMillis = millis();

 if (currentMillis - previousMillis >= interval) {

  previousMillis = currentMillis;

  // Sound Sensor Processing

  totalSound -= readingsSound[readIndexSound];

  readingsSound[readIndexSound] = analogRead(soundSensorPin);

  totalSound += readingsSound[readIndexSound];

  readIndexSound = (readIndexSound + 1) % numReadingsSound;

  averageSound = totalSound / numReadingsSound;

  int soundVolume = 0;

  int currentReadingSound = analogRead(soundSensorPin);

  if (abs(currentReadingSound - averageSound) > threshold) {

   soundVolume = currentReadingSound - averageSound;

   if (soundVolume <= 0){

    soundVolume = 0;

   }

  }

  // Piezo Sensor Processing

  long startTimePiezo = millis();

  int minPiezoSensor = 4095;

  int maxPiezoSensor = 0;

  while (millis() - startTimePiezo < 5000) {

   int piezoSensor = analogRead(piezoSensorPin);

   minPiezoSensor = min(piezoSensor, minPiezoSensor);

   maxPiezoSensor = max(piezoSensor, maxPiezoSensor);

   delay(1);

  }

  int piezoVolume = maxPiezoSensor - minPiezoSensor;

  // Combine data into a JSON string

  StaticJsonDocument<200> doc;

  doc["soundVolume"] = soundVolume;

  doc["piezoVolume"] = piezoVolume;

  char jsonBuffer[200];

  serializeJson(doc, jsonBuffer);

  // Send JSON data to Blynk using Virtual Pin V1

  Blynk.virtualWrite(V1, jsonBuffer);

 }

}

Blynk Setup

Screenshot 2024-03-17 at 14.10.34.png
Screenshot 2024-03-17 at 14.10.50.png
Screenshot 2024-03-17 at 14.11.01.png
Screenshot 2024-03-17 at 14.11.15.png
Screenshot 2024-03-17 at 14.11.30.png
Screenshot 2024-03-17 at 14.12.03.png
Screenshot 2024-03-17 at 14.11.43.png
Screenshot 2024-03-17 at 14.12.24.png
  1. Open you Blynk account and go to Developer Zone -> My Templates and click on New Template button.
  2. Go to Datastreams in your new template and create a new data stream and select “Virtual Pin” 
  3. Create the virtual pin to receive the sensors data.
  4. Go now to Web Dashboard to display the input that will receive this virtual pin ( it is not required for the good functionality of the project, it’s just for you to see what are you really getting from the sensors if you need to to adjustments for thresholds, etc…). Drag the Label widget to your dashboard and configure it as above.
  5. Save you template now. Go to Devices section and create a new device by clicking on the “+ New Device” button. Then select from template. Choose your template you just created and give it a cool name. You will then get all your tokens and Id’s to replace in the code I gave you.
  6. You now have your device ready to receive the data , you will see it in the widget “Sensors output” that we created before. We just need to create a webhook now so everytime our ESP32 will receive new data in Blynk, will send an HTTP request to our scenario in make.com to pass the data over to make.
  7. Now go to Developer Zone -> Webhooks. Create a new webhook to link it to the virtual pins.You will need to replace the “Final Project Device JSON” by your actual device name. For the webhook URL I will show you in the Make setup where you get it, and you will also understand why the query parameters are as above.

Make.com Configuration

Screenshot 2024-03-17 at 14.21.53.png
Screenshot 2024-03-17 at 14.22.07.png
Screenshot 2024-03-17 at 14.22.22.png
Screenshot 2024-03-17 at 14.22.37.png
Screenshot 2024-03-17 at 14.22.49.png
Screenshot 2024-03-17 at 14.23.05.png
Screenshot 2024-03-17 at 14.23.19.png
Screenshot 2024-03-17 at 14.23.32.png
Screenshot 2024-03-17 at 14.24.02.png
Screenshot 2024-03-17 at 14.24.16.png
Screenshot 2024-03-17 at 14.24.33.png
Screenshot 2024-03-17 at 14.24.46.png
Screenshot 2024-03-17 at 14.25.01.png
Screenshot 2024-03-17 at 14.25.12.png
Screenshot 2024-03-17 at 14.25.27.png
Screenshot 2024-03-17 at 14.25.38.png
Screenshot 2024-03-17 at 14.25.48.png
Screenshot 2024-03-17 at 14.26.00.png
Screenshot 2024-03-17 at 14.26.09.png
Screenshot 2024-03-17 at 14.26.20.png
  1. In your Make account go to the Scenarios section and Create a new scenario from scratch. We will create it together but it will look like the first pic above after the configuration.
  2. Search for a Webhook module and configure the Webhook module to receive data from Blynk. You will create a “Custom webhook” and choose a name for the webhook.
  3. You will then receive an URL. This is the URL that you will use in your Blynk webhook that you created. So go back to your webhook in Blynk , click on “Edit” and change the url to this one. You see the red “stop” button ? So you need to copy this URL paste it on your browser and add, the part highlighted in the third pic, at the end of the URL. You will then get a page with just the text "Accepted" written (4th pic). Also in your scenario, the module has changed like the 5th pic. Okay so what we did here is we told the make webhook module “Hey I will send you data, in the next format “json=outputPinValue”. Now the module expect this kind of data and every time it will receive new data it will just pass it along to the next module in your scenario.
  4. The data you will get is in JSON format, not something critical for you to know if you don’t have experience coding, but it is the format we get. We need to parse it to extract the relevant data we need (the sound value, the piezo value). Create a JSON module and choose Parse JSON and then drag the red json widget (that is what the webhook got). After setting this module or only the previous one you should run the scenario with your esp32 switched on, so the modules can have a sampling of the data ( the type of data and the names of the attributes of the json object ).
  5. The next module we need is a router. We’ll need it to send our data to several module, to the Telegram bot module so we’ll receive the notification on our phone, and to the the google sheets module so we can log all the visits. Create a router module by clicking on Tools, selecting Router.
  6. Set up a filter for our logic. We want to put some threshold so we won’t receive messages every time someone just talks in front of our door or if our ring bell is not loud enough. So click on the little wrench between the JSON module and the router and set up a filter , do as the 8th pic. Keep in mind that you need to do the "Run once" I told you earlier to get the data sampling for make to be aware of the attribute names of our JSON object. In this example after I ran the scenario I could drag the purple widgets “soundVolume” and “piezoVolume”, otherwise the filter wouldn’t have recognized these elements and I could have the option to drag them.
  7. Now create a Telegram module and Select “Send a text message or reply”. Before setting this module make sure to create a telegram account and install Telegram Desktop. Create a bot using the Botfather bot in telegram, this is pretty straightforward. Give it the name of your choice, that will be this bot that will notify you. Once your bot is setup you will receive a Token for this bot and you will be able to create a connection to your telegram module. You will also need your personal chat id. We used the bot “userinfobot” on telegram. *Disclaimer : It is not an official bot or trusted company that created it, so we don’t have any responsibility over it and it’s just the way we did it, if you find a better (maybe safer) way to get your personal id, you can always do it this other way.*
  8. Now we need two tools modules. Go to Tools and select “Set variable” for the 2 modules and do the same as pics 11 an 12.
  9. Now we need to store the the last time we logged a visit in our Google Sheets, so we can set up a limit, for example in our case we didn’t want to have more than one log per minute, you can change this as you wish of course. So first we need to create a new data structure to store our last log. Go to the section Data Structures and create a new one, then go to the section Data Stores and create a new data store, then go to your new data store and add a key and call it “lastLoggedTime”. After all these settings we can finally create our “Data store” module and select “Get a record” and do the same as the 16th pic.
  10. Now create a third “Tool” module and select “Set variable” and do the same as the 17th pic. You can see that we have access to our previous variables and also the Time variable stored in our data store in our key lastLoggedTime that we got previously.
  11. Now create a new Google Sheets, we called it “VisitDates”. Make a new column, we called it “VisitDate”. Now create a “Google Sheets” module and select “Add a row”. You will need to connect to your Google account. Once you did that do the same as pic 18.
  12. If you paid attention in the last pic, we set up a filter ! This is the filter that will check that 1 minute passed since the last time we logged a date in the google sheets. As we told you before you can change the time between logs as you wish. Look at pic 19 and remark that the time difference is calculated in seconds so be aware if you want to make changes.
  13. Finally, we add our last module to store the new timestamp our last log was made. So create a “Data Store” module and select "Update a record" and do the same settings as pic 20.


Conclusion

Congratulations on building your Smart Door Notification System! Feel free to share your modifications, how you use it in your daily life, or any tweaks you've made for your personal setup.