Access Control with Face Recognition


Open a door when a face is recognised using the ESP32-CAM

This page contains code and other information for the the YouTube video found here:

The code is a combination of the ESP32-CAM Face Recognition for Home Automation and ESP-WHO Face Recognition with WebSocket Communication tutorials.

As mentioned in the video, while this demonstration works well, the ESP32-CAM and associated IDF and Arduino libraries don’t match professional face based access control systems. It can be easily tricked and doesn’t check for ‘liveness’. It could be used as a secondary control system to open doors or activate systems for people that have already passed through another access control system.

If you want to see more tutorials like this such as doorbell camera then please say ‘thanks’ with a coffee below.

Here’s the current code used. You can download this with the other files you need here:

40 Replies to “Access Control with Face Recognition”

  1. Jasou says:

    Hi !
    Thankk you for the code , but i have a problem with esp32 cam when i enter access control it freezes then crashes and i have to restart it to work again , can it be a problem of overheating or something else ? any idea to fix this ?

    1. WordBot says:

      Hi, I was sometimes seeing this. I’m not sure if it’s a bug in the Espressif libraries (I think someone else has reported this) or the camera is just overheating. It seemed random to me.

  2. Noppanun says:

    Hi !
    I’m thai and love this project,so plz tell me how to detect intruder in code i’m beginner.

    1. WordBot says:

      Hi, I’m not sure what you mean but check out the other tutorials on the site and maybe there’s something to help.

  3. Dimitris says:

    First of all congrats for this great work!
    I’m facing an issue on this project…Everything was running perfect until the last couple of days i was no longer able to stream from the esp-32 cam, as a result it couldn’t detect or recognize faces anymore. I updated the boards and libraries, i even tried it from different computer and browser but still the same. I still can browse into the web UI but it won’t stream any image from the left window. I tested my esp32-cam board on other projects and it’s fully functional. So, any thoughts what’s causing this issue? Thanks!

    1. WordBot says:

      Does the camerawebserver example work for you? If you load that up can see the video at http://your-ip-address:81/stream ? Might be the camera.

  4. Keith Mack says:

    Success, installed 12/1/2019! Did the partition table changes and installed the code from the zip file. Worked great, no issues!
    Tried to strip down the code for OTA but couldn’t get that to work, only had about 10 minutes to work on the OTA, I’ll try again later.
    Thanks very much for posting this and the YouTube video!

    1. WordBot says:

      Great! It’s always nice to hear when people have a project working.

  5. Eva says:

    Thanks for sharing this. I implemented it and tried compiling the code; but got the following error message:
    ‘ Sketch too big; see for tips on reducing it.
    Error compiling for board ESP32 Wrover Module. ”
    Please, what should I do to solve this? If I change partition scheme to ”Huge App (3MB No OTA…), it compiles.

    1. WordBot says:

      Did you create a new partition following this tutorial – ? It’s a big application but also needs the partition for storing faces.

  6. Preman Jeyabalan says:

    Hi, I’ve followed what you’ve done but when I copy the code in I get the following error:

    ‘struct mtmn_config_t’ has no member named ‘type’

    Any solutions to this?

    1. WordBot says:

      Hi, Probably the wrong ESP32 Hardware library is installed. Which version are you using?

  7. Preman Jeyabalan says:

    Hi, sorted that out, yup I was using the wrong hardware. Sorry to ask a question a little unrelated here, but if say i wanted to store the enrolled faces on a google firebase database, which function do I call that contains the blob information?

    I’m quite new to this and I haven’t found any help online.

    1. WordBot says:

      I’m not sure how you would save the face information somewhere different from the flash memory. I don’t know how well the recognition would work if it was testing against face data that wasn’t stored locally… it might be too slow.

  8. cavim says:

    hey i want ask about something
    I have followed all the ways to be done but I found an error

    Camera Ready! Use’′ to connect
    [D] [WiFiClient.cpp:509] connected(): Disconnected: RES: -1, ERR:104
    [E] [WiFiClient.cpp:392] write(): fail on fd 60, errno: 104, “Connection reset by peer”
    [E] [WiFiClient.cpp:392] write(): fail on fd 61, errno: 104, “Connection reset by peer”

    can you help me? why show this error

    1. WordBot says:

      Do you know which version of the ESP32 Hardware libraries you are using? Does it always happen?

  9. cavim says:

    Im using v1.0.4
    Yes it always happens, and until now it’s still like that

    1. WordBot says:

      Hmmm. I’m not sure. I thought it was a problem with a previous version of the Wi-Fi library. It works fine on my ESP-EYE so it should be OK on the Ai-Thinker.

      I noticed that when I close the browser I see that message which means it comes up when the connection to the browser is lost for whatever reason.

      Can you move closer to the router? Might be a power issue as well if the radio for the Wi-Fi doesn’t have enough juice.

  10. +krish sharan says:

    whenever i click the ip given in serial monitor it shows like
    WiFi connected
    Camera Ready! Use ‘’ to connect
    [E][WiFiClient.cpp:392] write(): fail on fd 60, errno: 104, “Connection reset by peer”

    IT shows an error.Please hep me out

    1. WordBot says:

      Does it work at all? I guess you are using the 1.0.4 of the ESP Hardware libraries? Can you try moving closer to your router?

  11. Vichu says:

    Hello, thanks for the great code snippet.
    I also faced the same issue, when I entered access control the camera freezes and the system reboots.
    I have made a small changes and the issue is resolved.
    Under the recognition branch statement above the line of code “if(f)” the piece of code
    “Serial.println(f->id_name);” is removed. Before validating the condition the name is printed in serial monitor causing load prohibited error and causing the system to reboot in my scenario.
    Thanks again..

    1. WordBot says:

      Ah.. thanks for pointing that out. I hadn’t noticed that line sitting there. I’ve removed it.

  12. ANIRBAN GHOSAL says:

    Please help..
    Showing error during compliling. It shows “camrea_index.h” no such file or director ”..

    “Multiple libraries were found ” for WiFi.h

    1. WordBot says:

      You need to read the tutorial entirely. You’ve not got all the files you need in the directory.

  13. wasantha says:

    Sir I am getting error on line 200 saying “static inline int do_enrollment(face_id_name_list *face_list, dl_matrix3d_t *new_id)”
    can you help me.
    hope to hear form you soon

    1. WordBot says:

      Hi. What error do you see?

  14. Andri says:

    Hello Master
    I have error
    [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 0 – WIFI_READY
    [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 2 – STA_START
    ..[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 5 – STA_DISCONNECTED
    [W][WiFiGeneric.cpp:353] _eventCallback(): Reason: 2 – AUTH_EXPIRE
    ..[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 4 – STA_CONNECTED
    [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 7 – STA_GOT_IP
    [D][WiFiGeneric.cpp:381] _eventCallback(): STA IP:, MASK:, GW:
    WiFi connected
    Camera Ready! Use ‘’ to connect
    [D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128

    Now. I use Board 1.0.4 and library manager arduinowebsockets ver. 0.4.10 for Arduino 1.8.12
    Before the upgrade went well. But now it can’t.
    Can You help me…

    1. WordBot says:

      Hi, I thought it wasn’t working before updating to 1.0.4? It might be a poor Wi-Fi connection. Does the CameraWebServer example work well for you?

  15. Andri says:

    When I try to use the example camera webserver works fine, sir.

  16. You are cool says:

    Hello, thanks for the great instructions…..

    One question can I directly access the camera stream?

    1. WordBot says:

      Hi. If you just want the stream the easiest way is to load up the CameraWebServer example and open http://ip.address.of.esp32:81/stream

  17. Temp says:

    Hello, is it possible to increase the frame size to svga???

    1. WordBot says:

      Hi, You can stream at SVGA but the face detection etc has to be run at a lower resolution.

  18. Temp says:

    Hello, why has the face recognition has to be run at a lower resolution??

    1. WordBot says:

      It’s a limit of the hardware but mostly face recognition doesn’t need high resolution images.

  19. temp says:

    How can I change the resolution during runtime? Can you show me this?

    1. WordBot says:

      You can change the resolution like this:
      sensor_t * s = esp_camera_sensor_get();
      s->set_framesize(s, FRAMESIZE_SVGA);
      camera_fb_t * fb = esp_camera_fb_get();

      But not while grabbing frames. You would have to close the framebuffer with esp_camera_fb_return(fb); then change and restart.

  20. sneyl says:

    Sorry, but can you help me? What happens is that when editing the html file that comes inside the zip, it does not make the changes, for example it does not change the text to Spanish, but always remains in English
    Does anyone know why? or where it has to be modified?

    1. WordBot says:

      HTML file is just for reference. Check this tutorial for how to edit the HTML –

  21. Amgad Steen says:

    This is a great work and it works for me fine. Thanks very much
    My question how to activate access control on start without clicking
    its button from web server ?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

scroll to top