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.
To follow this tutorial you need the following components:
- ESP32-CAM with OV2640 – read Best ESP32-CAM Dev Boards
- FTDI programmer
- Female-to-female jumper wires
- Fake/dummy dome security camera
- 5V power supply for ESP32-CAM
- Optional – Home Assistant on Raspberry Pi:
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:
- Installing the ESP32 Board in Arduino IDE (Windows instructions)
- Installing the ESP32 Board in Arduino IDE (Mac and Linux instructions)
2. Video Streaming Web Server Code
After that, copy the code below to your Arduino IDE.
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.
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:
Many FTDI programmers have a jumper that allows you to select 3.3V or 5V. Make sure the jumper is in the right place to select 5V.
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:
1) Go to Tools > Board and select AI-Thinker ESP32-CAM.
2) Go to Tools > Port and select the COM port the ESP32 is connected to.
3) Then, click the upload button to upload the code.
4) When you start to see these dots on the debugging window as shown below, press the ESP32-CAM on-board RST button.
After a few seconds, the code should be successfully uploaded to your board.
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.
- You should be familiar with the Raspberry Pi – read Getting Started with Raspberry Pi.
- Getting Started with Home Assistant on Raspberry Pi
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
<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>
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
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 the ESP32-CAM:
- ESP32-CAM Video Streaming and Face Recognition with Arduino IDE
- ESP32-CAM Take Photo and Save to MicroSD Card
- ESP32-CAM PIR Motion Detector with Photo Capture (saves to microSD card)
- ESP32-CAM Take Photo and Display in Web Server
- Build ESP32-CAM Projects (eBook)
- Read all our ESP32-CAM Projects, Tutorials and Guides
Thanks for reading!