While talking to a neighbor, I mentioned I was experimenting with the ESP32-CAM module (Figure 1). He expressed an interest in a video camera in his entry way. So, I began thinking about putting one in a small 3D printed box for him.
Figure 1. ESP32-CAM module.
As I thought about this project, some of the shortcomings of this module came to mind. While it’s an inexpensive way (less the $10) to produce a video signal and stream it to your Web browser through your in-house router, it’s more of a module for the technical person than plug-and-play.
The first challenge is getting it programmed. It doesn’t have a nice USB interface for use with the Graphical User Interface (GUI) of the Arduino IDE (integrated development environment). Instead, you have to use a USB to TTL converter, like a CP2102.
This requires four female-to-female patch cables between the pins of the CP2102 and the ESP32-CAM. An additional patch cable is used to strap two of the ESP32-CAM pins together when programming. Refer to Figure 2.
Figure 2. CP2102 connections for programming the ESP32-CAM.
Before you can program, you need to install the ESP32 add-on into your Arduino IDE. A very nice tutorial on how to do this can be found at https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/.
Once the ESP32 add-on is installed, go to File, then Examples, then ESP32, then Camera, and finally CameraWebServer.
Next, from the Tools menu, select Board and then ESP32 WROVER Module.
From the Tools menu, select Partition Scheme and then Huge APP (3MB No OTA/1MEG SPIFFS).
In the CameraWebServer program, comment out:
In the lines with the ssid and password:
const char* ssid = "*********";
const char* password = "*********";
You’ll need to replace the line of asterisks in ssid and password with the name of your wireless router and its password.
At the top of the setup() routine, I suggest you insert a delay(5000); line. This will give you five seconds to get the serial monitor running (in the Tools menu) before it starts sending the local IP address you’ll need to view the video.
Now you can compile and upload the program to the ESP32-CAM module. When it finishes, unplug the SP2102 module from your USB port, then remove the jumper wire between pin GPIO0 and ground. Plug the SP2102 module back into the USB port to power the ESP32-CAM and then in the Tools menu, quickly run the serial monitor. The five second delay gives you time to get the serial monitor running.
After a few seconds, you should see a message like the following (Figure 3):
Starting web server on port: '80'
Starting stream server on port: '81'
Camera Ready! Use 'http://10.0.0.35' to connect
Figure 3. The needed IP address for connection is displayed.
Your local IP address will no doubt be different than mine. Type the IP address into the URL bar of a Web browser and then hit Enter. A page should appear with a set of selection buttons. See Figure 4.
Figure 4. Top portion of the Web server’s menu.
Scroll down to the bottom of the page and click on the Start Stream button. Scroll up to the top and you should see your live video. Now, you can explore how the various buttons will change your video.
Note that the Get Still button at the bottom will simply freeze a video frame on the display. It will not write that frame as a .jpg image file to a Micro SD card you insert in the SD card socket on the ESP32-CAM. That takes an entirely different program.
If a larger frame size is selected in Resolution, be prepared for slower frame rates.
If things are not working, I suggest this Web page for troubleshooting hints: https://randomnerdtutorials.com/esp32-cam-troubleshooting-guide/
Putting the ESP32-CAM in a small box and powering it with five volts just isn’t going to work for my neighbor. I can enter his SSID name and password and then show him how to enter the IP address his router assigns, but sooner rather than later that local IP address is going to change. He may power off the ESP32-CAM and while powered down another device may connect to his router and occupy that address.
When he powers up the ESP32-CAM, his router will assign it a different IP address and he won’t know what it is unless he programs the ESP32-CAM and gets the new IP address from the serial monitor. No way is that going to happen. My neighbor is just not that technical. What’s needed is a way for the ESP32-CAM to display its IP address each time it’s powered up.
The simplest method is to attach an LCD display to the ESP32-CAM which will display the IP address. There are a lot of different small LCD displays that would work; I chose the four-line by 20-character 2004 type display with the attached I2C serial interface, making it easy to connect with its two-wire interface.
I’ve used the LCD display shown in Figure 5 in several of my projects and the $6 cost on Amazon makes them attractive.
Figure 5. 2004 LCD display.
These usually come with one of two addresses (0x27 and 0x3F), so if one doesn’t work, try the other.
When using these LCD displays, they are simply connected to a five volt supply, and then the SDA and SCL lines of the I2C interface connect to those pins on your microprocessor. On an Arduino Uno or Nano, these would be pins A4 and A5; on the ESP32, pins GPIO21 and GPIO22, respectively.
A problem is the ESP32-CAM doesn’t bring these pins out on the board. It only has 16 pins total and the usual pin 21 for SDA and pin 22 for SCL on an ESP32 aren’t there.
I’ve seen casual mention online that the ESP32 can reassign pins and adding lines like:
Wire.begin(15, 14); in setup()
would reassign SDA and SCL to pins 15 and 14. I found this simple solution didn’t work.
After a lot of searching, I found a YouTube video that explained how to reassign pins. Turns out you need to change the assignment in the ESP32’s pins_arduino.h file.
There’s a different pins_arduino.h file for every different microcontroller the Arduino IDE has currently installed. You need to find the one for the ESP32. Mine was found in the following folder:
Your location will be different. Follow the AppData folder in your user folder or search on something like “esp32/hardware.” When you find the correct pins_arduino.h file, it will contain the following lines:
static const uint8_t SDA = 21;
static const uint8_t SCL = 22;
These need to be changed to:
static const uint8_t SDA = 15;
static const uint8_t SCL = 14;
Don’t forget to change them back after you successfully program the ESP32-CAM.
After programming the ESP32-CAM, the I2C lines will be on pin GPIO15 and GPIO14. If these pin assignments are left in place and you write a program to save .jpg images to the SD card, that program will not work. Pins GPIO15 and GPIO14 are normally used by the SD card interface.
I made a few changes to the example program CameraWebServer.
// initialize the lcd
// Print a message to the LCD.
At the end of the setup();, the following lines were added:
lcd.print("Camera Ready Use:");
The schematic for this project is shown in Figure 6.
Figure 6. Schematic of ESP32-CAM circuit.
I designed a box to mount things in with Sketchup and then 3D printed it. The Sketchup file and the .obj file are included in the article downloads. With the .obj file and the free Cura slicer program, you can 3D print this with just about any 3D printer.
While a printed circuit board (PCB) is always convenient, with the small number of parts needed I chose to use point-to-point wiring on a breadboard. A socket was made for the ESP32-CAM by cutting a 16-pin IC socket with .3 inch spacing in half.
Along with the ESP32-CAM in its socket, a switch was added between the GPIO0 pin and ground. A four-pin header socket and four-pin header were added to plug in the LCD module and the CP2102 USB to TTL interface.
To program the ESP32-CAM, you only need to close the switch and plug in the SP2102. When finished programming, remove the SP2102 and open the switch.
For power, I used a five volt/two amp wall wart type of supply. The two amps may be a bit of overkill, but the ESP32-CAM is known for low voltage brownout problems. I noted one of my five volt/one amp supplies gave me problems.
Figure 7 shows the interior of the project box.
Figure 7. Interior of the ESP32-CAM box.
Having a video feed for your entry way is becoming more and more common with all the shenanigans going on these days. Here’s a project that offers an alternative to have one that you can customize yourself. NV
|ESP32-CAM||Amazon or eBay|
|CP-2102 USB to TTL Board||Amazon or eBay|
|2004 Type LCD Display, 4-line x 20 character, with the attached I2C serial interface||Amazon or eBay|
|Toggle Switch, SPST or STDT||Electronic Goldmine|
|2,700 µF, 6.3 volt Electrolytic Capacitor||Electronic Goldmine|
|16-pin IC Socket, cut in half||Electronic Goldmine|
|Breadboard for Point-to-Point Soldering||Electronic Goldmine|
|Jumper Wires for Programming ESP-32||Electronic Goldmine|
|5 volt/2 amp Wall Wart Power Supply with Mating Jack||Amazon or eBay|
|Header Pins and Header Sockets||eBay|
|Solder, Various Machine Screws and Nuts||Home Depot, Lowes|
|Project Box||Electronic Goldmine|
What’s In The Zip?
3D Print Files