From Face Recognition FAIL to Maximum Accuracy: How I Built an ESP32 CAM Face Recognition Attendance System (And You Can Too)

The Day My Face Recognition Called Me “UNKNOWN”
I stood in front of my ESP32 CAM, smiling. | ESP32 Cam Face Recognition System fingers crossed with hope.
The screen flashed: “UNKNOWN”
I moved closer. Adjusted the lighting. Tilted my head.
“UNKNOWN”
I showed it a photo of Elon Musk.
“UNKNOWN”
I showed it a photo of myself again.
“UNKNOWN”
Three days. Forty-seven attempts. Countless Google searches. And my face recognition system still didn’t know who I was.
I was ready to throw the whole project into the trash.
But then, something clicked. And when it finally worked – when that green box appeared around my face with my name and “98.4%” confidence – I literally punched the air.
This is the story of how I built an ESP32 CAM face recognition attendance system, fought with Python packages for hours, and finally won.
And I’m going to show you exactly how to do it without losing your mind.
What Are We Building?
Imagine this:
You walk into a room. An ESP32 CAM watches. In less than a second, your face is recognized. Your name appears on screen. Your attendance is automatically logged in a CSV file with the exact time and date.
No fingerprint scanner. No ID card. No manual entry.
Just your face.
That’s what we’re building.
| Component | What It Does |
|---|---|
| ESP32 CAM | Captures live video and streams it over WiFi |
| Python Script | Fetches frames, detects faces, recognizes who they are |
| Deep Learning Model | The brain that actually recognizes faces (99.38% accurate) |
| CSV File | Logs attendance with timestamps |

The Problem That Almost Made Me Quit
Before we get to the working version, let me tell you about the nightmare.
I had Python 3.14 installed. I thought “newer is better.”
Wrong.
Every single package fought back:
| Package | What Happened |
|---|---|
| dlib | Required C++ compilation – failed for 2 hours |
| face_recognition | Couldn’t find its own model files |
| numpy | Version conflicts with everything |
| opencv-python | Incompatible with numpy versions |
I saw errors like:
ModuleNotFoundError: No module named 'pkg_resources'Cannot convert longdouble infinity to integerPlease install face_recognition_models
I wanted to cry.
The fix? Python 3.12, not 3.14. And setuptools version 80.0.0, not the latest.
That single change saved everything.
What You’ll Need
Hardware
| Component | Approx Price (USD) | Notes |
|---|---|---|
| ESP32 CAM Module | $8-12 | Includes OV2640 camera |
| FTDI Programmer | $3-5 | For uploading code (first time only) |
| USB Cable | $2-4 | Data cable, not just charging |
| Power Supply | $5-10 | Phone charger works fine |
Software (All Free)
| Software | Purpose |
|---|---|
| Python 3.12 | The programming language |
| VS Code or Arduino IDE | For ESP32-CAM code |
| Python Libraries | opencv, face_recognition, numpy, pandas |
Total hardware cost: ~$15-25 USD – less than a pizza with extra toppings!
Step 1: Setting Up the ESP32 CAM (The Camera)
The ESP32 CAM is the eye of our system. It captures video and streams it over WiFi.
Wiring the ESP32-CAM for Programming
| FTDI Programmer | ESP32-CAM |
|---|---|
| 5V | 5V |
| GND | GND |
| TX | U0R (GPIO 3) |
| RX | U0T (GPIO 1) |
Important: To upload code, connect GPIO 0 to GND, press reset, then upload. Remove the connection after uploading.
Quick Buy Links
| Component | Where to Find |
|---|---|
| ESP32 CAM Module | AliExpress |
| FTDI Programmer | AliExpress |
All the Codes Files:
📦 Complete Code on GitHub
Instead of cluttering this blog post with hundreds of lines of code, I’ve uploaded everything to GitHub. You’ll find:
✅ Complete ESP32-CAM Arduino code (ready to upload)
✅ Full Python attendance script (copy-paste ready)
✅ requirements.txt with all dependencies
✅ Pre-configured User_Setup.h for TFT display (if using)
✅ Wiring diagrams
👉 Get the complete code here: https://github.com/roborear/esp32-cam-face-recognition
Read the readme.md; everything is described there.
⭐ Star the repo if it helps you – it really motivates me to create more projects!
The ESP32 CAM Code and
Upload this code to your ESP32 CAM using Arduino IDE or VS Code with PlatformIO: https://github.com/shahrear-ab/Face-Recognition-Attendance-System/blob/main/ESP32CAM_FaceRecognition/src/main.cpp
After uploading, open Serial Monitor (115200 baud). You’ll see:
CAMERA OK WiFi connected http://192.168.x.x Server started
Copy that IP address. You’ll need it for the Python script.
Step 2: Setting Up Python (The Brain)
This is where the magic happens. But be careful – this is also where I lost two days.
The Golden Rule: Use Python 3.12
Not 3.14. Not 3.13. Python 3.12.
Everything works on 3.12. Nothing works on 3.14.
Create a Virtual Environment
# Navigate to your project folder cd C:\Users\YourName\ATTENDANCE # Create virtual environment with Python 3.12 py -3.12 -m venv .venv # Activate it (Windows) .venv\Scripts\activate # You should see (.venv) in your prompt
Install Packages in the RIGHT Order
This order is CRITICAL. I learned this the hard way.
# First, install the correct version of setuptools pip install setuptools==80.0.0 # Then install dlib (pre-compiled, no compilation needed) pip install dlib-bin # Then face_recognition pip install face_recognition # Finally, other packages pip install opencv-python pandas numpy
Why this order?
setuptools 80.0.0 works with face_recognition_models
dlib-bin avoids C++ compilation hell
face_recognition pulls the models correctly
Step 3: Preparing Training Images
The system needs to learn what faces look like. Create a folder called Training_images and add photos:
Training_images/ ├── your_name_1.jpg ├── your_name_2.jpg ├── your_name_3.jpg ├── elon_musk_1.jpg ├── elon_musk_2.jpg └── mark_zuckerberg_1.jpg
Tips for good training images:
| ✅ DO THIS | ❌ DON’T DO THIS |
|---|---|
| Front-facing photos | Side profiles |
| Good lighting | Dark or shadowy images |
| Clear, sharp images | Blurry photos |
| 2-5 images per person | One image only |
| Different expressions | Same photo repeated |

Step 4: The Complete Python Code
Here’s the full attendance system code. Save it as face_detection_attendance.py:
VS Code + PlatformIO Setup: If you have a blog explaining how to set up the professional coding environment instead of the default Arduino IDE Robotics for Beginners: Learn ESP32 PlatformIO with VS Code | Blink LED Tutorial
Step 5: Running the System
First Run (Training)
python face_detection_attendance.py
The system will:
Detect faces in your
Training_imagesfolderGenerate face encodings (mathematical representations)
Save them to
face_encodings.pickle
You should see:
🔄 Training face recognizer... ✅ Your Name ← your_name_1.jpg ✅ Your Name ← your_name_2.jpg ✅ Elon Musk ← elon_musk_1.jpg ✅ TRAINING COMPLETE! Your Name: 2 image(s) Elon Musk: 1 image(s) TOTAL: 2 person(s)
Live Recognition
After training, the system will:
Connect to ESP32 CAM
Show live video feed
Draw green boxes around recognized faces
Show confidence percentages
Log attendance to
Attendance.csv
What The CSV File Looks Like
Open Attendance.csv in Excel or Notepad:
Name,Time,Date YOUR NAME,09:15:23,2026-04-19 ELON MUSK,09:16:45,2026-04-19
Each person is logged only once per day.
This attendance system uses face recognition, but if you want to build simpler ESP32 projects first, check out my [ESP32 Pomodoro Timer] for learning sensors.
Troubleshooting (What I Learned)
The “Unknown” Face Problem
| Symptom | Fix |
|---|---|
| Always shows UNKNOWN | Lower tolerance in compare_faces(..., tolerance=0.6) |
| Wrong person recognized | Add more training images (3-5 per person) |
| No face detected | Check lighting – add more light |
The Python Package Nightmare
| Error | Solution |
|---|---|
No module named 'pkg_resources' | pip install setuptools==80.0.0 |
dlib compilation failed | pip install dlib-bin (not dlib) |
numpy version conflict | Use Python 3.12, not 3.14 |
ESP32 CAM Connection Issues
| Problem | Fix |
|---|---|
| Can’t access IP in browser | Check ESP32 CAM is on same WiFi network |
| Connection timeout | Update IP address in Python code |
| Blurry image | Adjust focus ring on camera lens |
Upgrades and Ideas
Once you have the basic system working, here’s how to level up:
| Upgrade | Difficulty | What You’ll Need |
|---|---|---|
| Add more people | Easy | More training images |
| Email alerts on recognition | Medium | SMTP library |
| Save recognized face images | Medium | cv2.imwrite() |
| Telegram bot notifications | Medium | python-telegram-bot |
| Web dashboard | Hard | Flask + HTML |
| Multiple cameras | Hard | Multiple ESP32 CAMs |
The Moment It Finally Worked
After three days of fighting with Python packages, incorrect versions, and mysterious errors, I stood in front of the camera one more time.
The green box appeared.
“SHAHREAR (68.4%)”
The buzzer on my desk didn’t go off. No fanfare. Just a quiet CSV file updating with my name and the current time.
But I knew. I had beaten the machine.
And now you can too.
Your Turn
This project taught me that the biggest enemy isn’t the code – it’s the environment. Python versions, package conflicts, missing dependencies. That’s where projects go to die.
But once you get past that? The actual face recognition just works.
So go build it. Train it with your face. Show it to your friends. Watch it recognize Elon Musk and Mark Zuckerberg correctly (yes, it can tell them apart).
And when that green box appears with your name, you’ll know exactly what I felt.
Prefer watching over reading? Join the Roborear community on YouTube https://www.youtube.com/channel/UCLbwg7Eo1UNTX45oeNBtk4A/
FAQs
1. Why is my ESP32-CAM not connecting or showing "Failed to connect to ESP32" error?
2. Why does my Python script show "Please install face_recognition_models" even though I already installed it?
3. What is the accuracy of this face recognition system? How far can the person stand from the camera?
Affiliate Disclosure
Some links in this post are affiliate links. If you purchase through them, I may earn a small commission at no extra cost to you. This helps support Roborear. Thanks!






