qts-iot — ESP32-S3 simulation

An interactive ESP32-S3 circuit simulation you can run free in your browser on Velxio, by itsmebenn.

Components

Sketch code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <ESP32Servo.h>

#define I2C_SDA 8
#define I2C_SCL 9

LiquidCrystal_I2C lcd(0x27, 16, 2); // Coba ubah ke 0x3F jika layar blank suatu saat

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'}
};

// Menggunakan formasi Ultra-Safe Pins
byte rowPins[ROWS] = {7,6,5,4}; 
byte colPins[COLS] = {13,12,11,10}; 

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

String correctPIN = "1234"; // PIN Master Anda
String inputPIN = "";       // Memori penampung input pengguna
int wrongAttempts = 0;      // Penghitung percobaan salah
const int MAX_ATTEMPTS = 3; // Batas maksimal salah PIN

Servo myServo;
int servoPin = 37;
int pos = 0;

bool opened = false;

void setup() {
  Serial.begin(115200);
  Wire.begin(I2C_SDA, I2C_SCL);

  myServo.attach(servoPin);
  
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Enter PIN:");
}

void loop() {
  char key = keypad.getKey();

  if (key) {
    
    // --- 1. Jika menekan tombol '#' (ENTER) ---
    if (key == '#') {
      lcd.clear();
      
      if (inputPIN == correctPIN) {
        // --- JIKA PIN BENAR ---
        lcd.setCursor(0, 0);
        lcd.print("ACCESS GRANTED");
        lcd.setCursor(0, 1);
        lcd.print("Welcome Home!");
        wrongAttempts = 0; // Reset kesalahan jika sukses
        
        // TODO: Perintah Motor Servo Buka Pintu masuk di sini
        myServo.write(180);
        
        delay(3000);
      } else {
        // --- JIKA PIN SALAH ---
        wrongAttempts++; 
        
        if (wrongAttempts >= MAX_ATTEMPTS) {
          // Eksekusi Lockdown langsung di sini
          lcd.setCursor(0, 0);
          lcd.print("SYSTEM LOCKDOWN!");
          lcd.setCursor(0, 1);
          lcd.print("Please Wait...");
          delay(30000000); // Tahan sistem
          
          wrongAttempts = 0; // Reset setelah hukuman selesai
        } else {
          // Peringatan salah PIN biasa
          lcd.setCursor(0, 0);
          lcd.print("ACCESS DENIED!");
          lcd.setCursor(0, 1);
          lcd.print("Attempts left: ");
          lcd.print(MAX_ATTEMPTS - wrongAttempts);
          delay(2000);
        }
      }
      
      // Kembalikan ke layar awal hanya setelah semua proses (sukses/gagal/lockdown) selesai
      inputPIN = "";
      lcd.clear();
      lcd.print("Enter PIN:");
    }
    
    // --- 2. Jika menekan tombol '*' (CLEAR) ---
    else if (key == '*') {
      inputPIN = ""; // Hapus memori ketikan
      lcd.clear();
      lcd.print("Enter PIN:");
    }
    
    // --- 3. Jika menekan angka/huruf (INPUT PIN) ---
    else {
      inputPIN += key; // Tambahkan karakter ke memori sementara
      
      lcd.setCursor(0, 1);
      // Cetak bintang sebanyak jumlah angka yang sudah ditekan
      for (int i = 0; i < inputPIN.length(); i++) {
        lcd.print("*");
      }
    }
 

More projects by itsmebenn