Setting up the Ai-Thinker ESP32-CAM with the Arduino IDE Camera Web Server example.
The AI-Thinker ESP32-CAM module features an ESP32-S chip, an OV2640 camera and a microSD card slot. They have them on AliExpress here. There are other ESP32 based camera modules available that should work if the pins are set in the sketch.
If you prefer to work with your ESP32 in the Espressif IDF there’s another guide here: ESP32 Camera Module with Face Recognition
Adding or Updating the ESP32 Range in the Arduino IDE
If you’ve never used an ESP32 board in the Arduino IDE you need to follow the first part of this tutorial: ESP32 Built-in OLED Heltec WiFi Kit 32
If you already have the ESP32 boards available in your IDE then you just need to update to the latest version of the board libraries. To do this, open the Arduino IDE and in the menu: Tools > Board:xxxxx > Boards Manager:
Search for ESP32:
Update this to the latest version.
The ESP32-CAM doesn’t come with a USB connector so you need either a CP2102 or a FT232RL USB to TTL Serial Converter to connect it to your PC. When using WiFi the ESP32 can use more current than is supplied via USB through these devices resulting in the module crashing and rebooting. I found the top device worked fine (I bought it here) but the FT232RL wouldn’t work without a separate supply to the 5V pin.
Wire the module according to the diagram above. The green connection should be connected when flashing the module and disconnected when running.
Running the Camera Web Server Example
Plug in your module and change the board settings to these:
Open the Sketch by navigating File > Examples > ESP32 > Camera > CameraWebServer:
Edit the Sketch defines to look like this (assuming you are using the Ai-Thinker module):
// Select camera model //#define CAMERA_MODEL_WROVER_KIT //#define CAMERA_MODEL_M5STACK_PSRAM #define CAMERA_MODEL_AI_THINKER
Change the following two lines to match your WiFi connection details:
const char* ssid = "NSA"; const char* password = "orange";
Click Upload to build and flash the Sketch to your device.
If you get an error that the device fails to connect. Check that the IO0 pin (green in the diagram) is connected to GND and press the reset button under the module and try again.
When the device has completed flashing, unplug IO0 from GND.
Open the serial monitor via Tools > Serial Monitor.
Press the reset button on the ESP32-CAM and watch the start up sequence in the serial monitor:
Look for the IP address that the ESP32 has been given on your network.
Type that IP address into your browser. You should be able to see a GUI on the left where you can control elements of the camera, set face detection and face recognition. Click Get Still to take a photo. Click Start Stream to see a video stream from the camera.
Here’s a list of resources that I used to get this working
https://github.com/espressif/arduino-esp32/tree/master/libraries/ESP32/examples/Camera/CameraWebServer – Arduino Camera Web Server example
https://github.com/espressif/esp-who – Homepage for the face recognition library
If I've saved you some time and you want to say 'Thanks!' you can buy me a coffee here...