In this tutorial, we are going to learn how to use the camera in the ESP32-CAM development board to set up a video stream. Combining this camera with the WiFi specification from the board can also allow us to capture and play videos, as well as taking pictures at any distance with your smartphone or computer as the triggering device.
To know more about this board and the basics on how to start, you may find it helpful to visit one of our previous tutorials called “ESP32 CAM Board – How to begin”.
Parts Required
- ESP32-CAM;
- FTDI Mini USB for TTL UART Serial Port Converter;
- Breadboard (optional);
- LED (optional);
- 330 ohm resistor (optional);
- Male to male jumper wires (optional);
The ESP32-CAM Board
In this tutorial, we will consider that you have basic knowledge about this board (Figure 1) because the main focus here will be the camera and data exchange.
The following steps will guide you through the process of building a video streaming web server with the ESP32-CAM that you can access within your local network.
Setting it up
There are several ways to do this. To keep it simple in this first approach, the ESP32 will behave as a web server on itself, inside our personal network, as shown in Figure 2.
Note that this is not the best way to set up IoT devices in a network, because the device should not run its own server and would be much advisable to connect your devices to a safer and complete server, for example running it on a Raspberry Pi.
This device configuration became functional but not totally safe. The majority of IoT networks are more or less a bunch of single devices connected to a master (Main Server) that manage the access to every single device on the network. You can find an architecture example using a Raspberry Pi as the main server in Figure 3.
Creating the web server
For such a task, an ESP32 add-on should be included in Arduino IDE. If you had followed the steps from the previous tutorial, “ESP32 CAM Board – How to begin”, you already have it done.
We can use the webserver example from the library to build our web server, thus in your Arduino IDE, select File > Examples > ESP32 > Camera and open the CameraWebServer example. After selecting it, the Arduino IDE will show 4 files associated with the project. Make sure that they are all open, Figure 4.
In the “camera_pins.h” file you can choose the pin assignment for your specific board. If for some reason, your camera module is not present, you will need to add it manually as a new entry with the pins for your specific board.
Circuit
The board can be powered by any power supply available, like a battery or USB port from your computer, as long as it complies with the board power requirements. In this setup, it will be powered through a USB port via the FTDI power pins, like in Figure 5. Start by connecting the FTDI GND pin to the ESP32 GND pin and do the same with VCC. Connect the (orange wire) FTDI TX to the ES32 RX and FTDI RX to the ES32 TX (white wire).
Note: Make sure you check your FTDI labels, as the pins on the diagram may not match yours.
Since GPIO 0 state determines whether the ESP32 is in flashing mode or not, we will need to connect it to the GND pin to turn the ESP32 into flashing mode. After uploading the code, the GPIO 0 must be disconnected from the GND pin.
Code
Before uploading the following code, you should specify your network credentials in “SSID” and “password”. You will also need to comment on all the other camera models different from yours. After modifying the code according to your configuration, everything is ready to be uploaded to your board.
// Select camera model
//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
//#define CAMERA_MODEL_ESP_EYE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
#define CAMERA_MODEL_AI_THINKER // Has PSRAM ------ Our Board
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
const char* ssid = "Your credentials";
const char* password = "Your password";
IP address and access to the video stream
Open the Arduino IDE Serial Monitor with a 115200 baud rate. For the initial information to appear, the on-board reset button must be pressed. All the initial information will appear including the attributed IP Address, with the text “Camera ready! Use http://<your esp32 ip>/ to connect”.
Then, just paste the link in your browser and press “Start Streaming” to start the video. So, it is very direct with the example from the library. Be aware that maybe you have to make some adjustments to your camera lens because it can have some blur from the manufactory. I was not able to adjust mine very well, but it proves the point in the video presented at the beginning of this post.
References
- https://randomnerdtutorials.com/esp32-cam-video-streaming-face-recognition-arduino-ide/
- https://dronebotworkshop.com/esp32-cam-intro/
- https://www.instructables.com/ESP-32-Camera-Streaming-Video-Over-WiFi-Getting-St/
- https://www.nutsvolts.com/magazine/article/build-a-video-camera-using-the-esp32-cam-board
- https://robotzero.one/esp32-cam-arduino-ide/
- https://www.filipeflop.com/blog/esp-32-camera-ip/
- https://github.com/espressif/arduino-esp32
- https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md
Best view i have ever seen !
I think this is one of the such a lot important information for me. And i am satisfied reading your article. But want to remark on few basic things, The website taste is great, the articles is really great : D. Excellent task, cheers