Proximity Camera Board Design
Project SpecificationDesign Notes: ESP32-S3 Proximity CameraFirmware Starter — ESP32-S3 Proximity CameraVBUS currently feeds a PAM2305 fixed 3.3 V buck regulator, which powers the ESP32-S3, camera, and VCNL4040 on 3V3.3V3 railLast modified 5mo ago
Table
| Function | ESP32-S3 GPIO | Net / Device |
|---|---|---|
| USB D- | GPIO19 | USB_DN |
| USB D+ | GPIO20 | USB_DP |
| I2C/SCCB SDA | GPIO4 | I2C_SDA to VCNL4040 SDA and OV2640 SIOD |
| I2C/SCCB SCL | GPIO5 | I2C_SCL to VCNL4040 SCL and OV2640 SIOC |
| VCNL4040 INT | GPIO21 | PROX_INT |
| Camera XCLK | GPIO15 | CAM_XCLK |
| Camera PCLK | GPIO13 | CAM_PCLK |
| Camera VSYNC | GPIO6 | CAM_VSYNC |
| Camera HREF | GPIO7 | CAM_HREF |
| Camera D0..D7 | GPIO11,9,8,10,12,18,17,16 | CAM_D0..CAM_D7 |
| Camera RESET | GPIO48 | CAM_RESET |
| Camera PWDN | GPIO47 | CAM_PWDN |
| BOOT | GPIO0 | BOOT button to GND |
| EN | EN | reset pull-up/filter/button |
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
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); }
Bash
pio run pio run -t upload pio device monitor
Platform & Toolchain
Pin Mapping
platformio.ini
src/main.cpp
Build & Flash