Proximity Camera Board Design


Designed and wired the schematic for ESP32-S3 Proximity Camera: ESP32-S3 compute, OV2640 camera, VCNL4040 proximity sensor, USB-C input, ESD protection, 3.3 V buck power rail, boot/reset controls, and required passives.
ERC is clean with zero open errors/warnings. I also created project files for the spec, design notes/power budget, and firmware starter:
  • Project Specification
  • Design Notes: ESP32-S3 Proximity Camera
  • Firmware Starter — ESP32-S3 Proximity Camera
Next step is PCB layout: board sizing, component placement, antenna/camera/proximity placement constraints, then routing after placement approval.
Add a LiPo battery charger so the board can run without USB power.
I’ll add a single-cell LiPo power path: USB-C charges the battery, the board can run from battery when USB is absent, and the existing 3.3 V rail will be updated so it can accept the battery source safely. I’ll size it against the existing ESP32/camera peak load, then wire and re-run ERC.
I started the LiPo battery upgrade and inspected the existing power path: USB-C VBUS currently feeds a PAM2305 fixed 3.3 V buck regulator, which powers the ESP32-S3, camera, and VCNL4040 on 3V3.
Important finding: a single-cell LiPo ranges about 4.2 V down to ~3.0 V, so the current buck-only 3.3 V regulator is not ideal for full battery operation. The right architecture is:
  • USB-C 5 V → single-cell LiPo charger / power-path IC
  • LiPo battery connector → charger BAT pin
  • charger SYS/output → 3.3 V buck-boost regulator
  • buck-boost output → existing 3V3 rail
I was blocked by project credits before I could add parts or wire the schematic. Remaining work:
  1. Select charger/power-path IC, likely BQ24074/MCP73871-class.
  2. Select 3.3 V buck-boost regulator rated for ESP32-S3 + camera peak current.
  3. Add JST LiPo connector, charger passives, battery thermistor/program resistor as required.
  4. Replace or bypass the existing PAM2305 buck with the buck-boost stage.
  5. Update power-budget notes and rerun ERC to zero unresolved violations.
Use BQ24074
Compare charger ICs
Find battery connector
Calculate peak current
Document power architecture

Last modified 5mo ago

Firmware Starter — ESP32-S3 Proximity Camera
Platform & Toolchain
  • MCU: ESP32-S3-WROOM-1-N16R8
  • Framework: Arduino via PlatformIO
  • Behavior: read VCNL4040 proximity sensor over I2C, require a continuous near condition for 3 seconds, capture a frame from OV2640, and HTTP POST the JPEG to a server.
Pin Mapping

Table


FunctionESP32-S3 GPIONet / Device
USB D-GPIO19USB_DN
USB D+GPIO20USB_DP
I2C/SCCB SDAGPIO4I2C_SDA to VCNL4040 SDA and OV2640 SIOD
I2C/SCCB SCLGPIO5I2C_SCL to VCNL4040 SCL and OV2640 SIOC
VCNL4040 INTGPIO21PROX_INT
Camera XCLKGPIO15CAM_XCLK
Camera PCLKGPIO13CAM_PCLK
Camera VSYNCGPIO6CAM_VSYNC
Camera HREFGPIO7CAM_HREF
Camera D0..D7GPIO11,9,8,10,12,18,17,16CAM_D0..CAM_D7
Camera RESETGPIO48CAM_RESET
Camera PWDNGPIO47CAM_PWDN
BOOTGPIO0BOOT button to GND
ENENreset pull-up/filter/button
platformio.ini

Ini


[env:esp32-s3-devkitc-1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
monitor_speed = 115200
build_flags =
    -DARDUINO_USB_MODE=1
    -DARDUINO_USB_CDC_ON_BOOT=1
lib_deps =
    espressif/esp32-camera
src/main.cpp

Cpp


#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include "esp_camera.h"

#define WIFI_SSID       "YOUR_WIFI_SSID"
#define WIFI_PASSWORD   "YOUR_WIFI_PASSWORD"
#define UPLOAD_URL      "https://example.com/upload"

#define I2C_SDA_PIN     4
#define I2C_SCL_PIN     5
#define PROX_INT_PIN    21

#define CAM_XCLK_PIN    15
#define CAM_PCLK_PIN    13
#define CAM_VSYNC_PIN   6
#define CAM_HREF_PIN    7
#define CAM_D0_PIN      11
#define CAM_D1_PIN      9
#define CAM_D2_PIN      8
#define CAM_D3_PIN      10
#define CAM_D4_PIN      12
#define CAM_D5_PIN      18
#define CAM_D6_PIN      17
#define CAM_D7_PIN      16
#define CAM_RESET_PIN   48
#define CAM_PWDN_PIN    47

#define VCNL4040_ADDR   0x60
#define HOLD_TIME_MS    3000UL
#define NEAR_THRESHOLD  1200

static unsigned long nearStartMs = 0;
static bool imageSentForThisHold = false;

uint16_t vcnlRead16(uint8_t reg) {
  Wire.beginTransmission(VCNL4040_ADDR);
  Wire.write(reg);
  if (Wire.endTransmission(false) != 0) return 0;
  if (Wire.requestFrom(VCNL4040_ADDR, (uint8_t)2) != 2) return 0;
  uint8_t lo = Wire.read();
  uint8_t hi = Wire.read();
  return (uint16_t)hi << 8 | lo;
}

void vcnlWrite16(uint8_t reg, uint16_t value) {
  Wire.beginTransmission(VCNL4040_ADDR);
  Wire.write(reg);
  Wire.write(value & 0xFF);
  Wire.write(value >> 8);
  Wire.endTransmission();
}

void initVCNL4040() {
  Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN, 400000);
  pinMode(PROX_INT_PIN, INPUT_PULLUP);
  vcnlWrite16(0x03, 0x0800); // PS 16-bit mode, interrupt disabled for polling fallback
  vcnlWrite16(0x04, 0x0000); // proximity normal mode, 50 mA IRED current
}

bool isNear() {
  uint16_t ps = vcnlRead16(0x08);
  return ps > NEAR_THRESHOLD || digitalRead(PROX_INT_PIN) == LOW;
}

void initCamera() {
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = CAM_D0_PIN;
  config.pin_d1 = CAM_D1_PIN;
  config.pin_d2 = CAM_D2_PIN;
  config.pin_d3 = CAM_D3_PIN;
  config.pin_d4 = CAM_D4_PIN;
  config.pin_d5 = CAM_D5_PIN;
  config.pin_d6 = CAM_D6_PIN;
  config.pin_d7 = CAM_D7_PIN;
  config.pin_xclk = CAM_XCLK_PIN;
  config.pin_pclk = CAM_PCLK_PIN;
  config.pin_vsync = CAM_VSYNC_PIN;
  config.pin_href = CAM_HREF_PIN;
  config.pin_sccb_sda = I2C_SDA_PIN;
  config.pin_sccb_scl = I2C_SCL_PIN;
  config.pin_pwdn = CAM_PWDN_PIN;
  config.pin_reset = CAM_RESET_PIN;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;
  config.frame_size = FRAMESIZE_VGA;
  config.jpeg_quality = 12;
  config.fb_count = 1;
  config.fb_location = CAMERA_FB_IN_PSRAM;
  config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;

  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed: 0x%x\n", err);
  }
}

void connectWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Connecting WiFi");
  for (int i = 0; i < 40 && WiFi.status() != WL_CONNECTED; i++) {
    delay(250);
    Serial.print('.');
  }
  Serial.println(WiFi.status() == WL_CONNECTED ? " connected" : " failed");
}

bool uploadImage(camera_fb_t *fb) {
  if (!fb || WiFi.status() != WL_CONNECTED) return false;
  HTTPClient http;
  http.begin(UPLOAD_URL);
  http.addHeader("Content-Type", "image/jpeg");
  int code = http.POST(fb->buf, fb->len);
  http.end();
  Serial.printf("Upload HTTP code: %d\n", code);
  return code >= 200 && code < 300;
}

void captureAndUpload() {
  camera_fb_t *fb = esp_camera_fb_get();
  if (!fb) {
    Serial.println("Camera capture failed");
    return;
  }
  uploadImage(fb);
  esp_camera_fb_return(fb);
}

void setup() {
  Serial.begin(115200);
  delay(1000);
  initVCNL4040();
  initCamera();
  connectWiFi();
  Serial.println("Ready: hold an object/person near sensor for 3 seconds.");
}

void loop() {
  if (WiFi.status() != WL_CONNECTED) connectWiFi();

  bool near = isNear();
  unsigned long now = millis();
  if (near) {
    if (nearStartMs == 0) nearStartMs = now;
    if (!imageSentForThisHold && now - nearStartMs >= HOLD_TIME_MS) {
      captureAndUpload();
      imageSentForThisHold = true;
    }
  } else {
    nearStartMs = 0;
    imageSentForThisHold = false;
  }
  delay(50);
}
Build & Flash

Bash


pio run
pio run -t upload
pio device monitor
Use the BOOT button while tapping RESET if the board does not automatically enter the bootloader.
  • Platform & Toolchain

  • Pin Mapping

  • platformio.ini

  • src/main.cpp

  • Build & Flash