YUVAN SRI S
Published

Smart Doorbell with Mobile Notification Using KiwisIoT

An ESP32-powered smart doorbell that detects visitors and sends instant mobile notifications through the KiwisIoT Dashboard, keeping you con

BeginnerFull instructions provided6
Smart Doorbell with Mobile Notification Using KiwisIoT

Things used in this project

Hardware components

ESP32
×1
Rotary Encoder with Push-Button
Rotary Encoder with Push-Button
×1
Active Buzzer
×1
LED (generic)
LED (generic)
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Pi Adaptor
Breadboard Mates Pi Adaptor
×1
umper Wires
×1
Bench Power Supply, USB Programmable DC
Bench Power Supply, USB Programmable DC
×1
Smartphone
×1

Software apps and online services

Arduino IDE
Arduino IDE
KIWIS

Story

Read more

Schematics

F

Code

Code

C/C++
#include <WiFi.h>
#include <PubSubClient.h>

// Wi-Fi credentials
const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";

// Use the broker settings provided by KiwisIoT
const char* mqtt_server = "YOUR_MQTT_BROKER";
const int mqtt_port = YOUR_MQTT_PORT;

// Use your actual device topic and credentials
const char* mqtt_topic = "YOUR_DEVICE_TOPIC";

#define BUTTON_PIN 18
#define BUZZER_PIN 19
#define LED_PIN 21

WiFiClient espClient;
PubSubClient client(espClient);

bool lastButtonState = HIGH;
unsigned long lastPressTime = 0;

void connectWiFi() {
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
}

void reconnectMQTT() {
  while (!client.connected()) {
    if (client.connect("SmartDoorbellESP32")) {
      break;
    }
    delay(2000);
  }
}

void setup() {
  Serial.begin(115200);

  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);

  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(LED_PIN, LOW);

  connectWiFi();

  client.setServer(mqtt_server, mqtt_port);
}

void loop() {
  if (!client.connected()) {
    reconnectMQTT();
  }

  client.loop();

  bool buttonState = digitalRead(BUTTON_PIN);

  if (lastButtonState == HIGH &&
      buttonState == LOW &&
      millis() - lastPressTime > 1000) {

    lastPressTime = millis();

    digitalWrite(BUZZER_PIN, HIGH);
    digitalWrite(LED_PIN, HIGH);

    // Replace with the payload required by your
    // KiwisIoT device integration.
    client.publish(mqtt_topic, "DOORBELL_PRESSED");

    Serial.println("Doorbell Pressed!");

    delay(500);

    digitalWrite(BUZZER_PIN, LOW);
    digitalWrite(LED_PIN, LOW);
  }

  lastButtonState = buttonState;
}

Credits

YUVAN SRI S
25 projects • 2 followers

Comments