Smart Password-Protected Alarm System Using ESP32 (Wokwi)

by tushar _electronics in Circuits > Microcontrollers

42 Views, 1 Favorites, 0 Comments

Smart Password-Protected Alarm System Using ESP32 (Wokwi)

Smart Password-Protected Alarm System Using ESP32 (Wokwi)
Hi everyone! In this project, I have designed and simulated a Smart Password-Protected Alarm System using the ESP32 microcontroller on the Wokwi simulator. This project is a core part of my personal desktop AI assistant project, named Jarvis.
The system acts as a smart security shield. It uses a matrix keypad for secure password entry, an OLED display to show real-time status messages, and sensors like a PIR motion sensor and ultrasonic sensor to detect unauthorized intrusions. If an incorrect password is entered or a motion breach is detected, a buzzer and LED indicators are instantly triggered to sound the alarm. This system runs completely on optimized C++ logic, making it highly responsive and perfect for modern IoT home security applications!




Supplies

Hardware Components used in Wokwi Simulator:
  1. ESP32 Development Board (The brain of our Jarvis alarm system)
  2. OLED Display (SSD1306 / I2C) (To display password status and system alerts)
  3. 4x4 Matrix Keypad (For secure password and pin code entry)
  4. PIR Motion Sensor (To detect unauthorized body movements)
  5. Ultrasonic Distance Sensor (HC-SR04) (To measure proximity or door breaches)
  6. Buzzer (To sound the loud audio alarm on security breach)
  7. LED Indicators (Red LED for alarm / Green LED for safe system)
  8. Resistors and Connecting Wires
Software & Tools:
  1. Wokwi Online Simulator (For complete circuit design and real-time execution)
  2. C++ Programming Language (To write optimized logic for loops and functions)


Circuit Connection

In this first step, we will wire up all our hardware components virtually on the Wokwi Simulator. Setting up the correct pin connections is crucial for our C++ code to run smoothly. Here is the pin mapping used in this Jarvis security system:
  1. OLED Display: Connected via I2C protocol. SDA pin goes to ESP32 Pin 21 and SCL pin goes to ESP32 Pin 22.
  2. 4x4 Keypad: Row and Column pins are mapped to digital I/O pins of the ESP32 to scan for keypresses.
  3. PIR Motion Sensor: The OUT pin is connected to a digital input pin (e.g., Pin 13) to monitor movement.
  4. Ultrasonic Sensor: Trig pin goes to Pin 5 and Echo pin goes to Pin 18 to measure breach distance.
  5. Buzzer & LEDs: The Buzzer is connected to Pin 25, the Red LED (Alarm) to Pin 26, and the Green LED (Safe) to Pin 27.
Note: Make sure to double-check all ground (GND) and VCC power lines in the simulator to avoid any runtime errors!



C++ Source Code

// Jarvis Smart Alarm System - C++ Source Code

#include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#include <Keypad.h>


#define SCREEN_WIDTH 128

#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);


// Keypad Setup

const byte ROWS = 4;

const byte COLS = 4;

char keys[ROWS][COLS] = {

{'1','2','3','A'},

{'4','5','6','B'},

{'7','8','9','C'},

{'*','0','#','D'}

};

byte rowPins[ROWS] = {14, 27, 26, 25};

byte colPins[COLS] = {33, 32, 13, 12};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);


// Pin Configurations

const int buzzerPin = 5;

const int ledPin = 18;

const int pirPin = 19;


String password = "1234"; // Default Jarvis password

String inputPassword = "";


void setup() {

Serial.begin(115200);

pinMode(buzzerPin, OUTPUT);

pinMode(ledPin, OUTPUT);

pinMode(pirPin, INPUT);

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {

Serial.println(F("SSD1306 allocation failed"));

for(;;);

}

display.clearDisplay();

display.setTextSize(1);

display.setTextColor(WHITE);

display.setCursor(0, 10);

display.println("JARVIS SYSTEM ONLINE");

display.display();

}


void loop() {

char key = keypad.getKey();

if (key) {

if (key == '#') { // Press # to submit password

if (inputPassword == password) {

display.clearDisplay();

display.setCursor(0, 10);

display.println("ACCESS GRANTED!");

display.display();

digitalWrite(ledPin, HIGH);

delay(2000);

digitalWrite(ledPin, LOW);

} else {

display.clearDisplay();

display.setCursor(0, 10);

display.println("ACCESS DENIED!");

display.display();

digitalWrite(buzzerPin, HIGH);

delay(2000);

digitalWrite(buzzerPin, LOW);

}

inputPassword = ""; // Clear input

} else if (key == '*') {

inputPassword = ""; // Reset input

} else {

inputPassword += key;

}

}

}


Live Simulation Link

You can test this smart alarm system online without any hardware components. Click the live simulation link below to open the project directly in the Wokwi simulator. Press the green start button to run the code, use the keypad to type the password, and see the real-time feedback on the OLED display!👉 Live Wokwi Project Link: [https://wokwi.com/projects/479297874179035137]