Sitemap / Advertise

Introduction

Startle your guests who do not have an entrance permit (RFID tag) and get notified w/ WhatsApp messages without checking the door :)


Tags

Share

WhatsApp Halloween-Themed RFID Talking Doorbell w/ RGB Eyes

Advertisement:


read_later

Read Later



read_later

Read Later

Introduction

Startle your guests who do not have an entrance permit (RFID tag) and get notified w/ WhatsApp messages without checking the door :)

Tags

Share





Advertisement

Advertisement




    Components :
  • [1]PCBWay Custom PCB
  • [1]Arduino Nano 33 IoT
  • [1]Raspberry Pi 3B or 4
  • [1]DFPlayer Mini MP3 Player
  • [1]Micro SD Card
  • [1]Speaker
  • [1]MFRC522 RFID Reader
  • [2]RGB Common Cathode LED
  • [1]DC184 Yellow Pushbutton
  • [1]1K Resistor
  • [1]10K Resistor
  • [1]MB102 Power Supply Module
  • [1]External Battery

Description

Despite the fact that making a hilarious yet not deceitful joke with a jack-o'-lantern on Halloween night is not unobtrusive, I decided to create an exceptional event for my guests on Halloween when they ring the doorbell by designing a jack-o'-lantern doorbell with intriguing features. And, not surprisingly, I only let some of my closest friends know about my new doorbell features by giving them registered RFID tags (entrance permits) to make my other guests frightened even a little bit :) In detail, this doorbell talks to the guests and informs the user via WhatsApp when the guests ring the doorbell or show RFID tags or cards.

First of all, to make the doorbell talking with the guests after an interaction, I generated voices from texts for each occasion I wanted the doorbell to talk. You can get more information about how to create voice files over text files in the following sections.

To be able to get notified via WhatsApp after an interaction, I created an application on the Raspberry Pi, including Twilio's API for WhatsApp. And, I utilized an Arduino Nano 33 IoT to communicate with the application on the Raspberry Pi.

Then, to play the voices I generated with the Arduino Nano 33 IoT, I used a DFPlayer Mini MP3 Player with a speaker. And, to read and register UIDs from RFID tags or cards, I used an MFRC522 RFID Reader.

Finally, I included a DC184 Yellow Pushbutton as the doorbell button and RGB common cathode LEDs as the eyes of the jack-o'-lantern.

After completing my design on a breadboard and testing the code, I designed a PCB (WhatsApp RFID Talking Doorbell) with a unique jack-o'-lantern shape with an angry facial expression to create a suitable and wicked doorbell for Halloween :)

Huge thanks to PCBWay for sponsoring this project.

project-image
Figure - 53.1


project-image
Figure - 53.2

Step 1: Designing and Soldering the WhatsApp RFID Talking Doorbell PCB

I tested all connections and modules with the Arduino Nano 33 IoT on the breadboard.

project-image
Figure - 53.3

Then, I designed the WhatsApp RFID Talking Doorbell PCB by using KiCad. I attached the Gerber file of the PCB below, so if you want, you can order this PCB from PCBWay to create a stylish jack-o'-lantern to frighten your guests who were not informed about its cursed features :)

Click here to inspect and order this PCB directly on PCBWay.

project-image
Figure - 53.4

First of all, by using a soldering iron, I attached headers (male and female), 5mm RGB common cathode LEDs, 1K resistor, 10K resistor, and DC184 yellow pushbutton.

Component list on the PCB:

A1 (Headers for Arduino Nano 33 IoT)

D1, D2 (5mm RGB Common Cathode LED)

J1 (Headers for MFRC522 RFID Reader)

J2, J3 (Headers for DFPlayer Mini)

J4 (Headers for Speaker)

P1 (Headers for Power Supply)

R1 (1K Resistor)

R2 (10K Resistor)

SW1 (DC184 Yellow Pushbutton)

project-image
Figure - 53.5


project-image
Figure - 53.6


project-image
Figure - 53.7

Step 2: Setting up a LAMP web server on Raspberry Pi

If you are a novice in programming with Raspberry Pi, you can inspect well-explained instructions and tutorials on the official Raspberry Pi website.

To go to the official Raspberry Pi setting up tutorial, click here.

project-image
Figure - 53.8

- Open a terminal window by selecting Accessories > Terminal from the menu.

- Install the apache2 package by typing the following command into the terminal and pressing Enter:

sudo apt-get install apache2 -y

project-image
Figure - 53.9

- To test the server, open Chromium by selecting Internet > Chromium Web Browser from the menu and enter http://localhost.

- If you want, you can use the IP address of your Raspberry Pi as well.

hostname -I

project-image
Figure - 53.10


project-image
Figure - 53.11

- Install the PHP package with the following command:

- Do not forget to update the Pi.

sudo apt-get update

sudo apt-get install php -y

project-image
Figure - 53.12

- To be able to utilize Twilio's API for WhatsApp in PHP, install the php-curl package:

sudo apt-get install php-curl

project-image
Figure - 53.13

- Then, restart the apache server to be able to use the installed packages on the localhost:

sudo service apache2 restart

Step 3: Creating a Twilio application

To send WhatsApp messages through Twilio's API, the only thing you need to do is to sign up for a Twilio Trial Account.

After signing up, with your SID and Auth Token, you can use Twilio's API for WhatsApp without any charge. As explained on Twilio, you need to join a shared phone number with your phone in order to verify your phone number and initiate the Twilio's API for WhatsApp.

For more information and learn how to create a new account, click the link below.

Go to Twilio.

You can sign up for Twilio with my referral code here :)

1) Create a new application - WhatsApp Talking Doorbell.

project-image
Figure - 53.14

2) Open the Dashboard of the application.

project-image
Figure - 53.15

3) Go to the Twilio Sandbox for WhatsApp to get the verification code.

project-image
Figure - 53.16

4) Connect your phone to your application with the verification code.

project-image
Figure - 53.17

Step 4: Developing the WhatsApp Talking Doorbell application (webhook) running on Raspberry Pi in PHP

I developed the WhatsApp Talking Doorbell in PHP and explained the source code of the application in the Code Explanation section below for those who are interested.

However, if you are not fond of web development with PHP, you can download the application in Downloads - named WhatsApp_Talking_Doorbell.zip - and upload it to your Raspberry Pi without diving into PHP coding.

The Twilio PHP Helper Library is necessary to use this application. And, I have already included the mentioned API in the application folder (WhatsApp_Talking_Doorbell), so you do not need to download it particularly.

You can get more information about the API here.

Upload:

By the following steps, install the WhatsApp Talking Doorbell on the localhost:

- Download the application - WhatsApp_Talking_Doorbell.zip - including index.php and WhatsAppAPI (Twilio's API for WhatsApp).

project-image
Figure - 53.18

- Extract the WhatsApp_Talking_Doorbell.zip.

project-image
Figure - 53.19


project-image
Figure - 53.20

- Move the application folder (WhatsApp_Talking_Doorbell) from Downloads to the server (/var/www/html) by using the terminal since the apache server is a protected location.

sudo mv /home/pi/Downloads/WhatsApp_Talking_Doorbell /var/www/html/

project-image
Figure - 53.21

- Go to the WhatsApp Talking Doorbell:

http://localhost/WhatsApp_Talking_Doorbell/

Features:

1) If there is no request for the webhook, the application prints: There is no request yet!

project-image
Figure - 53.22

2) Otherwise, if all required parameters are accurate, the application prints: Message Send...

sid: Twilio Application SID

a_token: Twilio Application Auth Token

body: WhatsApp Message Body

from: Shared Phone Number

to: Verified Phone Number

project-image
Figure - 53.23

3) Subsequently, the application sends the message body to the user via WhatsApp.

project-image
Figure - 53.24

Code Explanation:

1) index.php

- Include the required library - Twilio Helper Library for PHP.

- If all the required variables are detected - sid, a_token, body, from, and to - create a new Client.

- Then, send a WhatsApp message from the server as the shared phone number to the verified phone number via Twilio's API for WhatsApp.

Syntax:

http://localhost/WhatsApp_Talking_Doorbell/?sid="[Application_SID]"&a_token="[AUTH_TOKEN]"&body="[Message_Body]"&from="[Shared_Phone_Number]"&to="[Verified_Phone_Number]"

project-image
Figure - 53.25

Step 5: Generating voices from texts

After completing the steps above, to give the ability to speak to the device, I generated different voice files from text files for each occasion, which I wanted the device to interact with the guests by talking. In this way, I could play them with the DFPlayer Mini MP3 Player when triggered for each selected event.

I wrote four different speeches for occasions and converted them to voice files via the web application below:

Of course, they are tricky and apt for Halloween :)

https://ttsmp3.com/

You can download the voice files I generated below - voices.zip.

1) First attempt to ring the doorbell:

"Hello, I am the talking jack o lantern and obligated to protect this house in this wicked night. Please show your entry pass tag or card handed to you before entering the house. Then, I will notify the owner via WhatsApp, depending on whether you have the keycard or not."

project-image
Figure - 53.26

2) Second attempt to ring the doorbell:

"I suppose you neither know the requirement of a keycard nor familiar with the owner of the house. Hence, I will alert the owner of the house due to trespassing. Please leave the house immediately."

project-image
Figure - 53.27

3) Wrong RFID UID:

"Oddly enough, you showed me a wrong and yet deceitful entry tag or card in order to enter this house. Therefore, not surprisingly, I will send a breaking and entering alert message to the owner of the house. Please leave the house immediately."

project-image
Figure - 53.28

4) Correct RFID UID:

"Greetings, and thanks for visiting this haunted house on Halloween night by showing a registered entry card or tag relinquished to you by the owner of the house. I just notified the owner of the house about your arrival via WhatsApp. Please wait until your amiable welcome."

project-image
Figure - 53.29

Step 6: Setting up Arduino Nano 33 IoT

If you are a novice in programming with Arduino Nano 33 IoT: do not worry, it is simple to use with Arduino IDE. Just download the required drivers - Arduino SAMD Core - as well-explained here.

project-image
Figure - 53.30

To be able to connect to the WiFi via Arduino Nano 33 IoT, download the WiFiNINA library from here.

project-image
Figure - 53.31

I used the second serial port (Serial1) on the Arduino Nano 33 IoT to communicate with the DFPlayer Mini MP3 Player.

Serial Ports on the Arduino Nano 33 IoT:

"The USB connector of the board is directly connected to the USB host pins of the SAMD21. This routing enables you to use the Arduino NANO 33 IoT as a client USB peripheral (acting as a mouse or a keyboard connected to the computer) or as a USB host device so that devices like a mouse, keyboard, or an Android phone can be connected to the Arduino NANO 33 IoT. This port can also be used as a virtual serial port using the Serial object in the Arduino programming language. The RX0 and TX1 pins are a second serial port available as Serial1."

Then, Arduino Nano 33 IoT is ready to execute the project code :)

Step 7: Sending commands to the DFPlayer Mini MP3 Player

It is effortless to use a DFPlayer Mini MP3 Player with Arduino since it has a library, including all available UART commands and features. In that regard, you do not need to send UART commands manually to the DFPlayer Mini to play MP3 files.

As explained in its product wiki, "The DFPlayer Mini MP3 Player For Arduino is a small and low price MP3 module with a simplified output directly to the speaker. The module can be used as a stand-alone module with an attached battery, speaker, and push buttons or used in combination with Arduino".

project-image
Figure - 53.32


project-image
Figure - 53.33

To be able to use it with Arduino, the only thing you need to do is to download its library provided by DFRobot from here.

For Arduino Nano 33 IoT, you have to use the second serial port on RX0 and TX1 pins - Serial1 - instead of the SoftwareSerial library like in the sample code.


  // Initiate DFPlayer Mini on the second serial port on RX0 and TX1 pins.
  Serial1.begin(9600);
  while(!myDFPlayer.begin(Serial1)){ Serial.println("Not Connected!"); }
  Serial.println("DFPlayer Connected!!!");
  myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
  //----Set volume----
  myDFPlayer.volume(30);  //Set volume value (0~30).
  //myDFPlayer.volumeUp(); //Volume Up
  //myDFPlayer.volumeDown(); //Volume Down
  // Set EQ
  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
  // Set the SD Card as default source.
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);

And, to be able to execute commands accurately, save your songs by adding consecutive numbers to song names as did I:

001bell_voice.mp3

002second_bell_voice.mp3

003wrong_rfid.mp3

004correct_rfid.mp3

Step 8: Programming Arduino Nano 33 IoT

Download the required libraries to be able to control the modules:

DFPlayer Mini MP3 Player | Library

MFRC522 RFID Reader | Library

- Include the required libraries.

- Define your WiFi network settings - SSID and PASSWORD.

- Enter the IPAddress of your Raspberry Pi.

- Define the pathway of the application in the Raspberry Pi.

- Initialize the Ethernet client library.

- Create the DFPlayer Mini object.

- Create the MFRC522 instance.

- Define the MFRC522 module key input.

- After executing the register_new_UIDs() function, paste the registered UID list to the invited_guests string array and define the total guest number.

- Define RGB LED pins.

- Define the doorbell pin - DC184 Yellow Pushbutton.

- Initiate DFPlayer Mini on the second serial port - Serial1 - on RX0 and TX1 pins.

- Initialize MFRC522 hardware.

- Check for the WiFi module and settings.

- Startle and inform guests when they press the button (doorbell) by playing voice files - myDFPlayer.play(1).

- In the WhatsApp_Message() function:

- Define the required settings by Twilio - Account SID, Auth Token, FROM phone number (incoming), and TO phone number (outgoing).

- Connect to the web application named WhatsApp Talking Doorbell on the Raspberry Pi.

- In the register_new_UIDs() function (uncomment to execute), detect the new card or tag UID and print the UID list.

- To save the new UIDs to the invited_guests string array, copy the UID list after executing this function.

- In the read_UID() function:

- Get the recently read UID.

- Detect whether the recently read UID (lastRead) is in the registered UIDs in the invited_guests string array to activate the DFPlayer with the related voice file.

project-image
Figure - 53.34


project-image
Figure - 53.35


project-image
Figure - 53.36


project-image
Figure - 53.37


project-image
Figure - 53.38

Connections and Adjustments


// Connections
// Arduino Nano 33 IoT:           
//                            MFRC522
// D9  ----------------------- RST
// D10 ----------------------- SDA
// D11 ----------------------- MOSI
// D12 ----------------------- MISO
// D13 ----------------------- SCK
//                            DFPlayer Mini
//     ----------------------- VCC (5V External)
// TX  ----------------------- RX
// RX  ----------------------- TX
// GND ----------------------- GND
//                            RGB_Eye_1
// D3  ----------------------- R
// D5  ----------------------- G
// D6  ----------------------- B
//                            RGB_Eye_2
// A2  ----------------------- R
// A3  ----------------------- G
// A5  ----------------------- B
//                            Doorbell (Button)
// D2  ----------------------- S

After finishing and uploading the code to the Arduino Nano 33 IoT, I attached all required components to the board via headers - MFRC522 RFID Reader, DFPlayer Mini MP3 Player, Speaker, and 5V External Battery.

project-image
Figure - 53.39

DFPlayer Mini MP3 Player needs a sustainable 5V power supply to execute commands properly. Since the Arduino Nano 33 IoT is a 3.3V based development board, I added an external battery socket to the PCB to supply the DFPlayer Mini and the Nano 33 IoT both. I used an MB102 Breadboard Power Supply Module to generate sustainable 5V and connected it to the PCB via headers.

project-image
Figure - 53.40

Modes and Features

1) When the register_new_UIDs() function is executed, the device creates a list of UIDs to be registered for further comparison and displays the list via the serial port. In that regard, the user can register all RFID tags or cards to be utilized to distinguish invited and uninvited guests :)

project-image
Figure - 53.41


project-image
Figure - 53.42

2) The device prints the status of the WiFi connection, the state of the server connection, the state of the DFPlayer Mini, and the recently read UID if connected via the serial port.

project-image
Figure - 53.43

3) In the default mode, when the device starts working, it turns the RGB eyes to purple after executing the code precisely.

project-image
Figure - 53.44

4) After the first attempt to ring the doorbell, the device plays the 001bell_voice.mp3 file, turns the RGB eyes to yellow, and sends a notification message to the user via WhatsApp:

"There is someone at the door! Waiting for action... Status => New Guest"

project-image
Figure - 53.45


project-image
Figure - 53.46

5) After the second attempt to ring the doorbell, the device plays the 002second_bell_voice.mp3 file, turns the RGB eyes to red - angrier :) - and sends a notification message to the user via WhatsApp:

"The guest has not been apprised of the Halloween-themed RFID entrance system :) Status => Second Attempt"

project-image
Figure - 53.47


project-image
Figure - 53.48

6) If the guest shows an unregistered and wrong RFID tag or card, the device plays the 003wrong_rfid.mp3 file, turns the RGB eyes to cyan, and sends an alert message to the user via WhatsApp:

"Some uninvited guest is trying to breach the entrance system! Status => Trespassing"

project-image
Figure - 53.49


project-image
Figure - 53.50

7) If the guest shows a registered and correct RFID tag or card handed to him/her, the device plays the 004correct_rfid.mp3 file, turns the RGB eyes to green, and sends a notification message to the user via WhatsApp:

"One of the guests relinquished an entrance pass - registered UID - has been arrived :) Status => Accurate"

project-image
Figure - 53.51


project-image
Figure - 53.52

Videos and Conclusion




Code

WhatsApp_Halloween_Themed_RFID_Talking_Doorbell.ino

Download



         /////////////////////////////////////////////  
        //    WhatsApp Halloween-Themed RFID       //
       //      Talking Doorbell w/ RGB Eyes       //
      //        -------------------------        //
     //           (Arduino Nano 33 IoT)         //           
    //             by Kutluhan Aktar           // 
   //                                         //
  /////////////////////////////////////////////

// Startle your guests who do not have an entrance permit (RFID tag) and get notified w/ WhatsApp messages without checking the door :)
//
// For more information:
// https://www.theamplituhedron.com/projects/WhatsApp-Halloween-Themed-RFID-Talking-Doorbell-with-RGB-Eyes/
//
// Connections
// Arduino Nano 33 IoT:           
//                            MFRC522
// D9  ----------------------- RST
// D10 ----------------------- SDA
// D11 ----------------------- MOSI
// D12 ----------------------- MISO
// D13 ----------------------- SCK
//                            DFPlayer Mini
//     ----------------------- VCC (5V External)
// TX  ----------------------- RX
// RX  ----------------------- TX
// GND ----------------------- GND
//                            RGB_Eye_1
// D3  ----------------------- R
// D5  ----------------------- G
// D6  ----------------------- B
//                            RGB_Eye_2
// A2  ----------------------- R
// A3  ----------------------- G
// A5  ----------------------- B
//                            Doorbell (Button)
// D2  ----------------------- S

/*

   Typical pin layout used:
   -----------------------------------------------------------------------------------------
               MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
               Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
   Signal      Pin          Pin           Pin       Pin        Pin              Pin
   -----------------------------------------------------------------------------------------
   RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
   SPI SS      SDA(SS)      10            53        D10        10               10
   SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
   SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
   SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15

*/

#include <SPI.h>      // RC522 Module uses SPI protocol
#include <WiFiNINA.h>
#include <MFRC522.h>  // Library for Mifare RC522 Devices
#include "DFRobotDFPlayerMini.h"

char ssid[] = "[_SSID_]";        // your network SSID (name)
char pass[] = "[_PASSWORD_]";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;                // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

// Enter the IPAddress of your Raspberry Pi.
IPAddress server(192, 168, 1, 20);

// Define the pathway of the application in the Raspberry Pi.
String application = "/WhatsApp_Talking_Doorbell/";

// Initialize the Ethernet client library
WiFiClient client;

// Create DFPlayer Mini object.
DFRobotDFPlayerMini myDFPlayer;

// Create the MFRC522 instance.
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);

// Define the MFRC522 module key input.
MFRC522::MIFARE_Key key;

// Define the data holders:
String lastRead; // recently read UID
int red, green, blue;
int bell = 0; // ring

// After executing the register_new_UIDs() function, paste the registered UID list here and define the total guest number:
char *invited_guests[] = {"9B B6 3C 75", "56 1B 0D F8"};
#define guest_number 2

// Define RGB pins.
#define redPin_1 3
#define greenPin_1 5
#define bluePin_1 6
#define redPin_2 A2
#define greenPin_2 A3
#define bluePin_2 A5

// Define the doorbell pin.
#define doorbell 2

void setup() {
  Serial.begin(9600); 
  
  pinMode(redPin_1, OUTPUT);
  pinMode(greenPin_1, OUTPUT);
  pinMode(bluePin_1, OUTPUT);
  pinMode(redPin_2, OUTPUT);
  pinMode(greenPin_2, OUTPUT);
  pinMode(bluePin_2, OUTPUT);
  pinMode(doorbell, INPUT);
  
  // Initiate DFPlayer Mini on the second serial port on RX0 and TX1 pins.
  Serial1.begin(9600);
  while(!myDFPlayer.begin(Serial1)){ Serial.println("Not Connected!"); }
  Serial.println("DFPlayer Connected!!!");
  myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
  //----Set volume----
  myDFPlayer.volume(30);  //Set volume value (0~30).
  //myDFPlayer.volumeUp(); //Volume Up
  //myDFPlayer.volumeDown(); //Volume Down
  // Set EQ
  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
  // Set the SD Card as default source.
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
  
  // Initialize MFRC522 Hardware
  SPI.begin();          
  mfrc522.PCD_Init();
  Serial.println("\n----------------------------------\nApproximate a New Card or Key Tag : \n");

  // Check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) { Serial.println("Communication with WiFi module failed!"); while (true); }
  // Attempt to connect to the WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // Wait 10 seconds for connection:
    delay(10000);
  }

  // Verify connection on the serial monitor.
  Serial.println("Connected to wifi");

  // Adjust the default color of RGB eyes.
  adjustColor('f', 255, 0, 255);
  adjustColor('s', 255, 0, 255);
  
}

void loop(){  
  // Startle and inform guests when they press the button - doorbell.
  if(digitalRead(doorbell) == HIGH){
    bell++;
    if(bell == 1){
      myDFPlayer.play(1);
      adjustColor('f', 255, 255, 0);
      adjustColor('s', 255, 255, 0);
      WhatsApp_Message("There%20is%20someone%20at%20the%20door!%20Waiting%20for%20action...%0a%0aStatus%20=>%20New%20Guest");
    }else if(bell == 2){
      myDFPlayer.play(2);
      adjustColor('f', 255, 0, 0);
      adjustColor('s', 255, 0, 0);
      WhatsApp_Message("The%20guest%20has%20not%20been%20apprised%20of%20the%20Halloween-themed%20RFID%20entrance%20system%20:)%0a%0aStatus%20=>%20Second%20Attempt");
    }else{
      bell = 0;
    }
    delay(2000);
  }

  // Uncomment to get and register new UIDs for comparison.
  //register_new_UIDs();

  read_UID();
}

int read_UID() {
  // Detect the new card or tag UID. 
  if ( ! mfrc522.PICC_IsNewCardPresent()) { 
    return 0;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return 0;
  }

  // Display the new UID.
  Serial.print("\n----------------------------------\nNew Card or Key Tag UID : ");
  for (int i = 0; i < mfrc522.uid.size; i++) {
    lastRead += mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ";
    lastRead += String(mfrc522.uid.uidByte[i], HEX);
  }
  lastRead.trim();
  lastRead.toUpperCase();
  Serial.print(lastRead);
  Serial.print("\n----------------------------------\n");

  // Detect whether the recently read UID (lastRead) is in the registered UIDs in the invited_guests string array to activate the DFPlayer with the related voice file.
  volatile boolean UID_Found = false;
  for(int i=0;i<guest_number;i++){
    if(lastRead == invited_guests[i]){
      UID_Found = true;
    }
  }
  if(UID_Found == true){
    myDFPlayer.play(4);
    adjustColor('f', 0, 255, 0);
    adjustColor('s', 0, 255, 0);
    WhatsApp_Message("One%20of%20the%20guests%20relinquished%20an%20entrance%20pass%20-%20registered%20UID%20-%20has%20been%20arrived%20:)%0a%0aStatus%20=>%20Accurate");   
  }else if(UID_Found == false){
    myDFPlayer.play(3);
    adjustColor('f', 0, 255, 255);
    adjustColor('s', 0, 255, 255);
    WhatsApp_Message("Some%20uninvited%20guest%20is%20trying%20to%20breach%20the%20entrance%20system!%0a%0aStatus%20=>%20Trespassing");    
  }

  // Reset the doorbell:
  bell = 0;

  lastRead = "";
  mfrc522.PICC_HaltA();
  return 1;
}

int register_new_UIDs() {
  // Detect the new card or tag UID. 
  if ( ! mfrc522.PICC_IsNewCardPresent()) { 
    return 0;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return 0;
  }

  // Get the recently read UID.
  for (int i = 0; i < mfrc522.uid.size; i++) {  //
    lastRead += mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ";
    lastRead += String(mfrc522.uid.uidByte[i], HEX);
  }
  lastRead.trim();
  lastRead.toUpperCase();
  // To save the new UIDs to the invited_guests string array, copy the UID list after executing this function.
  Serial.print("\"" + lastRead + "\", ");
  lastRead = "";
  mfrc522.PICC_HaltA();
  return 1;
}

void WhatsApp_Message(String body){
  // Define the required settings by Twilio - Account SID, Auth Token, FROM phone number (incoming), and TO phone number (outgoing).
  String sid = "[_SID_]";
  String a_token = "[_AUTH_TOKEN_]";
  String FROM = "14155238886";
  String TO = "[_REGISTERED_PHONE_NUMBER_]";
  
  // Connect to the web application named WhatsApp Talking Doorbell on the Raspberry Pi.
  if (client.connect(server, 80)) {
    Serial.println("Connected to the server!"); // if you get a connection, report back via serial:
    // Make an HTTP request:
    client.println("GET " + application + "?sid=" + sid + "&a_token=" + a_token + "&body=" + body + "&from=" + FROM + "&to=" + TO + " HTTP/1.1");
    client.println("Host: 192.168.1.20");
    client.println("Connection: close");
    client.println();
  }else{
    Serial.println("Server Connection Failed!");
  }
  delay(2000); // Wait 2 seconds after connection...  
}

void adjustColor(char eye, int r, int g, int b){
  switch (eye){
    case 'f':
      analogWrite(redPin_1, r);
      analogWrite(greenPin_1, g);
      analogWrite(bluePin_1, b);
    break;
    case 's':
      analogWrite(redPin_2, r);
      analogWrite(greenPin_2, g);
      analogWrite(bluePin_2, b);
    break;
  }
}


index_WhatsApp_Talking_Doorbell.php

Download



<?php 

require_once 'WhatsAppAPI/Twilio/autoload.php'; 
 
use Twilio\Rest\Client; 

if(isset($_GET["sid"]) && isset($_GET["a_token"]) && isset($_GET["body"]) && isset($_GET["from"]) && isset($_GET["to"])){
	$sid    = $_GET["sid"]; 
    $token  = $_GET["a_token"];  
    $twilio = new Client($sid, $token);
	
	$to = $_GET['to'];
	$from = $_GET['from'];
	$body = $_GET['body'];
	
	$message = $twilio->messages 
                  ->create("whatsapp:+".$to, 
                           array( 
                               "from" => "whatsapp:+".$from,       
                               "body" => $body
                           ) 
                  );
    echo 'Message Send...';				  
	
}else{
	echo "There is no request yet!";
}

?>


Schematics

project-image
Schematic - 53.1


project-image
Schematic - 53.2


project-image
Schematic - 53.3


project-image
Schematic - 53.4

Downloads

Gerber Files

Download


Fabrication Files

Download


WhatsApp_Talking_Doorbell.zip

Download


voices.zip

Download