hpña — Esp32 Devkit C V4 simulation

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;
bool pir_motion_activado = false;
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:AAE8NdoIyz2AygWw7SJw6Q2T8lLG1xYuo2k"
#define CHAT_ID   "7500661315"

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

const char HUELLA_VALIDA = '3';  

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

unsigned long tiempoInicio;
const unsigned long tiempoMaximo = 120000;

String configuracion_inicial() {
  String nueva = "";
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("ingrese la clave");
  lcd.setCursor(0, 1);
  lcd.print("por el keypad");
  lcd.setCursor(0, 0);
  while(nueva == ""){
    char tecla;
    if(tecla = teclado.getKey()) nueva += tecla;
  }
  lcd.clear();
  lcd.print(nueva);
  char tecla;
  while (true) {
    tecla = teclado.getKey();
    if (!tecla) continue;
    if(nueva.length() == 16) lcd.setCursor(0, 1);
    if (tecla == '#' ) break;
    if (tecla == '*') {
        nueva = "";
        lcd.clear();
        lcd.setCursor(0, 0);
        continue;
    }
    if (nueva.length() >= 32) {
    lcd.clear();
    lcd.print("LIMITE");
    delay(500);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(nueva.substring(0, 16));
    lcd.setCursor(0, 1);
    lcd.print(nueva.substring(16, 32));
    continue;
}

nueva += tecla;
lcd.print(tecla);

  }
  maximo = nueva.length();
  lcd.clear();
  lcd.print("Configurado");
  delay(800);
  lcd.clear();
  return nueva;
}

void buzzer_error() {
  for (int i = 0; i < 3; i++) {
    tone(buzzer, 2000);
    delay(500);
    noTone(buzzer);
    delay(500);
  }
}

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 desbloquearcerradura() {
  puerta.write(90);
  lcd.clear();
  lcd.print("Acceso OK");
  delay(500);
  pir_motion_activado = false;
  lcd.clear();
  lcd.print("Sistema activado");
}

bool leerHuella(unsigned long ventanaMs) {
  while (huellas.available()) huellas.read();   
  unsigned long t0 = millis();
  while (millis() - t0 < ventanaMs

More projects by figueblue