En este tutorial veremos como crear un lector/reloj de control de personal con esp32, un sensor lector de huellas digitales o fingerprint. Todos los datos se van a subir a la nube, a traves de los servicios de thingspeak.com Se va incluir el armado del circuito electrónico, la explicación detallada del código fuente y finalmente, se va a probar el dispositivo.
No te pierdas ningún video más suscríbete a nuestro canal de telegram https://t.me/carlosvolt_electronica_robotica
Tal vez pueda interesarte proyectos en arduino, pic, robótica, telecomunicaciones, suscribete en http://www.youtube.com/user/carlosvolt?sub_confirmation=1 mucho videos con código fuentes completos y diagramas
Componentes electrónicos
Un Esp32
Características del módulo ESP32-T
Conectividad
El módulo ESP32 dispone de todas las variantes del WiFi:
- 802.11 b/g/n/e/i/n
- Wi-Fi Direct (P2P), P2P Discovery, P2P Group Owner mode and P2P Power Management
Esta versión nueva incluye la conectividad mediante Bluethoot de bajo consumo
- Bluetooth v4.2 BR/EDR and BLE
- BLE Beacon
Además, puede comunicarse mediante los protocoles SPI, I2C, UART, MAC Ethernet, Host SD
Prestaciones del microcontrolador
La CPU está formado por un SoC modelo Tensilica LX6 con las siguientes características y memoria
- Doble núcleo de 32 bits con velocidad de 160MHz
- Memoria ROM de 448 kBytes
- Memoria SRAM de 520kBytes
Dispne de 48 Pines
- 18 ADC de 12 bits
- 2 DAC de 8 bits
- 10 pines sensores de contacto
- 16 PWM
- 20 Entradas/salidas digitales
Alimentación y modos de consumo
Para un correcto funcionamiento del ESP32 es necesario subministrar un voltaje de entre 2,8V y 3,6V. La energía que consume depende del modo de funcionamiento. Contiene un modo, el Ultra Low Power Solution (ULP), en que se continúan realizando tareas básicas (ADC, RTC…) en el modo Sleep.
Módulo fingerprint Open Smart
Descargar Manual –> R308-fingerprint-module-user-manual_English
Buzzer
Pines hembra
Pines macho
PCB
Descargar archivo gerber –> Esp32_fingerprint_PCB
Código Fuente
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
// Importar bibliotecas necesarias #include <WiFi.h> #include <HTTPClient.h> #include <Adafruit_Fingerprint.h> Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2); uint8_t id; int pin27 = 27; const int led = 2;//Led onboard del esp32 String numID; int codigo; // Establezca su nombre y contraseña de wifi const char* ssid = "Tu_red_wifi"; const char* password = "Tu_clave_wifi"; // La URL de tu canal de thingspeak con el número de api_key String nombreServidor = "https://api.thingspeak.com/update?api_key=Tu_Api_Key"; void setup() { while (!Serial); // Para Yun/Leo/Micro/Zero/... Serial.begin(9600);//Velocidad del puerto serie arduino pinMode(pin27, OUTPUT);//Buzzer pinMode(led, OUTPUT);//Led onboard del esp32 WiFi.begin(ssid, password); // Intenta conectarte a wifi con nuestra contraseña Serial.println("Conectando"); // Imprime nuestro estado en el monitor de serie // Espera a que se conecte el wifi while(WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Conectado a la red WiFi con la dirección IP: "); Serial.println(WiFi.localIP()); //Dos bip indican que se conectó el dispositivo a la red wifi bip(100); delay(400); bip(100); Serial.println("Inicio detección del módulo fingerprint"); // Velocidad de transmisión de datos entre el arduino y el módulo fingerprint finger.begin(57600); if (finger.verifyPassword()) { Serial.println("¡Sensor de huellas dactilares conectado ok!"); } else { Serial.println("Revisa la conexión del sensor de huellas :("); while (1); } Serial.println("Esperando una huella válida..."); } void loop() { datosFingerprint(); delay(50); //Pequeño delay } // Devuelve -1 si falla, de lo contrario devuelve ID # int datosFingerprint() { uint8_t p = finger.getImage(); if (p != FINGERPRINT_OK) return -1; p = finger.image2Tz(); if (p != FINGERPRINT_OK) return -1; p = finger.fingerFastSearch(); if (p != FINGERPRINT_OK) return -1; //Encontrado una coincidencia! Serial.print("Huella ID #"); Serial.print(finger.fingerID); Serial.print(" con una confianza de "); Serial.println(finger.confidence); //Activar el buzzer durante 100 mili segundos bip(100); delay(100); numID = String(finger.fingerID); //Convierte el id en cadena para ser compatible con el display Serial.print("Huella Correcta # "); Serial.println(numID); digitalWrite(led, HIGH); ////--------------------- if(WiFi.status()== WL_CONNECTED){ // Comprueba que la wifi todavía esté conectada HTTPClient http; // Inicializar nuestro cliente HTTP String url = nombreServidor + "&field1=" + numID ; // Definir nuestra URL completa http.begin(url.c_str()); // Inicializa nuestra solicitud HTTP int codigoRespuestaHTTP = http.GET(); // Enviar solicitud HTTP if (codigoRespuestaHTTP > 0){ // Verifica que haya código de estado HTTP correcto Serial.print("Codigo de respuesta HTTP: "); Serial.println(codigoRespuestaHTTP); codigo = codigoRespuestaHTTP; }else{ Serial.print("Codigo de error: "); Serial.println(codigoRespuestaHTTP); //Reintentamos una vez más por si hubo un error en la comunicación http.begin(url.c_str()); // Inicializa nuestra solicitud HTTP int codigoRespuestaHTTP = http.GET(); // Enviar solicitud HTTP if (codigoRespuestaHTTP > 0){ // Verifica que haya código de estado HTTP correcto Serial.print("Codigo de respuesta HTTP: "); Serial.println(codigoRespuestaHTTP); } } http.end(); } else { Serial.println("WiFi desconectado"); } numID=""; delay(10000); //Bip largo sibió datos a thingspeak if(codigo == 200){ digitalWrite(led, LOW); bip(750); } //Tres bip hubo un problema al subir los datos a thingpeag if(codigo != 200){ bip(150); delay(150); digitalWrite(led, LOW); bip(150); delay(150); digitalWrite(led, HIGH); bip(150); delay(150); digitalWrite(led, LOW); } } //Sonido del buzzer void bip(int demora){ digitalWrite(pin27, HIGH); delay(demora); digitalWrite(pin27, LOW); } |
Código Enroll para esp32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
#include <Adafruit_Fingerprint.h> Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2); uint8_t id; uint8_t getFingerprintEnroll(); void setup() { while (!Serial); // For Yun/Leo/Micro/Zero/... delay(500); Serial.begin(9600); Serial.println("Adafruit Fingerprint sensor enrollment"); // set the data rate for the sensor serial port finger.begin(57600); if (finger.verifyPassword()) { Serial.println("Found fingerprint sensor!"); } else { Serial.println("Did not find fingerprint sensor :("); while (1); } } uint8_t readnumber(void) { uint8_t num = 0; boolean validnum = false; while (1) { while (! Serial.available()); char c = Serial.read(); if (isdigit(c)) { num *= 10; num += c - '0'; validnum = true; } else if (validnum) { return num; } } } void loop() // run over and over again { Serial.println("Ready to enroll a fingerprint! Please Type in the ID # you want to save this finger as..."); id = readnumber(); Serial.print("Enrolling ID #"); Serial.println(id); while (! getFingerprintEnroll() ); } uint8_t getFingerprintEnroll() { int p = -1; Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id); while (p != FINGERPRINT_OK) { p = finger.getImage(); switch (p) { case FINGERPRINT_OK: Serial.println("Image taken"); break; case FINGERPRINT_NOFINGER: Serial.println("."); break; case FINGERPRINT_PACKETRECIEVEERR: Serial.println("Communication error"); break; case FINGERPRINT_IMAGEFAIL: Serial.println("Imaging error"); break; default: Serial.println("Unknown error"); break; } } // OK success! p = finger.image2Tz(1); switch (p) { case FINGERPRINT_OK: Serial.println("Image converted"); break; case FINGERPRINT_IMAGEMESS: Serial.println("Image too messy"); return p; case FINGERPRINT_PACKETRECIEVEERR: Serial.println("Communication error"); return p; case FINGERPRINT_FEATUREFAIL: Serial.println("Could not find fingerprint features"); return p; case FINGERPRINT_INVALIDIMAGE: Serial.println("Could not find fingerprint features"); return p; default: Serial.println("Unknown error"); return p; } Serial.println("Remove finger"); delay(2000); p = 0; while (p != FINGERPRINT_NOFINGER) { p = finger.getImage(); } Serial.print("ID "); Serial.println(id); p = -1; Serial.println("Place same finger again"); while (p != FINGERPRINT_OK) { p = finger.getImage(); switch (p) { case FINGERPRINT_OK: Serial.println("Image taken"); break; case FINGERPRINT_NOFINGER: Serial.print("."); break; case FINGERPRINT_PACKETRECIEVEERR: Serial.println("Communication error"); break; case FINGERPRINT_IMAGEFAIL: Serial.println("Imaging error"); break; default: Serial.println("Unknown error"); break; } } // OK success! p = finger.image2Tz(2); switch (p) { case FINGERPRINT_OK: Serial.println("Image converted"); break; case FINGERPRINT_IMAGEMESS: Serial.println("Image too messy"); return p; case FINGERPRINT_PACKETRECIEVEERR: Serial.println("Communication error"); return p; case FINGERPRINT_FEATUREFAIL: Serial.println("Could not find fingerprint features"); return p; case FINGERPRINT_INVALIDIMAGE: Serial.println("Could not find fingerprint features"); return p; default: Serial.println("Unknown error"); return p; } // OK converted! Serial.print("Creating model for #"); Serial.println(id); p = finger.createModel(); if (p == FINGERPRINT_OK) { Serial.println("Prints matched!"); } else if (p == FINGERPRINT_PACKETRECIEVEERR) { Serial.println("Communication error"); return p; } else if (p == FINGERPRINT_ENROLLMISMATCH) { Serial.println("Fingerprints did not match"); return p; } else { Serial.println("Unknown error"); return p; } Serial.print("ID "); Serial.println(id); p = finger.storeModel(id); if (p == FINGERPRINT_OK) { Serial.println("Stored!"); } else if (p == FINGERPRINT_PACKETRECIEVEERR) { Serial.println("Communication error"); return p; } else if (p == FINGERPRINT_BADLOCATION) { Serial.println("Could not store in that location"); return p; } else if (p == FINGERPRINT_FLASHERR) { Serial.println("Error writing to flash"); return p; } else { Serial.println("Unknown error"); return p; } } |
Código delete para esp32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
#include <Adafruit_Fingerprint.h> Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2); uint8_t getFingerprintEnroll(uint8_t id); void setup() { Serial.begin(9600); Serial.println("Delete Finger"); // set the data rate for the sensor serial port finger.begin(57600); if (finger.verifyPassword()) { Serial.println("Found fingerprint sensor!"); } else { Serial.println("Did not find fingerprint sensor :("); while (1); } } void loop() // run over and over again { while (!Serial); // For Yun/Leo/Micro/Zero/... delay(500); Serial.println("Type in the ID # you want delete..."); uint8_t id = 0; while (true) { while (! Serial.available()); char c = Serial.read(); if (! isdigit(c)) break; id *= 10; id += c - '0'; } Serial.print("deleting ID #"); Serial.println(id); deleteFingerprint(id); } uint8_t deleteFingerprint(uint8_t id) { uint8_t p = -1; p = finger.deleteModel(id); if (p == FINGERPRINT_OK) { Serial.println("Deleted!"); } else if (p == FINGERPRINT_PACKETRECIEVEERR) { Serial.println("Communication error"); return p; } else if (p == FINGERPRINT_BADLOCATION) { Serial.println("Could not delete in that location"); return p; } else if (p == FINGERPRINT_FLASHERR) { Serial.println("Error writing to flash"); return p; } else { Serial.print("Unknown error: 0x"); Serial.println(p, HEX); return p; } } |
VIDEO RECOMENDADO