Community project

HD EVP Camera Recorder

Photo of HD EVP Camera Recorder
Generated with AI

Jessie Jackson

Published December 5, 2026

This project builds a video and audio recorder using an ESP32 microcontroller with camera and microphone inputs. Video frames are compressed as MJPEG and audio is captured at 16 kHz, with both streams written to an AVI container file on an SD card for playback on standard media players.

The guide provides a complete parts list, wiring diagram for connecting the camera module and audio input to the ESP32, assembly instructions for the Sense board, and the firmware needed to capture and encode video and audio simultaneously. Builders will have a standalone recorder capable of creating standard video files without requiring a computer.

Wiring diagram

Loading diagram…

Assemble it in 2 steps

1. Assemble the Sense board

With USB unplugged, seat the Sense expansion board with its camera attached on the matching connector on the XIAO.

2. Insert the memory card

Insert a FAT32-formatted microSD card, 32 GB or smaller, into the Sense expansion board before connecting USB power.

Deploy the firmware

#include <Arduino.h>
#include <SPI.h>
#include <SD.h>
#include <esp_camera.h>
#include <driver/i2s.h>
#include <atomic>
static File avi, wav;
static uint32_t frames, samples, movi, avih, strh;
static bool ioError;
static std::atomic<bool> recording{false}, audioError{false};
static SemaphoreHandle_t done;
static void put(File &f,const void *p,size_t n){if(f.write((const uint8_t*)p,n)!=n) ioError=true;}
static void tag(File &f,const char *s){put(f,s,4);}
static void u32(File &f,uint32_t v){put(f,&v,4);}
static void u16(File &f,uint16_t v){put(f,&v,2);}
static void patch(File &f,uint32_t p,uint32_t v){auto end=f.position(); if(!f.seek(p)) ioError=true; u32(f,v); if(!f.seek(end)) ioError=true;}
static void wavHeader(){
  tag(wav,"RIFF");u32(wav,36);tag(wav,"WAVE");tag(wav,"fmt ");u32(wav,16);
  u16(wav,1);u16(wav,1);u32(wav,16000);u32(wav,32000);u16(wav,2);u16(wav,16);
  tag(wav,"data");u32(wav,0);
}
static void aviHeader(){
  tag(avi,"RIFF");u32(avi,0);tag(avi,"AVI ");tag(avi,"LIST");u32(avi,192);tag(avi,"hdrl");
  tag(avi,"avih");u32(avi,56);avih=avi.position();
  const uint32_t mainh[]={200000,0,0,0,0,0,1,0,1280,720,0,0,0,0};put(avi,mainh,sizeof(mainh));
  tag(avi,"LIST");u32(avi,116);tag(avi,"strl");tag(avi,"strh");u32(avi,56);strh=avi.position();
  tag(avi,"vids");tag(avi,"MJPG");
  const uint32_t stream[]={0,0,0,1,5,0,0,0,0xffffffff,0};put(avi,stream,sizeof(stream));
  u16(avi,0);u16(avi,0);u16(avi,1280);u16(avi,720);
  tag(avi,"strf");u32(avi,40);u32(avi,40);u32(avi,1280);u32(avi,720);u16(avi,1);u16(avi,24);
  tag(avi,"MJPG");u32(avi,1280*720*3);for(int i=0;i<4;i++)u32(avi,0);
  tag(avi,"LIST");movi=avi.position();u32(avi,0);tag(avi,"movi");
}
static void audio(void*){
  int16_t buf[512];
  while(recording){
    size_t n=0;
    if(i2s_read(I2S_NUM_0,buf,sizeof(buf),&n,pdMS_TO_TICKS(100))!=ESP_OK || !n){audioError=true;break;}
    if(wav.write((uint8_t*)buf,n)!=n){audioError=true;break;} samples+=n/2;
  }
  xSemaphoreGive(done);vTaskDelete(nullptr);
}
static bool mic(){
  i2s_config_t c={};c.mode=(i2s_mode_t)(I2S_MODE_MASTER|I2S_MODE_RX|I2S_MODE_PDM);
  c.sample_rate=16000;c.bits_per_sample=I2S_BITS_PER_SAMPLE_16BIT;c.channel_format=I2S_CHANNEL_FMT_ONLY_LEFT;
  c.communication_format=I2S_COMM_FORMAT_STAND_I2S;c.dma_buf_count=12;c.dma_buf_len=512;
  i2s_pin_config_t p={};p.mck_io_num=-1;p.bck_io_num=-1;p.ws_io_num=42;p.data_out_num=-1;p.data_in_num=41;
  // ESP32-S3 hardware PDM-to-PCM conversion is on I2S port 0.
  return i2s_driver_install(I2S_NUM_0,&c,0,nullptr)==ESP_OK && i2s_set_pin(I2S_NUM_0,&p)==ESP_OK && i2s_stop(I2S_NUM_0)==ESP_OK;
}
static bool ready;
void setup(){
  Serial.begin(115200);
  SPI.begin(7,8,9,21);
  if(!SD.begin(21,SPI,20000000)){Serial.println("Insert a FAT32 card and reset.");return;}
  camera_config_t c={};c.pin_pwdn=c.pin_reset=-1;c.pin_xclk=10;c.pin_sccb_sda=40;c.pin_sccb_scl=39;
  c.pin_d0=15;c.pin_d1=17;c.pin_d2=18;c.pin_d3=16;c.pin_d4=14;c.pin_d5=12;c.pin_d6=11;c.pin_d7=48;
  c.pin_vsync=38;c.pin_href=47;c.pin_pclk=13;c.xclk_freq_hz=20000000;c.ledc_timer=LEDC_TIMER_0;c.ledc_channel=LEDC_CHANNEL_0;
  c.pixel_format=PIXFORMAT_JPEG;c.frame_size=FRAMESIZE_HD;c.jpeg_quality=15;c.fb_count=2;
  c.fb_location=CAMERA_FB_IN_PSRAM;c.grab_mode=CAMERA_GRAB_LATEST;
  if(!psramFound() || esp_camera_init(&c)!=ESP_OK || !mic()){Serial.println("Camera/PSRAM or microphone init failed.");return;}
  done=xSemaphoreCreateBinary();ready=done!=nullptr;
  Serial.println("Send r to record; send s to stop, or wait 30 seconds.");
}
static void record(){
  char ap[24],wp[24];unsigned id=1;
  for(;id<10000;id++){
    snprintf(ap,sizeof(ap),"/EVP%04u.avi",id);snprintf(wp,sizeof(wp),"/EVP%04u.wav",id);
    if(!SD.exists(ap)&&!SD.exists(wp))break;
  }
  if(id==10000){Serial.println("No free file names."); return;}
  avi=SD.open(ap,FILE_WRITE);wav=SD.open(wp,FILE_WRITE);
  if(!avi || !wav){avi.close();wav.close();Serial.println("Cannot open files.");return;}
  ioError=false;audioError=false;frames=samples=0;aviHeader();wavHeader();
  Serial.printf("Recording %s and %s\n",ap,wp);
  recording=true;
  if(i2s_start(I2S_NUM_0)!=ESP_OK || xTaskCreate(audio,"pcm",4096,nullptr,3,nullptr)!=pdPASS){
    recording=false;i2s_stop(I2S_NUM_0);avi.close();wav.close();SD.remove(ap);SD.remove(wp);
    Serial.println("Could not start audio.");return;
  }
  uint32_t start=millis(), next=0;
  while(!ioError && !audioError){
    if(Serial.available() && Serial.read()=='s')break;
    uint32_t elapsed=millis()-start;
    if(elapsed>=30000)break;
    if(elapsed<next){delay(2);continue;}
    camera_fb_t *fb=esp_camera_fb_get();
    if(!fb){ioError=true;break;}
    if(fb->width!=1280 || fb->height!=720){esp_camera_fb_return(fb);ioError=true;break;}
    tag(avi,"00dc");u32(avi,fb->len);put(avi,fb->buf,fb->len);
    if(fb->len&1){uint8_t zero=0;put(avi,&zero,1);}
    esp_camera_fb_return(fb);frames++;next=elapsed+200;
  }
  recording=false;xSemaphoreTake(done,portMAX_DELAY);i2s_stop(I2S_NUM_0);
  patch(wav,4,36+samples*2);patch(wav,40,samples*2);
  uint32_t end=avi.position();patch(avi,4,end-8);patch(avi,movi,end-movi-4);
  patch(avi,avih+16,frames);patch(avi,strh+32,frames);
  if(frames && samples){
    patch(avi,avih,(uint64_t)samples*1000000/16000/frames);
    patch(avi,strh+20,samples);patch(avi,strh+24,frames*16000);
  }
  avi.close();wav.close();
  Serial.printf("%s: %lu frames, %lu samples. Card can be removed after unplugging USB.\n",
     (ioError||audioError||!frames||!samples)?"Incomplete recording":"Saved",(unsigned long)frames,(unsigned long)samples);
}
void loop(){if(ready && Serial.available() && Serial.read()=='r')record();delay(10);}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik