Home Security System

* Student: Delicostea Robert-Alexandru


The purpose of this project is to create a home security system, that detects everything that comes within a distance decided beforehand. If someone goes within that distance the buzzer will start ringing for a period of time(chosen long enough for the person how got close to it to introduce the password). The password refers to the number of times the button on the board needs to be pressed in the timeframe that the buzzer is active. This whole system is connected to the home network using Blynk app. This application can a have a good impact for obvious reasons as it prevents intruders from entering the house and it alerts the owner regarding every action.


The picture above shows the flow of the application in the instance when the owner receives on his phone the number of times the button needs to pressed for the buzzer to stop when someone gets to close to the sensor. Another scenrio is when the password is introduced wrongly 3 times(the button is not pressed the correct amount of times before the buzzer stops). In this instance the owner will receive an alert that the password was introduced wrongly 3 times.

Hardware Design


Hardware Schematics

Software Design

The code for the system is written in Android IDE and the Blynk app. Blynk is an IoT platform for iOS or Android smartphones that is used to control Arduino, Raspberry Pi and NodeMCU via the Internet. This application is used to create a graphical interface or human machine interface (HMI) by compiling and providing the appropriate address on the available widgets.

Arduino Code

The following instructions show the libraries for newtwork connection(credentials and the code in the setup function) and for the use of the Blynk features:

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// Wi-Fi credentials
char ssid[] = "P16_network";
char password[] = "manutd4ever";

// Blynk authentication token
char auth[] = "7ep5xyxeAkkYEl3xZxKXSMEWqRGn_4e6";

void setup() {

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  Serial.println("Wi-Fi connected");

  // Initialize Blynk
  Blynk.begin(auth, ssid, password);

  pinMode(buzzerPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);

In the measureDistance function the condition is that if everyone goes closer than 10 cm the buzzer will start ringing with a notification on the Blynk app appearing if the password is introduced wromng 3 times, The distance is also updated on the Blynk widget Gauge.

Blynk.virtualWrite(distancePin, distance);

  Serial.print("Distance: ");
  Serial.println(" cm");

  if (distance < 10) {
      if(attempts == 3){
        Blynk.logEvent("button_pushed", String("Password introduced incorrectly 3 times!"));
        attempts = 0;

In the activateBuzzer function the number of times the button needs to pressed is set and the owner sees it on the Blynk app and in the handleButton the buzzer is stopped if the number is reached

passNumber = random(3, 10);
Blynk.logEvent("button_pushed", String("Buzzer activated, password is press button ") + passNumber + String(" times"));
// Check if the button state has been stable for the debounce delay
  if (millis() - lastDebounceTime >= debounceDelay) {
    // Update the button state only if it has changed
    if (reading != buttonState) {
      buttonState = reading;

      // If the button is pressed (LOW) and the buzzer is active, increase the press count
      if (buttonState == LOW && buzzerActive) {

        // If the button has been pressed passNumber or more times, stop the buzzer
        if (buttonPressCount >= passNumber) {
          digitalWrite(buzzerPin, LOW);
          buzzerActive = false;
          buttonPressCount = 0;
          return true;



iothings/proiecte/2022sric/home_security_system.txt · Last modified: 2023/06/02 00:52 by robert.delicostea
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0