Rohan Barnwal
Published © LGPL

Never Miss the Doorbell Again: Build This Smart Email Bell

A smart doorbell that sends email alerts — never miss a knock again.

BeginnerFull instructions provided143
Never Miss the Doorbell Again: Build This Smart Email Bell

Things used in this project

Hardware components

TTP223 Touch Sensor
×1
ESP32 Dev Board
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Connections

Code

Code

Arduino
#include <WiFi.h>
#include <ESP_Mail_Client.h>

#define TOUCH_PIN 23  // Touch sensor pin

const char* ssid = "Your_SSID";
const char* password = "Your_PASSWORD";

// Gmail SMTP settings
#define SMTP_HOST "smtp.gmail.com"
#define SMTP_PORT 465
#define AUTHOR_EMAIL "your_email@gmail.com"
#define AUTHOR_PASSWORD "your_app_password"
#define RECIPIENT_EMAIL "recipient@example.com"

SMTPSession smtp;
ESP_Mail_Session session;
SMTP_Message message;

bool touchPreviouslyHigh = false;

void setup() {
  pinMode(TOUCH_PIN, INPUT);
  Serial.begin(115200);

  // Fast WiFi connect
  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
    Serial.print(".");
  }
  Serial.println("\nWiFi Connected");

  // SMTP setup
  session.server.host_name = SMTP_HOST;
  session.server.port = SMTP_PORT;
  session.login.email = AUTHOR_EMAIL;
  session.login.password = AUTHOR_PASSWORD;
  session.login.user_domain = "";

  smtp.debug(0);  // Disable logs for speed
}

void loop() {
  bool currentTouchState = digitalRead(TOUCH_PIN);

  if (currentTouchState == HIGH && !touchPreviouslyHigh) {
    touchPreviouslyHigh = true;
    sendFastEmail();
  } else if (currentTouchState == LOW && touchPreviouslyHigh) {
    touchPreviouslyHigh = false;
  }

  delay(50);  // Fast polling
}

void sendFastEmail() {
  message.sender.name = "ESP32 Alert";
  message.sender.email = AUTHOR_EMAIL;
  message.subject = "Someone is outside the door";
  message.addRecipient("User", RECIPIENT_EMAIL);
  message.text.content = "Someone is standing outside the door. Open it fast or otherwise...";
  message.text.charSet = "utf-8";
  message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit;

  if (!smtp.connect(&session)) {
    Serial.println("SMTP connection failed");
    return;
  }

  if (MailClient.sendMail(&smtp, &message)) {
    Serial.println("ALERT EMAIL SENT!");
  } else {
    Serial.print("Email error: ");
    Serial.println(smtp.errorReason());
  }

  smtp.closeSession();  // Optional, or keep alive if frequent
}

Credits

Rohan Barnwal
31 projects • 35 followers
Rohan Barnwal - maker, hacker, tech enthusiast. I explore new tech & find innovative solutions. See my projects on hackster.io!

Comments