ESP32-CAM Wi-Fi video stream
Build it step by step
0 of 5 doneFit the programmer
Push the ESP32-CAM onto the MB board, camera facing up.
Set the board
In the Arduino IDE pick "AI Thinker ESP32-CAM" and the MB board's port.
Add Wi-Fi details
Put your 2.4 GHz network name and password in the sketch.
Upload
Upload. If it does not start uploading, hold the MB board's IO0 button, press RST, then release IO0.
Open the stream
Press RST, read the address in the serial monitor and open it on a phone on the same Wi-Fi.
How do you build an ESP32-CAM Wi-Fi video stream?
An ESP32-CAM streams live MJPEG video to a browser on your Wi-Fi, with a snapshot link, for under ₹600 of parts. You need ESP32-CAM, ESP32-CAM-MB programmer board, USB A to micro-USB cable (data) and 5 V 2 A USB adapter. It takes 5 steps and about 75 minutes.
- Level
- Intermediate
- Time
- About 75 min
- Parts
- 4
Wiring
| From | To | Why |
|---|---|---|
| ESP32-CAM | ESP32-CAM-MB board | Push the camera board onto the USB programmer |
| MB micro-USB | Computer (for upload) or 5 V 2 A adapter (to run) | Power and programming |
Code
Arduino IDE with the ESP32 board package (Espressif), board "AI Thinker ESP32-CAM". Turn on PSRAM if the menu offers it. One viewer at a time: the stream holds the server while it runs.
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include "esp_camera.h"
#include <WiFi.h>
#include <WebServer.h>
const char* SSID = "your-wifi";
const char* PASS = "your-password";
WebServer server(80);
bool startCamera() { // AI-Thinker ESP32-CAM pin map
camera_config_t c = {};
c.ledc_channel = LEDC_CHANNEL_0; c.ledc_timer = LEDC_TIMER_0;
c.pin_d0 = 5; c.pin_d1 = 18; c.pin_d2 = 19; c.pin_d3 = 21; c.pin_d4 = 36; c.pin_d5 = 39; c.pin_d6 = 34; c.pin_d7 = 35;
c.pin_xclk = 0; c.pin_pclk = 22; c.pin_vsync = 25; c.pin_href = 23;
c.pin_sccb_sda = 26; c.pin_sccb_scl = 27; c.pin_pwdn = 32; c.pin_reset = -1;
c.xclk_freq_hz = 20000000; c.pixel_format = PIXFORMAT_JPEG;
c.frame_size = FRAMESIZE_VGA; c.jpeg_quality = 12; c.fb_count = 2;
return esp_camera_init(&c) == ESP_OK;
}
void stream() {
WiFiClient client = server.client();
client.print("HTTP/1.1 200 OK\r\nContent-Type: multipart/x-mixed-replace; boundary=frame\r\n\r\n");
while (client.connected()) {
camera_fb_t* fb = esp_camera_fb_get();
if (!fb) break;
client.printf("--frame\r\nContent-Type: image/jpeg\r\nContent-Length: %u\r\n\r\n", fb->len);
client.write(fb->buf, fb->len);
client.print("\r\n");
esp_camera_fb_return(fb);
}
}
void snapshot() {
camera_fb_t* fb = esp_camera_fb_get();
if (!fb) { server.send(500, "text/plain", "Camera error"); return; }
server.send_P(200, "image/jpeg", (const char*)fb->buf, fb->len);
esp_camera_fb_return(fb);
}
void setup() {
Serial.begin(115200);
if (!startCamera()) { Serial.println("Camera init failed"); return; }
WiFi.begin(SSID, PASS);
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
Serial.print("\nStream: http://"); Serial.print(WiFi.localIP()); Serial.println("/stream");
server.on("/", [] { server.send(200, "text/html", "<img src='/stream' style='width:100%'><p><a href='/jpg'>Snapshot</a>"); });
server.on("/stream", stream);
server.on("/jpg", snapshot);
server.begin();
}
void loop() { server.handleClient(); }Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Serial monitor | "Stream: http://192.168.x.x/stream" |
| Opening the address | Live video at 640x480, about 10 to 20 frames per second |
| /jpg link | A single JPEG snapshot |
| Current while streaming | 160 to 260 mA at 5 V |
If it does not work
"Camera init failed"
The camera ribbon is loose or the wrong board model is selected. Reseat the ribbon latch on the ESP32-CAM.
Brownout resets
Power it from a 5 V 2 A adapter, not a laptop port, and use a short cable.
Stream freezes when a second person opens it
This simple server serves one viewer. Close other tabs.
Grainy picture
Lower jpeg_quality to 10 or use FRAMESIZE_SVGA in good light.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the ESP32-CAM Wi-Fi video stream?
ESP32-CAM, ESP32-CAM-MB programmer board, USB A to micro-USB cable (data) and 5 V 2 A USB adapter. ESP32-CAM: AI-Thinker board with OV2640.
How long does the ESP32-CAM Wi-Fi video stream take to build?
About 75 minutes for a intermediate maker, in 5 steps.
How do I know the ESP32-CAM Wi-Fi video stream works?
Serial monitor: "Stream: http://192.168.x.x/stream". Opening the address: Live video at 640x480, about 10 to 20 frames per second. /jpg link: A single JPEG snapshot.
Camera init failed: what should I check?
The camera ribbon is loose or the wrong board model is selected. Reseat the ribbon latch on the ESP32-CAM.
Brownout resets: what should I check?
Power it from a 5 V 2 A adapter, not a laptop port, and use a short cable.
Stream freezes when a second person opens it: what should I check?
This simple server serves one viewer. Close other tabs.
Grainy picture: what should I check?
Lower jpeg_quality to 10 or use FRAMESIZE_SVGA in good light.
