Acoptex.Com

Learn ESP32, ESP8266, Arduino, and Raspberry Pi

How to set static IP address for ESP32-CAM AI-Thinker

We will learn how to set static (fixed) IP address for ESP32-CAM. If you are running a web server or WiFi client with your ESP32-CAM then you notice that every time when you restart your ESP32-CAM, it’s coming up with a new IP address. If you want to have the same (static) IP address then follow this project. The ESP32-CAM needs to be connected through the local network to a router with access to the internet to complete this project. More ESP32-CAM projects you can find here.

Tag: Project 136e How to set static IP address for ESP32-CAM AI-Thinker

Project resources

  • Libraries: None;
  • Sketch: sketch;
  • Other attachements: None.

Parts required

1. ESP32-CAM Development Board with camera 1 set

ESP32-CAM

2. Arduino IDE ( you can download it from here  )

3. USB to TTL/Serial adaptor/converter 1 pc

USB to TTL/Serial adaptor/converter
USB to TTL/Serial adaptor/converter

4. Jumper cables F-F

JUMPER CABLES

5. Micro SD card and SD card adapter 1 pc

MICRO SD WITH ADAPTER

6. WiFi AntennaCompact Internal WiFi Antenna with U.FL connector and 5.9 inch cable 1 pc (optional)

WiFi Antenna, Compact Internal WiFi Antenna with U.FL connector and 5.9 inch cable

Understanding the USB to TTL converter

You can read more about them here.

Understanding the ESP32-CAM Development Board with camera

You can read more about it here.

You can find the ESP32-CAM schematic here, ESP32-CAM development board specification is here, camera specification is here.

Signals and connections of the ESP32-CAM Development Board with camera

Signals and connections of the ESP32-CAM Development Board with camera

ESP32-CAM pinout:

ESP32-CAM pinout
  • GND – ground pin. Connected to Arduino board GND pin.
  • 5V – external power supply pin 5VDC 2A
  • VCC – power supply pin. Connected to 5V pin.
  • 3V3 – power supply pin. Connected to 3V3 pin.
  • U0TXD, U0RXD – Serial pins. You need these pins to upload code to your board.
  • GPIO 0 – pin which determines whether the ESP32 is in flashing mode or not. When GPIO 0 connected to GND, the ESP32-CAM is in flashing mode.

The following pins are internally connected to the Micro SD card reader:

  • GPIO 14: CLK
  • GPIO 15: CMD
  • GPIO 2: Data 0
  • GPIO 4: Data 1 (also connected to the on-board LED)
  • GPIO 12: Data 2
  • GPIO 13: Data 3

Wiring

ESP32-CAM WIRING
ESP32-CAM moduleFTDI programmer
U0TXD (GPIO1) RXI     
U0RXD (GPIO3)TX0
GNDGND
5V 5V
GND and GPIO0 connected (for flashing only)   

Step by Step instruction

1.Preparations

We assume that you have the latest version the Arduino IDE and ESP32 add on installed in your Arduino IDE. You can read how to do it here – Basics: Project 137 Installing the ESP32 Board in Arduino IDE (Windows, Mac OS X, Linux). You can download the latest Arduino IDE version Windows Installer here. We are using PC with Windows 7 64 bit OS.

2.Uploading the code to ESP32-CAM

1.Do wiring. Very important: GPIO 0 (IO 0) must be connected to GND otherwise you will not be able to upload code.

2. Attach WiFi antenna (optional). It will help you to increase WiFi range.

3.Attach OV2640 camera.

4.Plug your FTDI programmer into your PC USB port.

5.Open Arduino IDE.

6.Go to Tools -> Board… -> ESP32 Arduino ->and select AI Thinker ESP32-CAM. Make sure you select the right camera module. In this project we use the AI-THINKER ESP32-CAM Development Board with camera. 

ESP32-CAM webserver

7.Go to Tools -> Port and select the COM port the ESP32-CAM Development Board connected to (we have COM3).

ESP32-CAM webserver

6. Open this sketch in your Arduino IDE, modify with your local network data (ssid and password).

ESP32-CAM webserver static IP address

7.Click the upload button in Arduino IDE to upload the sketch. When you see Uploading… message press the ESP32-CAM Development Board on-board RST (RESET) button to restart your ESP32 in flashing mode.

ESP32-CAM webserver static IP address

9.When uploading completed disconnect GPIO 0 from GND.

10.Open the Serial Monitor of Arduino IDE (Tools -> Serial Monitor) at the baud rate of 115200. Press the ESP32-CAM Development board on-board RST (RESET) button. The IP address defined in our code ( 192.168.0.114 ) should be assigned to your ESP32-CAM now.

ESP32-CAM webserver static IP address

11.You can access your camera streaming server on your local network. Open any internet browser (IE,Google Chrome,..) (We used Google Chrome) and type the ESP32-CAM Development board IP address (we have http://192.168.0.114).

ESP32-CAM webserver static IP address
ESP32-CAM webserver

Code

You need to set the local network credentials in the following variables:

const char* ssid = “yourSSIDhere”;
const char* password = “yourPASSWORDhere”;

Define the following variables with your own static IP address and corresponding gateway IP address before the setup() and loop() functions. By default, the next snippet assigns the IP address 192.168.0.114 that works in the gateway 192.168.0.1.

// We set a Static IP address
IPAddress local_IP(192, 168, 0, 114);
// We set a Gateway IP address
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);

// Optional
//IPAddress primaryDNS(8, 8, 8, 8); 
//IPAddress secondaryDNS(8, 8, 8, 4); 

In the setup(), we need to call the WiFi.config() method to assign the configurations to the ESP32-CAM before starting WiFi.

if(!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
  Serial.println("STA Failed to configure");
}

The primaryDNS and secondaryDNS parameters are optional and you can remove them.

if(!WiFi.config(local_IP, gateway, subnet)) {
  Serial.println("STA Failed to configure");
}

Wrapping up

We have learnt how to set static (fixed) IP address for ESP32-CAM.

Check for more DIY projects here.

Thank you for reading and supporting us.

Check for more DIY projects on Acoptex.lt and Acoptex.com!

If you are looking for high quality PCBs PCBWay is the best choice: