Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "esp_camera.h"
- #include <WiFi.h>
- // Pilih model kamera yang sesuai
- #define CAMERA_MODEL_AI_THINKER // ESP32-CAM AI-THINKER dengan OV2640
- #include "camera_pins.h"
- // WiFi credentials
- const char* ssid = "Megabot";
- const char* password = "1234567890";
- void startCameraServer();
- void setup() {
- Serial.begin(115200);
- Serial.setDebugOutput(true);
- Serial.println();
- // Konfigurasi kamera
- camera_config_t config;
- config.ledc_channel = LEDC_CHANNEL_0;
- config.ledc_timer = LEDC_TIMER_0;
- config.pin_d0 = Y2_GPIO_NUM;
- config.pin_d1 = Y3_GPIO_NUM;
- config.pin_d2 = Y4_GPIO_NUM;
- config.pin_d3 = Y5_GPIO_NUM;
- config.pin_d4 = Y6_GPIO_NUM;
- config.pin_d5 = Y7_GPIO_NUM;
- config.pin_d6 = Y8_GPIO_NUM;
- config.pin_d7 = Y9_GPIO_NUM;
- config.pin_xclk = XCLK_GPIO_NUM;
- config.pin_pclk = PCLK_GPIO_NUM;
- config.pin_vsync = VSYNC_GPIO_NUM;
- config.pin_href = HREF_GPIO_NUM;
- config.pin_sccb_sda = SIOD_GPIO_NUM;
- config.pin_sccb_scl = SIOC_GPIO_NUM;
- config.pin_pwdn = PWDN_GPIO_NUM;
- config.pin_reset = RESET_GPIO_NUM;
- config.xclk_freq_hz = 20000000;
- // config.pixel_format = PIXFORMAT_JPEG;
- config.pixel_format = PIXFORMAT_RGB565;
- config.frame_size = FRAMESIZE_QVGA; // Resolusi lebih rendah untuk stabilitas awal
- config.jpeg_quality = 10; // 10 = kualitas medium, 12 = lebih tinggi
- config.fb_count = 1;
- // Inisialisasi kamera
- esp_err_t err = esp_camera_init(&config);
- if (err != ESP_OK) {
- Serial.printf("❌ Kamera gagal diinisialisasi, error 0x%x\n", err);
- return;
- }
- // Konfigurasi sensor kamera
- sensor_t *s = esp_camera_sensor_get();
- if (s->id.PID == OV3660_PID) {
- s->set_vflip(s, 1); // Flip vertikal
- s->set_brightness(s, 1); // Tambah kecerahan
- s->set_saturation(s, -2); // Kurangi saturasi warna
- }
- // Setup WiFi
- WiFi.begin(ssid, password);
- WiFi.setSleep(false);
- Serial.print("Menghubungkan ke WiFi");
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("\n✅ WiFi Terhubung!");
- // Jalankan server kamera
- startCameraServer();
- Serial.print("📷 Kamera Siap! Buka: http://");
- Serial.print(WiFi.localIP());
- Serial.println("/");
- }
- void loop() {
- delay(10000); // Loop tidak perlu melakukan apa-apa, server berjalan sendiri
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement