ESP32-CAM AI-Thinker Camera Module, OV2640, Wi-Fi and Bluetooth

140,00 DH 160,00 DH

Availability:

3 in stock

SKU: 0034-A Categories: ,

Description

ESP32-CAM Camera Module with OV2640

Compact camera module based on an ESP32 dual-core microcontroller, with an OV2640 camera, GPIO connections and a microSD card slot for storing images and files.

  • Microcontroller: ESP32 dual-core family
  • Camera: OV2640
  • Wireless: 802.11 b/g/n Wi-Fi and Bluetooth 4.2 BR/EDR plus BLE, as listed by the source
  • Flash memory: 4MB, as listed by the source
  • Storage: microSD card slot
  • GPIO: several pins exposed; some are shared with camera, microSD and onboard functions

The module does not include a built-in USB programming interface. Use a compatible USB-to-TTL programmer. Verify the exact board version and pinout before wiring.

Applications

  • Video and image capture
  • IoT projects that capture or process images
  • Connected-device prototyping

Parts and tools

Arduino IDE setup

  1. Install the Arduino IDE from the official Arduino website.
  2. Install the Espressif ESP32 board package using the Boards Manager URL listed in the source: https://dl.espressif.com/dl/package_esp32_index.json.
  3. Choose a board profile that matches the exact ESP32-CAM hardware. The source names “ESP32 Wrover Module”; the example below uses AI-Thinker ESP32-CAM pin definitions, so verify the selected profile and camera mapping against your board.

USB-to-TTL connections

  • Adapter RX → ESP32-CAM TX
  • Adapter TX → ESP32-CAM RX
  • Adapter 5V → board VCC (only if the adapter can supply the required current)
  • Adapter GND → board GND

Use 3.3V UART logic levels. Follow the adapter and board instructions for entering programming mode. Download the Windows driver package.

Arduino camera and microSD example

The source code below initializes the camera and SD card, captures a JPEG image, saves it to the card, and repeats every 10 seconds. Despite the source introduction, this code does not toggle the onboard LED.

#include "esp_camera.h"
#include "FS.h"
#include "SD_MMC.h"


// ----------------------------------------------------------------------------
// 1. Camera pins (AI‑Thinker / ESP32‑CAM)
// ----------------------------------------------------------------------------
#define PWDN_GPIO_NUM    32
#define RESET_GPIO_NUM   -1
#define XCLK_GPIO_NUM     0
#define SIOD_GPIO_NUM    26
#define SIOC_GPIO_NUM    27
#define Y9_GPIO_NUM      35
#define Y8_GPIO_NUM      34
#define Y7_GPIO_NUM      39
#define Y6_GPIO_NUM      36
#define Y5_GPIO_NUM      21
#define Y4_GPIO_NUM      19
#define Y3_GPIO_NUM      18
#define Y2_GPIO_NUM       5
#define VSYNC_GPIO_NUM   25
#define HREF_GPIO_NUM    23
#define PCLK_GPIO_NUM    22


// ----------------------------------------------------------------------------
// 2. Allocate an empty camera_config_t
// ----------------------------------------------------------------------------
camera_config_t camera_config;


void setup() {
  Serial.begin(115200);
  delay(100);


  // ——— Fill in the pins & settings ———
  camera_config.ledc_channel = LEDC_CHANNEL_0;
  camera_config.ledc_timer   = LEDC_TIMER_0;
  camera_config.pin_d0       = Y2_GPIO_NUM;
  camera_config.pin_d1       = Y3_GPIO_NUM;
  camera_config.pin_d2       = Y4_GPIO_NUM;
  camera_config.pin_d3       = Y5_GPIO_NUM;
  camera_config.pin_d4       = Y6_GPIO_NUM;
  camera_config.pin_d5       = Y7_GPIO_NUM;
  camera_config.pin_d6       = Y8_GPIO_NUM;
  camera_config.pin_d7       = Y9_GPIO_NUM;
  camera_config.pin_xclk     = XCLK_GPIO_NUM;
  camera_config.pin_pclk     = PCLK_GPIO_NUM;
  camera_config.pin_vsync    = VSYNC_GPIO_NUM;
  camera_config.pin_href     = HREF_GPIO_NUM;
  camera_config.pin_sscb_sda = SIOD_GPIO_NUM;
  camera_config.pin_sscb_scl = SIOC_GPIO_NUM;
  camera_config.pin_pwdn     = PWDN_GPIO_NUM;
  camera_config.pin_reset    = RESET_GPIO_NUM;
  camera_config.xclk_freq_hz = 20000000;   // no underscores
  camera_config.pixel_format = PIXFORMAT_JPEG;


  // ——— Choose frame size / quality based on PSRAM ———
  if (psramFound()) {
    camera_config.frame_size   = FRAMESIZE_UXGA;
    camera_config.jpeg_quality = 10;
    camera_config.fb_count     = 2;
  } else {
    camera_config.frame_size   = FRAMESIZE_SVGA;
    camera_config.jpeg_quality = 12;
    camera_config.fb_count     = 1;
  }


  // ——— Init camera ———
  Serial.println("→ Initializing camera...");
  esp_err_t err = esp_camera_init(&camera_config);
  if (err != ESP_OK) {
    Serial.printf("‼ Camera init failed: 0x%x\n", err);
    while (true) { delay(1000); }
  }
  Serial.println("✓ Camera initialized");


  // ——— Mount SD card ———
  Serial.println("→ Mounting SD card...");
  if (!SD_MMC.begin()) {
    Serial.println("‼ SD_MMC.begin() failed");
    while (true) { delay(1000); }
  }
  if (SD_MMC.cardType() == CARD_NONE) {
    Serial.println("‼ No SD card attached");
    while (true) { delay(1000); }
  }
  Serial.printf("✓ SD mounted, type=%d\n", SD_MMC.cardType());
}


void loop() {
  static uint16_t counter = 0;
  counter++;


  // ——— Capture frame ———
  camera_fb_t* fb = esp_camera_fb_get();
  if (!fb) {
    Serial.println("‼ Frame capture failed");
    delay(2000);
    return;
  }


  // ——— Build filename ———
  char filename[32];
  snprintf(filename, sizeof(filename), "/photo%03u.jpg", counter);


  // ——— Save to SD ———
  File file = SD_MMC.open(filename, FILE_WRITE);
  if (!file) {
    Serial.printf("‼ Failed to open %s for writing\n", filename);
  } else {
    file.write(fb->buf, fb->len);
    Serial.printf("✓ Saved %s (%u bytes)\n", filename, fb->len);
    file.close();
  }


  // ——— Return the frame buffer ———
  esp_camera_fb_return(fb);


  // Wait 10 s before next capture
  delay(10000);
}

Use a microSD card and a board/pin configuration compatible with the AI-Thinker ESP32-CAM. Camera and SD pins are not freely available as general GPIO while those peripherals are in use.

For current ESP32-CAM software support, see the official Espressif esp32-camera repository.

Thank you for your loyalty!

EN