Welcome to Hong Kong Bitfoic Electronics Co., Ltd
[email protected] Request a Quote Contact Us My order
en ru en ru en
Home > Components >How to create a smart Wi-Fi doorbell with an ESP32 and camera?

How to create a smart Wi-Fi doorbell with an ESP32 and camera?

3/5/2024

 

Project Introduction

 

Nowadays, security systems are one of the most researched fields. With the increase in security threats, companies are introducing new intelligent security products to counter these threats. The Internet of Things (IoT) is an additional advantage in this field; it can automatically trigger events in any emergency, such as alarms, fire brigades, or your neighbors. Today, we'll construct a smart Wi-Fi doorbell using an ESP32 and a camera.

 

Table of content

 

Components needed

 

ESP32-CAM

FTDI programming board

220V AC to 5V DC converter

buzzer

button

Light emitting diode (2)

 

 

Circuit schematic

 

The circuit diagram of this smart Wi-Fi doorbell is as simple as connecting two LEDs, a button, and a buzzer to the ESP32 GPIO pins. The buzzer will sound whenever the button is pressed. One LED indicates power status and the other LED indicates network status. If the ESP is connected to the network, the network LED will be high, otherwise, it will flash.

 

Circuit schematic

 

 

This is what the Wi-Fi video doorbell setup looks like in a 3D-printed case:

 

IFTTT setup for Wi-Fi doorbell

 

IFTTT is a free web-based service that allows users to create chains of simple conditional statements called "recipes" triggered based on changes to other web services such as Gmail, Facebook, Instagram, and Pinterest. IFTTT stands for “If This Then That.”

In this project, IFTTT is used to send an email when the temperature or humidity exceeds predefined limits. We have previously used IFTTT in many IoT-based projects to send emails or SMS for specific events like excessive power usage, high pulse rate, intruder entry, etc.

First, log into IFTTT using your credentials or sign up if you don't have an account.

Now search for “Webhooks” and click on “Webhooks” in the Services section.

Webhooks

 

Now, click on Documents in the upper right corner of the Webhooks window to get the private key.

Copy this key. It is a part of the curriculum.

 

key

After obtaining the private key, we will create a small program using webhooks and email services. Click on your profile and then select Create to create an applet.

 

small program

 

Now in the next window, click on the "This" icon.

This

 

 

Proceed to the search section, type in "Webhooks," and choose it.

Receive Web Request

 

Now select the "Receive Web Request" trigger and in the next window, enter the event name as button_pressed and click on Create Trigger.

Now to complete the applet, click "that" to create a reaction for the button_pressed event.

 

that

 

Here, the phone will play a pre-designated song when the IoT doorbell button is pressed. Search for "Android devices" in the search section.

 

Android devices

 

Now on your Android device, select the "Play specific song" trigger.

creative action

Now enter the name of the song that you want to play when the doorbell button is pressed. In my case, I was playing a song called "123" from my Google Play Music. You can also use Spotify or other music apps.

After that, click on Create Action and then click on Finish to complete the process.

Now create another applet that sends a message with a web link to your phone when the doorbell button is pressed.

So, to create this applet, select "Webhooks" in the "this" section and "Android SMS" in the "that" section.

Now it will ask for the phone number and message body. For this Wi-Fi doorbell project, we are sending a message with a link to the web server so that you can see the live video stream directly.

 

 

Code Explanation

 

Some of the code's most significant components are explained below.

 

First, include all the required library files for this code.

 

#include "esp_camera.h"

#include <WiFi.h>

 

Then enter the Wi-Fi credentials.

 

const char* ssid = "Wi-Fi Name";

const char* password = "Wi-Fi Password";

 

After that, enter the IFTTT hostname and private key that you copied from the IFTTT website.

 

const char *host = "maker.ifttt.com";

const char *privateKey = "Your Private Key";

 

Define all the pins that you are using in this project. I'm connecting the push button, LED, and buzzer using the GPIO 2, 14, and 15 pins.

 

const int buttonPin = 2;

const int led1 = 14;

const int buzzer = 15;

 

Inside the void setup loop, define the button pin as input and the LED and buzzer pins as output.

 

void setup() {

  pinMode(buttonPin, INPUT);

  pinMode(led1, OUTPUT);

  pinMode(buzzer, OUTPUT);

 

It will attempt to establish a Wi-Fi connection with the provided credentials, and upon successful connection, the LED status will transition from low to high.

 

WiFi.begin(ssid, password);

  int led = LOW;

  while (WiFi.status() != WL_CONNECTED) {

    delay(500);

    Serial.print(".");

    digitalWrite(led1, led);

    led = !led;

  }

  Serial.println("");

  Serial.println("WiFi connected");

  digitalWrite(led1, HIGH);

 

The ESP32 will restart when it is not connected to a network until it does so.

 

while (WiFi.status() == WL_DISCONNECTED) {

    ESP.restart();

    digitalWrite(led1, LOW);

    Serial.print("Connection Lost");

 

When the ESP32 detects that a button has been pressed and is in the LOW state (pulled high), it transmits an event and activates the buzzer for three seconds.

 

int reading = digitalRead(buttonPin);

if (buttonState == LOW) {

        send_event("button_pressed");

        Serial.print("button pressed");

        digitalWrite(buzzer, HIGH);

        delay(3000);

          digitalWrite(buzzer, LOW);

 

Related Articles
Popular parts number