Sistema de Seguridad ESP32 — Esp32 Devkit C V4 simulation

Sistema de seguridad con ESP32, teclado matricial, sensor de huellas, servo y Telegram.

An interactive Esp32 Devkit C V4 circuit simulation you can run free in your browser on Velxio, by figueblue.

Components

Sketch code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <ESP32Servo.h>

HardwareSerial huellas(2); 

const int TX_huella = 16;
const int RX_huella = 17;
Servo puerta;
const int SERVO = 5;
const int pir_motion = 0;
const int buzzer = 23;

const byte FILAS = 4;
const byte COLUMNAS = 4;
char teclas[FILAS][COLUMNAS] = {
  {'1','2','3','A'},   
  {'4','5','6','B'},   
  {'7','8','9','C'},   
  {'*','0','#','D'}    
};
byte pinesFilas[FILAS] = {13, 14, 27, 26};
byte pinesColumnas[COLUMNAS] = {25, 33, 32, 18};
Keypad teclado = Keypad(makeKeymap(teclas), pinesFilas, pinesColumnas, FILAS, COLUMNAS);

const char* SSID = "Velxio-GUEST";       
const char* PASS = "";                   
#define BOT_TOKEN "9226577341:AAEsW7g7RkuPYYlDtGKbIRsowCAcyt6wgp0"  
#define CHAT_ID   "7500661315"

String ingresado;
String clave = "";
int maximo = 0;
int intentos_maximo = 2;
int intentos = 0;

LiquidCrystal_I2C lcd(0x27, 16, 2);
WiFiClientSecure clienteTLS;
UniversalTelegramBot bot(BOT_TOKEN, clienteTLS);

unsigned long tiempoInicio;
const unsigned long tiempoMaximo = 10000; // 10 minutos



void configuracion_inicial(){
  char confirmar = ' ';
  lcd.setCursor(0, 0);
  lcd.print("ingrese la clave");
  lcd.setCursor(0, 1);
  lcd.print("por el keypad");
  while(clave == ""){
    char tecla;
    if(tecla = teclado.getKey()) clave += tecla;
  }
  lcd.clear();
  lcd.print(clave);
  while(confirmar != '#' && clave.length() <= 32){
      if(clave.length() == 16){
        lcd.setCursor(0,1);


      }
     if(confirmar = teclado.getKey()){
        clave += confirmar;
        lcd.print(confirmar);

     } 


  }
  lcd.clear();
  lcd.println("configurado");
  delay(500);
  lcd.clear();
  maximo = clave.length();
}


void buzzer_activado(){
    for(int i = 0; i < 3; i++){
        // El primer parámetro es el pin, el segundo es la frecuencia en Hz (ej. 2000Hz)
        tone(buzzer, 2000); 
        delay(500);         // Duración del pitido
        noTone(buzzer);     // Apagar el tono
        delay(500);         // Pausa entre pitidos
    }
}
void avisarTelegram(String msg) {
  Serial.println("[Telegram] " + msg);   
  if (WiFi.status() != WL_CONNECTED) { Serial.println("  -> sin WiFi"); return; }
  bool ok = bot.sendMessage(CHAT_ID, msg, "");
  Serial.println(ok ? "  -> enviado OK" : "  -> FALLO (revisar TLS/token/chatID)");
}
void setup(){
  Serial.begin(115200);
  
  // 1. PRIMERO inicializamos el bus I2C con los pines correctos de la ESP32
  Wire.begin(21, 22);

  // 2. Luego inicializamos pines y periféricos
  pinMode(pir_motion, INPUT);
  pinMode(SERVO, OUTPUT);
  pinMode(buzzer, OUTPUT);
  
  huellas.begin(57600, SERIAL_8N1, RX_huella, TX_huella);
  puerta.attach(SERVO);
  puerta.write(0);

  // 3. Ahora sí podemos inicializar la pantalla LCD con seguridad
  lcd.init();
  lcd.backlight();

  // 4. Configuración inicial y WiFi
  configuracion_inicial();

  WiFi.begin(SSID, PAS

More projects by figueblue