ESP32-CAM is a development board with an ESP32-S chip, an OV2640 camera, microSD card slot, and several GPIOs for connecting peripherals. In this guide, we will introduce the ESP32-CAM GPIOs and how to use them.
pinout diagram
The image below shows the pinout diagram of the ESP32-CAM AI-Thinker .
Schematic diagram of the circuit principle
The figure below shows the schematic of the ESP32-CAM.
power pin
ESP32-CAM is equipped with three GND pins (black) and two power pins (red): 3.3V and 5V .
You can pass 3.3V or 5V pins. However, many people have reported errors when powering the ESP32-CAM with 3.3V, so we always recommend powering the ESP32-CAM through the 5V pin .
power output pin
The pins on the silkscreen are also labeled VCC (colored with a yellow rectangle). You should not use this pin to power the ESP32-CAM. This is an output supply pin. It can output 5V or 3.3V.
In our case, the ESP32-CAM outputs 3.3V, regardless of whether it is powered by 5V or 3.3V. Next to the VCC pin, there are two pads. One is marked 3.3V and the other is marked 5V.
If you look closely, you should have a jumper on the 3.3V pad. If you want to have an output of 5V on the VCC pin, you need to remove that connection and solder the 5V pad.
serial pin
GPIO 1 and GPIO 3 are serial pins (TX and RX respectively). Since the ESP32-CAM does not have a built-in programmer, you will need to use these pins to communicate with the board and upload code.
The best way to upload code to the ESP32-CAM is to use the FTDI Programmer
GPIO 1 and GPIO 3 can be used to connect other peripherals such as outputs or sensors after uploading the code. However, you won't be able to open the serial monitor and see if all is well with your setup.
GPIO 0
GPIO 0 determines if the ESP32 is in blink mode. This GPIO is internally connected to a pull-up 10k ohm resistor.
When GPIO 0 is connected to GND, the ESP32 will enter blink mode and you can upload code to the board.
- GPIO 0 connected to GND ESP32-CAM in blink mode
To get the ESP32 running "normally" you just need to disconnect GPIO 0 from GND.
MicroSD card connection
The following pins are used to interface with the microSD card while it is running.
micro SD card | ESP32 processor |
Florida. | GPIO 14 |
interrupter | GPIO 15 |
data 0 | GPIO 2 |
Data 1 / Flashlight | GPIO 4 |
Data 2 | GPIO 12 |
Data 3 | GPIO 13 |
If you're not using a microSD card, you can use these pins as regular I/O. You can see the characteristics of these pins.
All of these GPIOs are RTC and support ADC: GPIO 2, 4, 12, 13, 14 and 15
LED(GPIO 4)
ESP32-CAM has a very bright built-in LED that can
be used as a flash when taking pictures. This LED is internally connected to GPIO 4 .
This GPIO is also connected to the microSD card slot, so you might have trouble trying to use both at the same time - the torch will light up when using the microSD card.
NOTE: One of our card readers shared that if you initialize the microSD card as follows, you won't have this problem because the microSD card won't use the data row.
SD_MMC.begin("/sdcard", true)
*We've found this works, and the LED doesn't produce a flashing effect. However, the LED still lights up at low brightness - we're not sure if we're missing something.
GPIO 33 – Built-in red LED
Next to the RST button, there is an onboard red LED. This LED is connected internally to GPIO 33. You can use this LED to indicate that something is happening. For example, if Wi-Fi is connected, the LED is red and vice versa.
The LED works with inverted logic, so you send a low signal to turn it on, and a high signal to turn it off.
You can try uploading the code snippet below to see if the LED turns on.
void setup() {
pinMode(33, OUTPUT);
}
void loop() {
digitalWrite(33, LOW);
}
camera connection
The connection between the camera and ESP32-CAM AI-Thinker is shown in the table below.
OV2640 camera | ESP32 processor | variable name in code |
D0 | GPIO 5 | Y2_GPIO_NUM |
D1 | GPIO 18 | Y3_GPIO_NUM |
D2 | GPIO 19 | Y4_GPIO_NUM |
D3 | GPIO 21 | Y5_GPIO_NUM |
D4 | GPIO 36 | Y6_GPIO_NUM |
D5 type | GPIO 39 | Y7_GPIO_NUM |
Terminal D6 | GPIO 34 | Y8_GPIO_NUM |
D7 | GPIO 35 | Y9_GPIO_NUM |
interrupter | GPIO 0 | XCLK_GPIO_NUM |
interrupter | GPIO 22 | PCLK_GPIO_NUM |
virtual synchronization | GPIO 25 | VSYNC_GPIO_NUM |
HREF | GPIO 23 | HREF_GPIO_NUM |
interrupter | GPIO 26 | SIOD_GPIO_NUM |
interrupter | GPIO 27 | SIOC_GPIO_NUM |
power pin | GPIO 32 | PWDN_GPIO_NUM |
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27
#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
We hope the ESP32-CAM GPIO guide is helpful to you.