Basics: Project 084c ESP32-CAM Development Board – How to take picture and save on SD card
Basics: Project 084c
Project name: ESP32-CAM Development Board – How to take picture and save on SD card
Tags: Arduino, Ai-Thinker, ESP32-CAM, Development Board with camera, OV2640, OV7670, how to take a picture and save it to SD card, saving picture to SD card
In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):
2. Arduino IDE ( you can download it from here )
3. USB to TTL/Serial adaptor/converter 1 pc
4. Jumper cables F-F
7. External 5V power supply for ESP32-CAM 1 pc (optional)
We will learn in this project how to take a picture with ESP32-CAM Development Board with camera and save it to micro SD card. If you press the ESP32-CAM on-board RESET button, it will wake up and take a picture and save it on the micro SD card.
- A ESP32-CAM Development Board with camera is in deep sleep mode;
- An on-board RST (RESET) button PRESSED to wake it up;
- A ESP32-CAM Development Board camera takes a picture;
- A picture is saved on a micro SD card with the name: pictureX.jpg, where X corresponds to the picture number;
- A picture number will be saved in the ESP-CAM Development Board flash memory so that it will be not erased during RESET;
- We will be able to keep track of the number of pictures taken.
Understanding the USB to TTL converter
You can read more about them here.
Understanding the ESP32-CAM Development Board with camera
The ESP32-CAM has a very competitive small-size camera module that can operate independently as a minimum system with a footprint of only 27*40.5*4.5mm and a deep sleep current of up to 6mA.
ESP32-CAM can be widely used in various IoT applications. It is suitable for home smart devices, industrial wireless control, wireless monitoring, QR wireless identification, wireless positioning system signals and other IoT applications. It is an ideal solution for IoT applications.
ESP32-CAM adopts DIP package and can be directly inserted into the backplane to realize rapid production of products, providing customers with high-reliability connection mode, which is convenient for application in various IoT hardware terminals.
The ESP32-CAM Development Board with camera doesn’t come with a USB connector, so you need an USB to TTL/Serial adaptor/converter to upload code through the serial pins (U0R and U0T pins).
- The smallest 802.11b/g/n Wi-Fi BT SoC Module
- Low power 32-bit CPU,can also serve the application processor
- Up to 160MHz clock speed，Summary computing power up to 600 DMIPS
- Built-in 520 KB SRAM, external 4MPSRAM
- Supports UART/SPI/I2C/PWM/ADC/DAC
- Support OV2640 and OV7670 cameras,Built-in Flash lamp.
- Support image WiFI upload
- Support TF card
- Supports multiple sleep modes.
- Embedded Lwip and FreeRTOS
- Supports STA/AP/STA+AP operation mode
- Support Smart Config/AirKiss technology
- Support for serial port local and remote firmware upgrades (FOTA)
- Dimensions 40.5mm x27mm x4.5mm
- Weight G.W 20g
- Battery Exclude
- Package DIP-16
- SPI Flash Default 32Mbit
- RAM 520KB SRAM +4M PSRAM
- Bluetooth Bluetooth 4.2 BR/EDR and BLE standards
- Wi-Fi 802.11 b/g/n/
- Support interface UART,SPI,I2C,PWM
- Support TF card Maximum support 4G
- IO port 9
- UART Baudrate Default 115200 bps
- Image Output Format JPEG( OV2640 support only ), BMP,GRAYSCALE
- Spectrum Range 2412 ~2484MHz
- Antenna Onboard PCB antenna, gain 2dBi
- Transmit Power 802.11b: 17±2 dBm (@11Mbps); 802.11g: 14±2 dBm (@54Mbps); 802.11n: 13±2 dBm (@MCS7)
- Receiving Sensitivity CCK, 1 Mbps : -90dBm; CCK, 11 Mbps: -85dBm; 6 Mbps (1/2 BPSK): -88dBm; 54 Mbps (3/4 64-QAM): -70dBm; MCS7 (65 Mbps, 72.2 Mbps): -67dBm
- Power Dissipation Turn off the flash lamp:180mA@5V; Turn on the flash lamp and turn on the brightness to the maximum:310mA@5V; Deep-sleep: Minimum power consumption can be achieved 6mA@5V; Moderm-sleep: Minimum up to 20mA@5V; Light-sleep: Minimum up to 6.7mA@5V
- Security WPA/WPA2/WPA2-Enterprise/WPS
- Power Supply Range 5V
- Operating Temperature -20 ℃ ~ 85 ℃
- Storage Environment -40 ℃ ~ 90 ℃ , < 90%RH
In the package you will get 1 x ESP32-CAM Development Board, 1x camera Module-OV2640-FPC-24P-0.5mm-21mm- 2 Megapixel and 2x headers-2.54mm-1x8pin.
On-Board vs IPEX Antenna
ESP32-CAM Development Board with camera can be with the antenna jumper set for an external antenna or for the on-board antenna. You can see the two different settings below:
If you have a low frame rate or poor reception this might be the problem. You can either move the jumper with a bit of very careful soldering or buy an IPEX WiFi antenna which will improve the signal.
- We can easily build a simple camera with this board and save the photos in an SD card using the embedded SD card slot the board offers.
- We can then modify this project to detect humans and save an image when one is detected.
- We can recognize human faces and act accordingly.
- We can build a surveillance camera with the ESP32 Cam board.
- We can also stream video using this board.
Signals and connections of the ESP32-CAM Development Board with camera
You can read more about ESP32-CAM development board GPIOs here.
ESP32-CAM module FTDI programmer
U0TXD (GPIO1) RXI
U0RXD (GPIO3) TX0
GND and GPIO0 connected just to upload the sketch (for flashing). Many FTDI programmers have a jumper that allows you to select between 3.3V or 5V. Make sure the jumper is on 5V.
Please note: the order of the FTDI programmer’s pins on the diagram may not match yours. Make sure you check label next to each pin on ESP32-CAM development board.
Step by Step instruction
1. Adding ESP32 platform to Arduino IDE
The Arduino environment has to be set up to make it compatible with the ESP32 module.
If you previously installed the hardware libraries for the ESP32 using the old method you need to delete them. Find the folder where your Arduino libraries are kept by opening File -> Preferences in the Arduino IDE. See the sketchbook location field. Click on Browse button. Inside Arduino folder open the hardware folder and find and delete either the esp32 folder or espressif folder.
We are using PC with Windows 7 OS.
1.Download and install the latest Arduino IDE version Windows Installer. You can download it here.
2.Open Arduino IDE.
3.Open the Preferences window from the Arduino IDE. Go to File -> Preferences.
4.Paste the following line into the Additional Boards Manager URLs field: https://dl.espressif.com/dl/package_esp32_index.json
5.If you have entries in this field already then add the new line before them but separate them with a comma.
6.Go to Tools -> Board -> Board Manager…
7. Type ESP32, point with mouse cursor on record line found (ESP32 by …) and click on Install button to install the new hardware libraries.
8.When installation done, close and open your Arduino IDE again.
9.You will be able to find all the ESP32 boards in the Arduino IDE’s board selector.
2. Uploading the sketch to the ESP32-CAM Development Board with camera using FTDI programmer
1. Most SD cards work right out of the box, but it’s possible you have one that was used in a computer or camera and it cannot be read by the SD library. It’s not desirable to format SD cards frequently, as it shortens their life span. You’ll need a SD reader and computer to format your card. The library supports the FAT16 and FAT32 filesystems, but use FAT16 when possible. See additional info here. Please note that according to the ESP32-CAM development board specifications, the ESP32-CAM should only support 4 GB SD cards. However, we have tested it with 16 GB SD card and it works very well.
2.Format the SD card as FAT16 or FAT32. Insert the SD card adapter with Micro SD card in your PC. Go to My Computer and right click on the SD card. Select Format…
3.A new window pops up. Select FAT32, press Start to initialize the formatting process and follow the onscreen instructions.
4. Click on Close button when done. Take out and insert the formatted Mirco SD card to TF card slot in ESP32-CAM.
5.Do wiring. Very important: GPIO0 (IO0) must be connected to GND otherwise you will not be able to upload code. In this project we use the AI-THINKER ESP32-CAM Development Board with camera.
6.Attach WiFi antenna (optional). It will help you to increase WiFi range.
7.Attach OV2640 camera.
8. Plug your FTDI programmer into your PC USB port.
9. Open Arduino IDE.
10. Open sketch.
11. Go to Tools -> Board, select AI Thinker ESP32-CAM.
12. Go to Tools -> Port and select the COM port the ESP32-CAM Development Board connected to (we have COM7).
13. Click on Upload button in your Arduino IDE.
14.When you see some dots in the debugging window, press the ESP32-CAM Development Board on-board RST (RESET) button to restart your ESP32 in flashing mode.
15. After a few seconds, the code should be successfully uploaded to your board. When you see the “Done uploading” message, you need to remove GPIO0 from GND.
16. Open the Serial Monitor of Arduino IDE (Tools -> Serial Monitor) at the baud rate of 115200 and press the ESP32-CAM Development Board on-board RST (RESET) button to run your new code.
17. As you can see, the picture was successfully saved on the Micro SD card.
18. If everything is working as it was expected, you can disconnect the ESP32-CAM development board from the FTDI programmer and power it using an external power supply.
19. To see the pictures taken, remove the Micro SD card from the TF card slot and insert it inside the SD card adapter into your PC. You should have all the pictures saved. The quality of your picture depends on your lighting conditions.
If you have any errors with your ESP32-CAM development board please check our project – Basics: Project 084d ESP32-CAM Development Board with camera – Troubleshooting
We start by including the necessary libraries to use a camera, Micro SD card and the EEPROM library to save permanent data in the flash memory.
Define the number of bytes you want to access in the flash memory. We will use only one byte that allows us to generate up to 256 picture numbers. The we define the pins for the AI-THINKER ESP32-CAM development board. You might need to change the pin definition depending on the board which you have. Wrong pin assignment can result a failure to initialize the camera.
We set an int variable pictureNumber that that will generate a picture name: pictureX.jpg.
In the setup() the code runs only once when the ESP32 wakes up (when you press the on-board RST button). We define the camera settings and use the settings for a camera with PSRAM. Then we initialize the camera and Micro SD card. Then we take a picture with a camera. After that, we initialize the EEPROM with the size defined before. The picture number is generated by adding 1 to the current number saved in the flash memory. To save the picture on the Micro SD card, create a path to your file. We will save the photo in the main directory of a Micro SD card and the file name is going to be pictureX.jpg. After saving a picture, we save the current picture number in the flash memory to keep track of the number of pictures taken.
When the ESP32-CAM development board takes a picture, it flashes the on-board LED. After taking the picture, the LED remains ON, so we send commands to turn it OFF. The LED is connected to GPIO 4.
Finally, we put the ESP32 in deep sleep. As we do not pass any argument to the deep sleep function, the ESP32-CAM development board will be sleeping all the time until on-board RST button is pressed.
We have learnt in this project how to take a picture with ESP32-CAM Development Board with camera and save it to micro SD card.
Thank you for reading and supporting us.
- See attachments on the begining of this project description