ESP32-CAM Video Streaming Web Server (works with Home Assistant)

In this project we’re going to build an IP surveillance camera with the ESP32-CAM board. The ESP32 camera is going to host a video streaming web server that you can access with any device in your network.

You can integrate this video streaming web server with popular home automation platforms like Home Assistant or Node-RED. In this tutorial, we’ll show you how to integrate it with Home Assistant and Node-RED.

Watch the Video Tutorial

You can watch the video tutorial or keep reading this page for the written instructions.

Parts Required

To follow this tutorial you need the following components:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Introducing the ESP32-CAM

The ESP32-CAM is a very small camera module with the ESP32-S chip that costs less than $10. You can read our getting started guide for the ESP32-CAM and learn how to use the Video Streaming and Face Recognition example.

Video Streaming Server

Follow the next steps to build a video streaming web server with the ESP32-CAM that you can access on your local network. 

1. Install the ESP32 add-on

In this example, we use Arduino IDE to program the ESP32-CAM board. So, you need to have Arduino IDE installed as well as the ESP32 add-on. Follow one of the next tutorials to install the ESP32 add-on, if you haven’t already:

2. Video Streaming Web Server Code

After that, copy the code below to your Arduino IDE.

/*********
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com
  
  IMPORTANT!!! 
   - Select Board "ESP32 Wrover Module"
   - Select the Partion Scheme "Huge APP (3MB No OTA)
   - GPIO 0 must be connected to GND to upload a sketch
   - After connecting GPIO 0 to GND, press the ESP32-CAM on-board RESET button to put your board in flashing mode
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*********/

#include "esp_camera.h"
#include <WiFi.h>
#include "esp_timer.h"
#include "img_converters.h"
#include "Arduino.h"
#include "fb_gfx.h"
#include "soc/soc.h" //disable brownout problems
#include "soc/rtc_cntl_reg.h"  //disable brownout problems
#include "dl_lib.h"
#include "esp_http_server.h"

//Replace with your network credentials
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

#define PART_BOUNDARY "123456789000000000000987654321"

// This project was tested with the AI Thinker Model, M5STACK PSRAM Model and M5STACK WITHOUT PSRAM
#define CAMERA_MODEL_AI_THINKER
//#define CAMERA_MODEL_M5STACK_PSRAM
//#define CAMERA_MODEL_M5STACK_WITHOUT_PSRAM

// Not tested with this model
//#define CAMERA_MODEL_WROVER_KIT

#if defined(CAMERA_MODEL_WROVER_KIT)
  #define PWDN_GPIO_NUM    -1
  #define RESET_GPIO_NUM   -1
  #define XCLK_GPIO_NUM    21
  #define SIOD_GPIO_NUM    26
  #define SIOC_GPIO_NUM    27
  
  #define Y9_GPIO_NUM      35
  #define Y8_GPIO_NUM      34
  #define Y7_GPIO_NUM      39
  #define Y6_GPIO_NUM      36
  #define Y5_GPIO_NUM      19
  #define Y4_GPIO_NUM      18
  #define Y3_GPIO_NUM       5
  #define Y2_GPIO_NUM       4
  #define VSYNC_GPIO_NUM   25
  #define HREF_GPIO_NUM    23
  #define PCLK_GPIO_NUM    22

#elif defined(CAMERA_MODEL_M5STACK_PSRAM)
  #define PWDN_GPIO_NUM     -1
  #define RESET_GPIO_NUM    15
  #define XCLK_GPIO_NUM     27
  #define SIOD_GPIO_NUM     25
  #define SIOC_GPIO_NUM     23
  
  #define Y9_GPIO_NUM       19
  #define Y8_GPIO_NUM       36
  #define Y7_GPIO_NUM       18
  #define Y6_GPIO_NUM       39
  #define Y5_GPIO_NUM        5
  #define Y4_GPIO_NUM       34
  #define Y3_GPIO_NUM       35
  #define Y2_GPIO_NUM       32
  #define VSYNC_GPIO_NUM    22
  #define HREF_GPIO_NUM     26
  #define PCLK_GPIO_NUM     21

#elif defined(CAMERA_MODEL_M5STACK_WITHOUT_PSRAM)
  #define PWDN_GPIO_NUM     -1
  #define RESET_GPIO_NUM    15
  #define XCLK_GPIO_NUM     27
  #define SIOD_GPIO_NUM     25
  #define SIOC_GPIO_NUM     23
  
  #define Y9_GPIO_NUM       19
  #define Y8_GPIO_NUM       36
  #define Y7_GPIO_NUM       18
  #define Y6_GPIO_NUM       39
  #define Y5_GPIO_NUM        5
  #define Y4_GPIO_NUM       34
  #define Y3_GPIO_NUM       35
  #define Y2_GPIO_NUM       17
  #define VSYNC_GPIO_NUM    22
  #define HREF_GPIO_NUM     26
  #define PCLK_GPIO_NUM     21

#elif defined(CAMERA_MODEL_AI_THINKER)
  #define PWDN_GPIO_NUM     32
  #define RESET_GPIO_NUM    -1
  #define XCLK_GPIO_NUM      0
  #define SIOD_GPIO_NUM     26
  #define SIOC_GPIO_NUM     27
  
  #define Y9_GPIO_NUM       35
  #define Y8_GPIO_NUM       34
  #define Y7_GPIO_NUM       39
  #define Y6_GPIO_NUM       36
  #define Y5_GPIO_NUM       21
  #define Y4_GPIO_NUM       19
  #define Y3_GPIO_NUM       18
  #define Y2_GPIO_NUM        5
  #define VSYNC_GPIO_NUM    25
  #define HREF_GPIO_NUM     23
  #define PCLK_GPIO_NUM     22
#else
  #error "Camera model not selected"
#endif

static const char* _STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary=" PART_BOUNDARY;
static const char* _STREAM_BOUNDARY = "\r\n--" PART_BOUNDARY "\r\n";
static const char* _STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %u\r\n\r\n";

httpd_handle_t stream_httpd = NULL;

static esp_err_t stream_handler(httpd_req_t *req){
  camera_fb_t * fb = NULL;
  esp_err_t res = ESP_OK;
  size_t _jpg_buf_len = 0;
  uint8_t * _jpg_buf = NULL;
  char * part_buf[64];

  res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE);
  if(res != ESP_OK){
    return res;
  }

  while(true){
    fb = esp_camera_fb_get();
    if (!fb) {
      Serial.println("Camera capture failed");
      res = ESP_FAIL;
    } else {
      if(fb->width > 400){
        if(fb->format != PIXFORMAT_JPEG){
          bool jpeg_converted = frame2jpg(fb, 80, &_jpg_buf, &_jpg_buf_len);
          esp_camera_fb_return(fb);
          fb = NULL;
          if(!jpeg_converted){
            Serial.println("JPEG compression failed");
            res = ESP_FAIL;
          }
        } else {
          _jpg_buf_len = fb->len;
          _jpg_buf = fb->buf;
        }
      }
    }
    if(res == ESP_OK){
      size_t hlen = snprintf((char *)part_buf, 64, _STREAM_PART, _jpg_buf_len);
      res = httpd_resp_send_chunk(req, (const char *)part_buf, hlen);
    }
    if(res == ESP_OK){
      res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len);
    }
    if(res == ESP_OK){
      res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY));
    }
    if(fb){
      esp_camera_fb_return(fb);
      fb = NULL;
      _jpg_buf = NULL;
    } else if(_jpg_buf){
      free(_jpg_buf);
      _jpg_buf = NULL;
    }
    if(res != ESP_OK){
      break;
    }
    //Serial.printf("MJPG: %uB\n",(uint32_t)(_jpg_buf_len));
  }
  return res;
}

void startCameraServer(){
  httpd_config_t config = HTTPD_DEFAULT_CONFIG();
  config.server_port = 80;

  httpd_uri_t index_uri = {
    .uri       = "/",
    .method    = HTTP_GET,
    .handler   = stream_handler,
    .user_ctx  = NULL
  };
  
  //Serial.printf("Starting web server on port: '%d'\n", config.server_port);
  if (httpd_start(&stream_httpd, &config) == ESP_OK) {
    httpd_register_uri_handler(stream_httpd, &index_uri);
  }
}

void setup() {
  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
 
  Serial.begin(115200);
  Serial.setDebugOutput(false);
  
  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_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_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; 
  
  if(psramFound()){
    config.frame_size = FRAMESIZE_UXGA;
    config.jpeg_quality = 10;
    config.fb_count = 2;
  } else {
    config.frame_size = FRAMESIZE_SVGA;
    config.jpeg_quality = 12;
    config.fb_count = 1;
  }
  
  // Camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    return;
  }
  // Wi-Fi connection
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  Serial.print("Camera Stream Ready! Go to: http://");
  Serial.print(WiFi.localIP());
  
  // Start streaming web server
  startCameraServer();
}

void loop() {
  delay(1);
}

View raw code

Before uploading the code, you need to insert your network credentials in the following variables:

const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

Then, make sure you select the right camera module. In this case, we’re using the AI-THINKER Model.

If you’re using the same camera module, you don’t need to change anything on the code.

#define CAMERA_MODEL_AI_THINKER

Now, you can upload the code to your ESP32-CAM board.

3. Uploading the Code

Connect the ESP32-CAM board to your computer using an FTDI programmer. Follow the next schematic diagram:

Important: GPIO 0 needs to be connected to GND so that you’re able to upload code.

To upload the code, follow the next steps:

  • Go to Tools > Board and select ESP32 Wrover Module
  • Go to Tools > Port and select the COM port the ESP32 is connected to
  • In Tools > Partition Scheme, select “Huge APP (3MB No OTA)
  • Press the ESP32-CAM on-board RESET button
  • Then, click the upload button to upload the code.

Important: if you can’t upload the code, double-check that GPIO 0 is connected to GND and that you selected the right settings in the Tools menu. You should also press the on-board Reset button to restart your ESP32 in flashing mode.

Getting the IP address

After uploading the code, disconnect GPIO 0 from GND. Open the Serial Monitor at a baud rate of 115200. Press the ESP32-CAM on-board Reset button.

The ESP32 IP address should be printed in the Serial Monitor.

Accessing the Video Streaming Server

Now, you can access your camera streaming server on your local network. Open a browser and type the ESP32-CAM IP address. A page with the current video streaming should load.

Home Assistant Integration

Having just the ESP32-CAM working via IP might be useful for most people, but you can integrate this project with Home Assistant (or with other home automation platforms). Continue reading to learn how to integrate with Home Assistant.

Prerequisites

Adding ESP32-CAM to Home Assistant

Open your Home Assistant dashboard and go to the more Settings menu.

Open Configure UI:

Add a new card to your Dashboard:

Pick a card of the type Picture.

In the Image URL field, enter your ESP32-CAM IP address. Then, click the “SAVE” button and return to the main dashboard.

If you’re using the configuration file, this is what you need to add.

After that, Home Assistant can display the ESP32-CAM video streaming.

Taking It Further

To take this project further, you can use one fake dummy camera and place the ESP32-CAM inside.

The ESP32-CAM board fits perfectly into the dummy camera enclosure.

You can power it using a 5V power adapter through the ESP32-CAM GND and 5V pins.

Place the surveillance camera in a suitable place.

After that, go to the camera IP address or to your Home Assistant dashboard and see in real time what’s happening. The following image shows us testing the video streaming camera. Sara is taking a screenshot while I’m filming the camera.

It’s impressive what this little $9 ESP32 camera module can do and it’s been working reliably. Now, we can use the surveillance camera to see in real time what’s happening in my front entrance.

Tip: Node-RED Integration

The video streaming web server also integrates with Node-RED and Node-RED Dashboard. You just need to create a Template node and add the following:

<div style="margin-bottom: 10px;">
<img src="https://YOUR-ESP32-CAM-IP-ADDRESS" width="650px">
</div>

In the src attribute, you need to type your ESP32-CAM IP address:

<div style="margin-bottom: 10px;">
<img src="https://192.168.1.91" width="650px">
</div>

Troubleshooting

If you’re getting any of the following errors, read our ESP32-CAM Troubleshooting Guide: Most Common Problems Fixed

  • Failed to connect to ESP32: Timed out waiting for packet header
  • Camera init failed with error 0x20001 or similar
  • Brownout detector or Guru meditation error
  • Sketch too big error – Wrong partition scheme selected
  • Board at COMX is not available – COM Port Not Selected
  • Psram error: GPIO isr service is not installed
  • Weak Wi-Fi Signal
  • No IP Address in Arduino IDE Serial Monitor
  • Can’t open web server
  • The image lags/shows lots of latency

Wrapping Up

In this tutorial we’ve shown you how to build a simple video streaming web server with the ESP32-CAM board to build an IP camera. The web server we’ve built can be easily integrated with your home automation platform like Node-RED or Home Assistant.

We hope you’ve find this tutorial useful. If you don’t have an ESP32-CAM yet, you can grab it here.

If you like this project, you may also like other projects with cameras:

Learn more about ESP32: Learn ESP32 with Arduino IDE (video course and ebook).


Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »


Enjoyed this project? Stay updated by subscribing our weekly newsletter!

122 thoughts on “ESP32-CAM Video Streaming Web Server (works with Home Assistant)”

    • Yes. We intend to integrate this with Node-RED too.
      The face recognition and triggering events might be a bit more difficult. We’ll see…
      Regards,
      Sara

        • Hi.
          Try powering the camera with 5V.
          Some readers reported improvements in wifi signal after powering with 5V.
          Regards,
          Sara

        • Check the jumper 0K resistor by the antenna connector is in the proper position for the antenna desired. There are 3 little white squares laid out like a “<" with the middle position being common. With board turned so the the pcb antenna up, to use the pcb antenna, the resistor must be on the top position, like this: /

          For the antenna connector, the resistor must be on the bottom position, like this: \

  1. I meant completely integrating it in Node-RED – available on the dashboard as a viewable feed, face recognition triggering events, etc.

  2. I’d like to create a battery powered version that uses the ESP32’s deep sleep mode (with motion detection to wake it up) and low battery notifications.

  3. Dear Sir,
    That’s a lovely project.

    However, I’m not getting the some of the header files used in the arduino sketch. They are esp_camera.h, “esp_http_server.h”,
    esp_timer.h,img_converters.h

    Can you please be kind enough to help me getting these header files?

    Thanks in advance..

    Rgds.

    S. Bera

  4. Fantastic! Any suggestions on how to use it to capture video? IE: if it could detect motion with a passive IR added in addition to the ESP32 camera…and that motion could trigger the local PC to record for X minutes, that would be FANTASTIC.

      • Hi Sara,

        Most excellent! I look forward to it. Got several of the boards on the way. I’m thinking that instead of putting the board into a security camera housing, I’m going to mount it to the inside of a window facing to the outside. Should work well and not require any environmental sealing. 🙂

        Thanks much,
        ben

  5. Hi, I wanted to know if it was possible to reduce the latency of the image, and if it were possible to use an ESP8266. Thank you.

  6. Rui,
    My daughter is into Legos and wants me to help her to develop a Lego Sorter.
    How difficult would it be to adapt the face recognition SW to learn to recognize objects?

    Thanks to you and Sara for all the information and work you do to educate people.

    Regards,

    Lloyd

    • Hi Lloyd.
      At the moment, I don’t think it is easy to do that with the ESP32-CAM and arduino IDE. It’s a quite new topic and there aren’t many libraries available to do that.
      There are much more support for object recognition using raspberry pi and its camera at the moment.
      Regards,
      Sara

  7. HI, I’m using this esp32 camera from amazon.com/M5Stack-Camera-Antenna-Arduino-Raspberry/dp/B07DVD4J7N/

    When the code executes this line:
    fb = esp_camera_fb_get();
    it never returns. I’ve place a Serial.println() before and after the line, and the line after never prints out.

    The only camera model setting that passes the camera init and probe is this: CAMERA_MODEL_M5STACK_PSRAM.

    Here are the things that I’ve tried:
    — created OV2640 config : fails camera init and probe
    — changed jpeg_quality making from a Min of 1 to a max of 12
    — Changed fb_count numbers 1-3

    What would you suggest?

    Thanks in advance,

  8. Hello.
    When I try to upload the sketch to the ESP32 CAM an error mesagge shows “Failed to connect to ESP32: Timed out waiting for packet header”.
    I’ve checked the connections, pressed Reset before and during the upload attempt, connected to 3.3v and 5v, used //#define CAMERA_MODEL_WROVER_KIT and #define CAMERA_MODEL_AI_THINKER.
    Please, I’ll be glad to know if you have any suggestions of something else to try.
    Best wishes.

    • Hi Marcelo.
      I’m sorry you’re having trouble with your board.
      Please verify that you have the ESP32 GPIO0 connected to GND during the uploading.
      Also, make sure that in the arduino ide settings, you select Tools > Partition Scheme, select “Huge APP (3MB No OTA)“.
      It this doesn’t work, it is very difficult for me to understand what might be wrong.
      Regards,
      Sara

  9. Wow, what a brilliant, inspiring idea !!!

    Just last week I received some of these camera’s. I ordered them from China some time ago, but it took some time before they were shipped.
    (I guess they are very popular)

    Yesterday I assembled and programmed the ESP-CAM and found out that it works well when you use a powerbank, you can just walk around with it !
    (also found out that you can program the board with a USB-to-TTL module model CP2102 and that the CH340 model does NOT work)
    Then I searched the whole house for my old dummy camera’s..
    and found them today, haha. They are not as easy to use as yours,
    but some are ‘workable’.

    Surprisingly enough, I managed to build my first dummy-ESP-CAM today !
    I use it to watch my front door, it’s battery operated (3xAA-rechargable-2000mAh) and it works very well !
    They is some (a few seconds) time-lag (latency ?) between what happens and it showing up on screen, but other than that the camera works fine and I love that I can see who’s at my front door before I open it !
    Now we will have to learn by experience how long these batteries will last…

    Your explanation was very easy to follow and my ESP-CAM was up and running before I knew it…. getting it into my old dummy-cam was (a lot) more work…

    Thank you again, for another inspiration ! I had a great day building it !

    • Hi Gerrit.
      Thank you so much for your nice words.
      I’m really happy when I see that our readers can actually make our projects and put them working in a real world scenario.
      Then, let me know how long your batteries last.
      Thank you for your interest and enthusiasm in our projects.
      Regards,
      Sara

  10. I ordered the components from Maker Advisor but received an unknown model of the ESP32CAM, with which none of the three camera settings work. Since the serial monitor reports: “[D][esp32-hal-psram.c:47] psramInit(): PSRAM enabled”
    I guessed this must be the M5STACK_PSRAM model, but booting with this setting sends the error message “Camera init failed with error 0x20001”.

    The WROVER_KIT setting als returns these errors: “SCCB_Write [ff]=01 failed; SCCB_Write [12]=80 failed; Camera init failed with error 0x20001”

    And the AI_THINKER setting complains about an illegal instruction, reboots and then gives no more information after the “PSRAM enabled” message.

    Any ideas?

    Pierre

  11. I ordered the components from Maker Advisor but received an unknown model of the ESP32CAM, with which none of the three camera settings work. Since the serial monitor reports: “[D][esp32-hal-psram.c:47] psramInit(): PSRAM enabled”
    I guessed this must be the M5STACK_PSRAM model, but booting with this setting sends the error message “Camera init failed with error 0x20001”.

    The WROVER_KIT setting als returns these errors: “SCCB_Write [ff]=01 failed; SCCB_Write [12]=80 failed; Camera init failed with error 0x20001”

    And the AI_THINKER setting complains about an illegal instruction, reboots and then gives no more information after the “PSRAM enabled” message.

    Any ideas?

    Pierre

    (my earlier message about being unable to flash are obsolete now, they were due to a faulty FT232)

  12. Rui,

    I purchased three ESP32-CAM modules from Banggood with camera.

    I have tried everything I could find on internet to program anything on them. I keep getting “Timed out waiting for packet header” error. Nothing ever get programmed? Even used an external power supply and nothing works.

    These modules do not say “AI-THINKER” on them. Might be a different module but cannot prove it this way.

    Any more ideas:

    Thanks, Joe L.

    • Hi Joseph.
      That error means that your ESP is not in flashing mode.
      Please check that you’ve wire the RX and TX pins properly to the FTDI programmer, and that the ESP32 GPIO0 is connected to GND.
      Regards,
      Sara

      • Sara,

        I have TX going to RX etc. and GPI0 going to gnd. I press boot buton before programming and serial says “waiting for download”. How can I know if ESP32 in flashing mode?

        Tried every mode possible and same result.

        The programmer works ok on other standard ESP32 modules.

        Thanks Joe L.

  13. Hi Rui,

    I purchased two ESP32-CAM modules from Banggood with camera; they are exactly same than yours.
    I tried everything I found on your kind blog to program on them.
    I keep getting ever “Timed out waiting for packet header” error as follows:

    esptool.py v2.6-beta1
    Serial port COM8
    Connecting…….._____….._____….._____….._____….._____….._____….._____

    A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header

    I have TX going to RX etc. and GPI0 going to gnd.
    I pressed boot button before programming.
    Tried every mode possible and same result.
    The programmer works fine on other standard ESP32 modules.

    Any idea Sara/Rui?

    • I purchased my esp32-cam from banggood they do not say Ai-Thinker on them.
      Ihave yet to get it to work but was able to get the program loaded.I was getting the same error as you.In the if you are using Windows in the Control Panel check to make sure you have a good Driver for the COM port you are using try updating the driver.

    • I had exactly the same problem. Used another type of FT232 board (bought on Amazon) and the communication problems were solved. But my ESP32 cam boards from Banggood are also of an unknown type that does not work with the software provided in this article…

    • I had this problem and it was not enough power through USB source I fed +5 to Vcc pin and that fixed it. It was brown out in my case.

    • Hi Domenico.
      That error means that the ESP32 is not in flashing mode.
      You have to follow the exact same instructions we have in our tutorial.
      By what you’re describing, it seems that you’re doing everything right. If you’re doing as we describe in our tutorial and it doesn’t work, I don’t know what can be the problem.

      Also, as Richard said “If you are using Windows in the Control Panel check to make sure you have a good Driver for the COM port you are using try updating the driver.”

      I’m sorry that I can’t help much. Meanwhile, if you find out the problem let us know. We’re planning to write a troubleshooting guide for the ESP32-CAM.
      Regards,
      Sara

          • Hi Sara, the flashing is now Okay; but I got this error ; could be it due to cam related. Right?
            PS: I purchased my esp32-cam from banggood they do not say Ai-Thinker on them, but they are exactly same than yours. Any idea to solve in case not exactly the AI-Thinker camera?

            =========================================
            18:46:14.539 -> configsip: 0, SPIWP:0xee
            18:46:14.539 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
            18:46:14.539 -> mode:DIO, clock div:1
            18:46:14.539 -> load:0x3fff0018,len:4
            18:46:14.539 -> load:0x3fff001c,len:1100
            18:46:14.539 -> load:0x40078000,len:10088
            18:46:14.539 -> load:0x40080400,len:6380
            18:46:14.539 -> entry 0x400806a4
            18:46:16.939 -> Guru Meditation Error: Core 0 panic’ed (LoadProhibited). Exception was unhandled.
            18:46:17.059 -> Core 0 register dump:
            18:46:17.059 -> PC : 0x4014284b PS : 0x00060830 A0 : 0x80140b67 A1 : 0x3ffd3150
            18:46:17.059 -> A2 : 0x3ffc8c08 A3 : 0x401417d8 A4 : 0x00000002 A5 : 0x00000005
            18:46:17.059 -> A6 : 0x0000000b A7 : 0x00000003 A8 : 0x80142845 A9 : 0x3ffd3130
            18:46:17.059 -> A10 : 0x4000446c A11 : 0x400041fc A12 : 0x3ffc8c50 A13 : 0x00000007
            18:46:17.059 -> A14 : 0x3ffae0c0 A15 : 0x00000008 SAR : 0x0000001c EXCCAUSE: 0x0000001c
            18:46:17.059 -> EXCVADDR: 0x00000002 LBEG : 0x4008d664 LEND : 0x4008d67c LCOUNT : 0x00000000
            18:46:17.059 ->
            18:46:17.059 -> Backtrace: 0x4014284b:0x3ffd3150 0x40140b64:0x3ffd3180 0x4014105c:0x3ffd31a0 0x400dd8a6:0x3ffd3260 0x400ddb56:0x3ffd3290 0x40115439:0x3ffd32c0 0x4011553c:0x3ffd32f0 0x4011583e:0x3ffd3320 0x401159b3:0x3ffd3350 0x4008b5c8:0x3ffd3370 0x40091b11:0x3ffd33b0
            18:46:17.059 ->
            18:46:17.059 -> Rebooting…
            18:46:17.059 -> ets Jun 8 2016 00:22:57
            18:46:17.059 ->
            18:46:17.059 -> rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
            18:46:17.059 -> configsip: 0, SPIWP:0xee
            18:46:17.059 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
            18:46:17.059 -> mode:DIO, clock div:1
            18:46:17.059 -> load:0x3fff0018,len:4
            18:46:17.059 -> load:0x3fff001c,len:1100
            18:46:17.059 -> load:0x40078000,len:10088
            18:46:17.059 -> load:0x40080400,len:6380
            18:46:17.059 -> entry 0x400806a4
            18:46:18.739 -> SCCB_Write [ff]=01 failed
            18:46:18.739 -> SCCB_Write [12]=80 failed
            18:46:18.859 -> Camera init failed with error 0x20001
            ===============================================

          • After flashing, you need to remove the connection between GND and IO0. If you see the error (below) – that indicates the ESP-32 is in boot mode, try adding a 10K resistor between IO0 and 3.3V to make sure the state of this pin/input isn’t floating. Once I added the resistor, everything worked for me!

  14. I have the same problem as ‘Domenico’ – I ordered 2 ESP32-CAM modules from Banggood and they also do not recognise the camera…they are also not marked AI Thinker…

    • I had the same issue Chris Parsons. I bought 2 ESP32-CAM modules from Amazon. I paid a premium to get them quickly. They are from DIYMORE. They do not work with the examples here. I replaced them with 2 from Banggood that are labelled AI Thinker and they work just fine

      • I actually bought my modules from Banggood – the advert shows ‘AI Thinker’ but they sent what I suspect is an ‘equivalent’ that doesn’t work – so now I will have to convince them to refund me and send the correct ones – and wait another 2 weeks 🙁

        Guess you must have been lucky?

        • I have tried convincing Banggood to refund in another issue that seemed crystal clear (ordered a shutter up/down switch and received a light dimmer 🙂 and got only a fraction of my money back. Trying to get this module to work will probably be easier than claiming a refund

  15. I am trying to edit the code of the esp32 on access point mode. But it work. The wifi is up and running. But the website is not loading. Is this code compatible with accesspoint wifi?

    • Hi.
      I don’t see why it wouldn’t be compatible, but I haven’t tried it.
      Please note that you can only access the video streaming at one place at a time. Make sure you don’t have the web server opened in another tab.
      Regards,
      Sara

  16. Hi Rui..Sara can you make an update on the code to fix the Camera init failed with error 0x20001 ERROR CODE ? Thanks a lot lot lot. 🙂

  17. Hello
    It works, but …
    when I run the ip I have a picture every 30 seconds or so.
    Is it possible to block the IP fixed?

  18. I too received boards with a different chip from Bang Good, however mine work fine with the AI Thinker selection. I did have issues in the beginning when setting them up and finally figured out they are really picky about their power. They need a lot and are extremely intolerant of noise or low voltage. Try using the 5V pin and the ground next to it rather than the 3.3V. They seem to be happier when using their own onboard voltage converter.

  19. I too received a unmarked unit from banggood (also 1 from AliExpress) and had the same error, Camera init failed with error 0x20001. But as an earlier poster said, I too switch the jumpier from 3.3v to 5v and that solved the problem.

    NOTE: both my units, were unmarked (images on websites showed AI-Thinker) but required 5 volts. So that was the problem not anything in the code.
    Ivory

    • Unfortunately, this solution doesn’t work for me. After flashing, I switched to 5V, the reset LED now keeps burning faintly and after reset, the serial monitor does not show anything, not even an error message. Scanning the ports on my local network also does not show a new server added…

  20. Dear Rui, thanks for the tutorial.
    I would like to be able to turn on a light from my cell phone, a light attached to a relay controlled by the ESP32.
    How would do that?
    Thanks
    Paulo

  21. HI RUi, excellent, now works fine! It was a power issue, you have to connect to 5VDC not 3.3V !

    • Is this when you are programming it? I have a different FTDI programmer with a 3.3v or 5v switch?

      I did wonder if the ESP32 would get enough power via the FTDI programmer which is connected to a USB port on my PC?

      Chris

  22. Hi Rui, a quick question not fully understood; can I check the cam (accessing the video streaming server) from outside the house, not using the same IP address????

  23. Hi rui…I tried an answer by myself and found the OpenVPN could be a way to reach from outside of the home to inside it the web cam video streaming. Am I wrong?

    • Yes. Using a setup like that should definitely make your ESP32-CAM web server available from anywhere.

  24. Hi,
    Referring to the this tutorial with the ESP-32 CAM.
    I would like to be able to switch on a lamp while watching the streaming video from the camera.
    How can it be done?
    Thanks
    Paulo

  25. bonjour,
    merci pour les infos j’ai bloqué l’IP et l’image est plus fluide avec une bonne antenne.
    Mon souhait serait de pouvoir capturer une image et l’envoyer par mail .
    Une idée ?
    Merci

  26. Gave up on using the non ‘AI Thinker’ boards and bought another one that was marked AI Thinker…uploaded the code, and finally got the message showing the IP address in the monitor, but no web server on the same LAN!

    Tried a reboot and even reloading the code but get garbage in the monitor and sometimes a message about ‘Camera init failed with error 0x20002’

    I have tried disconnecting the power to the board and connecting 5v and GND instead but get the same results, reflashing the firmware (with 3.3v connected) but nothing…did you ever produce the help guide?

    • Hey, try reflashing with 5V (connect to the 5V pin of course). Programming with 3.3V here has also resulted in tons of error messages. With 5V flashing&running, everything is find.

  27. Hi and thanks for the tutorial. Really needed it!
    Took a while to get everything working.
    My main problems were power issues as well.
    I found I could flash the code via USB at 3.3 and 5, but then trying to run the code would constantly crash in different ways.
    So I powered the device with an external 5v power supply, disconnected the USB power (but not the ground). With that, everything worked great.
    Don’t give up on this device … it’s really impressive once you get it going!
    Thanks again for your article!

  28. I’ve bought also from aliexpress 3 ESP32-cam non-AI-thinker boards.
    I’ve found out that the boards come with pre-installed fw.
    if you look with phone or PC for WiFi networks, you’ll find an “ESP32_CAM” ssid, which belong to it. just click on connect, no-pwd and go to :

    http://192.168.4.1/jpg_stream

    that’s all. i’m figuring out how to connect to the board and flash another fw.
    I’ll keep you update.

  29. I found the problem. I had upgraded the boards to Version 1.0.2 and no ESP32 code would compile.

    Thanks to a post by stankusaudrius on the ESP32 Github, I looked in
    C:\Users\steve\AppData\Local\Arduino15\packages\esp32\hardware\esp32
    and found a folder for the older version (1.0.1). Deleting the folder for 1.0.1 fixed the problem.

  30. Your stuff is great as usual!
    Worked first try… Unfortunately I bought mine off Alliexpress and of course the quality of the image is poor. But – it did work first try and still fun to play with.
    Thanks for your great work.

  31. Hi, Once again another fantastic tutorial which help me enormously. I got it working after changing to the 5v connections and was a little disappointed with the picture lag. I managed to overcome this by changing the: ‘config.frame_size = FRAMESIZE_UXGA;’ to: VGA (config.frame_size = FRAMESIZE_VGA;). The picture quality is not as sharp but it is much more responsive. Also, this camera works with the motion eye os setup. A much cheaper alternative to the pi-zero option with camera. Thanks.

    • Hi guy, the cam works perfect at 5 voltages; also, I tried successfully to streaming out using ngrok.com service. On my application the port 80 is fine. Thanks rui and Sara.

  32. Hi Sara and Rui
    I too got an unmarked ESP32 cam board from China and set it up as an AI Thinker following your excellent tutorial. I was originally running it on 3.3 volts via the USB adaptor board and although it flashed and worked just fine, it was a bit iffy at connecting to the wifi network and there was a lot of latency and coloured lines across the picture. I have now changed to a stand alone 5 volt supply and it is much much better, so it would seem that these unbranded Chinese boards want to run at 5 volts. On a slightly different note, I would really like one of my external camera viewer apps to be able to ‘see’ this camera. I should be able to integrate it manually from the network IP address, port numbers involved and if I know the format of the video stream. Do you happen to know what it is and what port I would need to be looking for / forwarding ?

      • Thanks Sara. I’m going away for a few days so won’t get an opportunity to try anything for a while. Is it possible to have more than one of these camera modules loaded with the tutorial software, running at once ? The router would presumably issue a different IP address to each module but would it just produce a conflict on port 80 ? Sorry if these are dumb questions, but I’m very new to all this. I have several remote viewer apps that I have tried to use with this module but I have been unable so far to get any of them to ‘see’ the module. The apps all seem to have settings for ‘generic’ IP cameras, but there are a lot of them. Is there anything else about the format of the data other than “MJPEG” that’s known that would help me find a setting that allowed the camera to be recognised ? Aircam is the app I would like to use as this works fine with my existing USB cameras and is able to operate with IP cameras as well if you can get them recognised. Thanks again for the excellent tutorials and taking the time to help old dinosaurs like me ! 🙂

  33. Hi, I’ve just got my esp32-cam and managed to make it work in no time, thanks to your explantion – thanks!
    Just wondering about the camera – the picture quality is pretty low – it needs lots of light and I have blue and yellow horizontal lines, flickering all over the image. Is it just my camera, or is it a known problem?

    • Hi Danny.
      The quality of the picture is low, but I didn’t get horizontal lines.
      Some readers reported that powering the ESP32 with 5V through the 5V pin can help solve that issue.
      Regards,
      Sara

  34. What do I wrong?
    Wn10 environment
    RPI 3B
    No pblm with the installation of the ESP. It works and gives me the IP address.
    But impossible to install Home assistant.
    I’ve loaded the file “hassos_rpi2-2.12.img.gz”. Extracted it gives me he file “hassos_rpi2-2.12.img”.
    I load this file with Etcher on a (new) 64GB SD card.
    Etcher comes back with “all fine” after a few minutes.
    But the SD card is empty and asks to be formatted…
    Nothing has been copied on the SD card…
    I’ve also used “Win32DiskImager” with same results.
    Tested several times.
    Any idea?

  35. Unlike most of your projects, this one was a disaster…I have bought three ESP32-CAM boards and none of them have yet to produce an image. I have tried running them off both 3.3v and 5v and can get a wireless connection but no image is displayed. I have also tried the ESP32 WebCameraServer example and this didn’t work either (‘camera not supported’ message)

    Bit disappointed I have wasted my money but I guess perhaps the boards and cameras vary although they all advertised as the same!

    I did manage to get one board where the chip was marked ‘AI Thinker’ but this didn’t work either 🙁

    • Chris.
      The camera not supported message could be an indication that the camera ribbon cable is not connected correctly. On the ribbon cable should be a line, when connected if you can see that line, the cable is not pushed in far enough.
      I had the same problem, and fixed it with reconnecting the ribbon cable correctly.
      Please try reconnecting again and see if this fixes the problem.
      Hope this helps.

    • I had similar problems initially using just a cheap Chinese version from an eBay seller. I have found that it definitely needs to be be powered from 5v not 3.3v and you need to have a good wifi connection. If necessary, configure the antenna link and use an external antenna – dirt cheap from eBay sellers. The camera connects every time now for me with no “camera not supported” error messages and stays reliably connected. I have to say that the picture quality is very good – easily as good as other cameras that I have that were much more expensive. The second issue that I had was with the browser that I tried to use to look at the camera output. Under Windows 10, my preferred IE v10 will have none of it. Although it connects and all looks to be well, the picture window is just blank. However, both Chrome under W10 and Safari under IOS on my iPhone produce an excellent picture as soon as “Start Stream” is clicked

  36. Hi Rui and Sara,
    I like your website a lot. I love your Raspberry Pi 20 Easy Projects book, very useful and easy to follow!
    I wanted to try this project with the ESP32 and the camera, but I need some help. I am having issues uploading the programm using the Arduino IDE. I get this error:

    Arduino: 1.8.9 (Windows 7), Board: “ESP32 Wrover Module, Huge APP (3MB No OTA), QIO, 80MHz, 921600, None”

    Sketch uses 774606 bytes (24%) of program storage space. Maximum is 3145728 bytes.
    Global variables use 47912 bytes (14%) of dynamic memory, leaving 279768 bytes for local variables. Maximum is 327680 bytes.
    esptool.py v2.6
    Serial port COM6
    Connecting…….._____….._____….._____….._____….._____….._____….._____

    A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header

    • Hi again,
      It is working! I just forgot to set the jumper from the FTDI programmer to 3V3 (it was on 5V). Thanks for this tutorial! 🙂

      • I’m glad you’ve found out the problem.
        Thank you for following our work, specially our Raspberry Pi book.
        Regards,
        Sara

  37. Hi,
    I have been able to install everything. Not as easy as described…
    Now I’ve a pblm to retrieve the images taken with the OV2640 and put them in HomeAssistant.
    You write simply to add the url (http://192.168.1.91/ in your ex.) but this is no working in my case.
    If I want to get an image in HA, I’ve to use the complete url like found in the image source file of OV2640 application.
    This is what I’ve to use: “http://192.168.0.162/capture?_cb=1559298840529”
    BUT this is not working automatically. I’ve to update the address manually.
    Not the best solution.
    Do you have a idea how to improve?
    Thanks in advance for any help

    • Hi Jean.
      I’m sorry for the delay in our response.
      We receive lots of comments, questions and emails every day. It is very difficult to keep track of everything. I hope you understand.

      Regarding your question.
      We’ve got everything working fine by just copying the URL. So, I don’t know what can be the issue in your case.
      If you go to the IP address, outside Home Assistant, can you see the video streaming properly?

      Regards,
      Sara

      • Most Home Assistant users are not using the Lovelace UI, so I don’t know if the yaml code is any different. This works in my cameras.yaml file:

        # ESP32-CAMERA
        – platform: mjpeg
        mjpeg_url: http://192.168.1.54
        name: ESP32-CAM

        Of all my WiFi cameras, this one interfaces with my Home Assistant easier than all others.

      • Hi Sara,
        Thanks!
        We all have the same prblm… time.
        Let me a few time to test it again, I’m in an other (of your) project actually.

  38. I got this working on a chinese no-brand ESP-CAM – works well, though lots of latency and the occasional vertical line – but running at 5v has helped somewhat.

    I think the latency is due to the sheer size of the image – 1600×1200. Is there any way to get a reduced image size from the CCD – or maybe force a slower refresh rate of 1 frame per second.

    Thanks!

    • Solved:

      config.frame_size = FRAMESIZE_SVGA;

      This makes it 800×600. A bit better, but still a bit wobbly. I suspect there isn’t enough CPU there to handle lots of movement.

      • Hi Aris.
        Thanks for sharing that information.
        Yes, the ESP32 may not have enough CPU to process movement.
        Regards,
        Sara

  39. Hi Sara,
    I have two questions. When I install the program and run it, everything works fine. However, if I detach it from the programmer and power it with the 5V powersupply, I cannot seem to connect to it anymore. Do you have any suggestions? Another questions is regarding Octoprint. It has a feature to use a camera stream to monitor 3D prints. I was wondering if you could use this setup as a stream in Octoprint in stead of the fixed Raspberry Pi camera?

    Cheers,
    Peter

    • Hi Peter.
      What external power supply are you using? I’ve experimented with a phone portable charger and it worked fine.
      You can have just one client at a time, so if you have a previous tab open, when you try to connect again, it won’t show anything in the new tab. You need to close the previous tab.
      Also, make sure that when you are powering it with the external power supply, the ESP32 is within the wi-fi range of your router.
      If the octoprint software provides the option to add an ip cam, it would probably be compatible. You just need to pass the streaming URL.
      Regards,
      Sara

  40. Thank you for this tutorial! I recently purchased two of these boards with cameras and am anxious to get them up and running. I believe I’ve installed everything correctly for the IDE but when I go to compile the sample code I get this error message:

    Board esp32doit-devkit-v1 (platform esp32, package esp32) is unknown
    Error compiling for board DOIT ESP32 DEVKIT V1.

    Thank you for any help and guidance…

  41. Hi Sara

    My ESP camera worked a treat whilst I was away and provided a good security picture of my house. Couple of questions that I hope you might be able to answer. First, where is the user interface located ? Is it a piece of software built into the camera that the Arduino sketch interacts with, or is it part of one of the Arduino libraries that is used in the sketch ? Can the “Start Stream” button effectively be ‘pressed’ in software i.e. without having to click on the button so that the camera is streaming immediately from when it connects ? Also, where is the post number that it is outputting on defined ? Can it be changed from 80 so that more than one ESP 32 cam module can be active on different IP addresses. I’m sure others must want to do this as more than one camera would be really useful. These are probably dumb questions but I’m pretty new to all this and am just pleased that I have gotten as far as I have already with your tutorial and help 🙂

  42. Great tutorial – I was able to upload the code just fine to my AI-Thinker esp32, however when I disconnect the GPIO0 connected to GND and reset, if I watch it in Serial Monitor it never connects to the WiFi.

    I’ve tried three different WiFi’s that I have here, all different SSIDs, but none of them ever connect.

    This is what I get, looks like it’s just fine, but that last row of ……. dots just go on forever!

    rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:1
    load:0x3fff0018,len:4
    load:0x3fff001c,len:1100
    load:0x40078000,len:9232
    load:0x40080400,len:6400
    entry 0x400806a8
    ………………………………………….

    Any ideas?

    • Hi Don.

      Some of our readers reported that if your network credentials have more than 11 characters, it will not work.

      Also, I’ve recently discovered through one of our readers, that some ESP32-CAM boards come connected to the external antenna instead of the internal antenna. Here’s what he said that might be useful:

      “Check the jumper 0K resistor by the antenna connector is in the proper position for the antenna desired. There are 3 little white squares laid out like a “<" with the middle position being common. With board turned so the the pcb antenna up, to use the pcb antenna, the resistor must be on the top position, like this: / For the antenna connector, the resistor must be on the bottom position, like this: \ " The board provides a connector for an external antenna and has an onboard antenna as well. If your ESP32 comes with the external connector enabled, you can try adding an external antenna. Or solder/unsolder to use the internal antenna. I hope this helps. Regards, Sara

  43. Hey. Hope this might help someone. The ESP32 cam units cannot connect to a WiFi hotspot where the SSID has more than 11 characters in the name. Mine had 12 and I was tearing my hair out trying to work out what was wrong, as everything else seemed perfect. Found this snippet on another forum, I hope it aids someone.

      • Hi Sara,

        If this the case, do you have a suggestion?
        I’m not able to change the SSID.
        And even if I could do it I should have to change all the systems connected…

        • Hi Berrier.
          Some of our readers have done that, but I don’t know how to do that. Maybe a google search can help with that.
          Some routers also provide the option to create guest networks. That can be a better alternative because you won’t have to change the systems that are already connected (if your router allows that).
          Bur before trying it, take a look at our troubleshooting guide to ensure that you’ve done all the steps to make it work: https://randomnerdtutorials.com/esp32-cam-troubleshooting-guide/
          Regards,
          Sara

  44. My board looks just like the AI Thinker, but it is an HW-297 which I got from Amazon for $12.99. I followed the instructions and got the code loaded OK but it wouldn’t work. Just gave lots of errors. When I powered it with 5V (on the 5V pin) instead of 3.3V (on the 3.3V pin), it began to work. Amazing little thing!

  45. For anyone having “Camera init failed with error 0x20004” try for flash and power up the board using 5v pin instead 3v, its worked for me.

  46. Excellent tutorial!! I really want to thank you for posting this. As always, you do an excellent job of explaining all the steps. Thank you so much for your hard work and for sharing your knowledge with the community.

Leave a Comment

Download our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.