Components and supplies
1
esp32-cam
1
Arduino Nano R3
Apps and platforms
1
Arduino IDE
Project description
Code
CameraWebServer.ino
c_cpp
1#include "esp_camera.h" 2#include <WiFi.h> 3 4// 5// WARNING!!! Make sure that you have either selected ESP32 Wrover Module, 6// or another board which has PSRAM enabled 7// 8 9// Select camera model 10//#define CAMERA_MODEL_WROVER_KIT 11//#define CAMERA_MODEL_ESP_EYE 12//#define CAMERA_MODEL_M5STACK_PSRAM 13//#define CAMERA_MODEL_M5STACK_WIDE 14#define CAMERA_MODEL_AI_THINKER 15 16#include "camera_pins.h" 17 18const char* ssid = "PM.GOHARIAN"; 19const char* password = "*******"; 20 21void startCameraServer(); 22 23void setup() { 24 Serial.begin(115200); 25 Serial.setDebugOutput(true); 26 Serial.println(); 27 28 camera_config_t config; 29 config.ledc_channel = LEDC_CHANNEL_0; 30 config.ledc_timer = LEDC_TIMER_0; 31 config.pin_d0 = Y2_GPIO_NUM; 32 config.pin_d1 = Y3_GPIO_NUM; 33 config.pin_d2 = Y4_GPIO_NUM; 34 config.pin_d3 = Y5_GPIO_NUM; 35 config.pin_d4 = Y6_GPIO_NUM; 36 config.pin_d5 = Y7_GPIO_NUM; 37 config.pin_d6 = Y8_GPIO_NUM; 38 config.pin_d7 = Y9_GPIO_NUM; 39 config.pin_xclk = XCLK_GPIO_NUM; 40 config.pin_pclk = PCLK_GPIO_NUM; 41 config.pin_vsync = VSYNC_GPIO_NUM; 42 config.pin_href = HREF_GPIO_NUM; 43 config.pin_sscb_sda = SIOD_GPIO_NUM; 44 config.pin_sscb_scl = SIOC_GPIO_NUM; 45 config.pin_pwdn = PWDN_GPIO_NUM; 46 config.pin_reset = RESET_GPIO_NUM; 47 config.xclk_freq_hz = 20000000; 48 config.pixel_format = PIXFORMAT_JPEG; 49 //init with high specs to pre-allocate larger buffers 50 if(psramFound()){ 51 config.frame_size = FRAMESIZE_UXGA; 52 config.jpeg_quality = 10; 53 config.fb_count = 2; 54 } else { 55 config.frame_size = FRAMESIZE_SVGA; 56 config.jpeg_quality = 12; 57 config.fb_count = 1; 58 } 59 60#if defined(CAMERA_MODEL_ESP_EYE) 61 pinMode(13, INPUT_PULLUP); 62 pinMode(14, INPUT_PULLUP); 63#endif 64 65 // camera init 66 esp_err_t err = esp_camera_init(&config); 67 if (err != ESP_OK) { 68 Serial.printf("Camera init failed with error 0x%x", err); 69 return; 70 } 71 72 sensor_t * s = esp_camera_sensor_get(); 73 //initial sensors are flipped vertically and colors are a bit saturated 74 if (s->id.PID == OV3660_PID) { 75 s->set_vflip(s, 1);//flip it back 76 s->set_brightness(s, 1);//up the blightness just a bit 77 s->set_saturation(s, -2);//lower the saturation 78 } 79 //drop down frame size for higher initial frame rate 80 s->set_framesize(s, FRAMESIZE_QVGA); 81 82#if defined(CAMERA_MODEL_M5STACK_WIDE) 83 s->set_vflip(s, 1); 84 s->set_hmirror(s, 1); 85#endif 86 87 WiFi.begin(ssid, password); 88 89 while (WiFi.status() != WL_CONNECTED) { 90 delay(500); 91 Serial.print("."); 92 } 93 Serial.println(""); 94 Serial.println("WiFi connected"); 95 96 startCameraServer(); 97 98 Serial.print("Camera Ready! Use 'http://"); 99 Serial.print(WiFi.localIP()); 100 Serial.println("' to connect"); 101} 102 103void loop() { 104 // put your main code here, to run repeatedly: 105 delay(10000); 106} 107
Downloadable files
circuit_xbSBpsDg3U.jpg
circuit_xbSBpsDg3U.jpg

circuit_xbSBpsDg3U.jpg
circuit_xbSBpsDg3U.jpg

Comments
Only logged in users can leave comments