Ai-Thinker ESP32-CAM in the Arduino IDE

camera-web-server-screen.jpg

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:

Boards Manager

Search for ESP32:

Boards Manager ESP32

Update this to the latest version.

Connections

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.

USB to ESP32-CAM Wiring Diagram

 

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:

IDE Camera Settings

Open the Sketch by navigating  File > Examples > ESP32 > Camera > CameraWebServer:

Camera Web Server Sketch

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:

Camera Web Server Startup

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.

ESP-WHO GUI

Resources

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

13 Replies to “Ai-Thinker ESP32-CAM in the Arduino IDE”

  1. Chris Lidyard says:

    Thanks for the article. Sorted me out and have donated. Keep posting, I’m interested in your adventures with the MAIX board.

    1. WordBot says:

      That’s great thanks! The MAIX is very interesting but they have a way to go to get to where the Espressif boards are with libraries etc.

  2. who_took_my_nick says:

    Brownout detector was triggered

    ets Jun 8 2016 00:22:57

    rst:0xc (SW_CPU_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:1
    load:0x3fff0018,len:4
    load:0x3fff001c,len:1100
    load:0x40078000,len:10088
    load:0x40080400,len:6380
    entry 0x400806a4

    It is power issue, as i can see from the forums. I power it as you suggested. From the same TTL adapter i use 5V and GND and connect it to 5V and GND on the ESP32 cam board. ESP module is little bit hot. Not sure is it ok. Any idea?

    1. WordBot says:

      I found that with the FT232RL connected with a USB cable that when the wifi started up it would crash with the brown out error. The other connector I plugged straight into my PC (no cable) and this was fine. It could be your adaptor or the USB cable that can’t carry the current needed. You can connect your own supply of 5v to the board (without the 5v and ground of the connector being connected) to see if that works.

  3. _rp_ says:

    Thanks for this…

    Any ideas on how to activate the flash light?

    rp

    1. WordBot says:

      Not yet. I’ll write a note if I find out.

      1. Piebe says:

        GPIO4 is the Flash

        1. _rp_ says:

          Thanks.
          That thing is bright…

  4. victor says:

    Do you have an example of how to save a photo to the card?

    1. WordBot says:

      Here’s a start – https://github.com/raphaelbs/esp32-cam-ai-thinker/tree/master/examples/sd_jpg but this is for the Espressif IDF. I’ve not tried it myself.

  5. Richard Luckman says:

    Just in case anyone has the same problem that I had whereby the module worked fine plugged directly into the PC but as soon as I moved it to photograph the bird table just outside the window I lost connection. On my module the jumper next to the IPEX connector was set to use the IPEX connector and not the circuit board antenna. Pictures I have seen on the web show it jumpered the other way. As it happened my eventual plan was to use it with an external antenna so it saved me having to alter the jumper

  6. Ian Muir says:

    After booting and watching the serial monitor mine just shows dots going across the screen and nothing else.
    I am running off a seperate 5v power supply.
    any Ideas?

    1. WordBot says:

      The dots are shown while it’s trying to connect to the your wifi network. Double check your wifi settings and maybe move closer to the router.

      Also – see this comment: https://robotzero.one/esp32-cam-arduino-ide/#comment-2703

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