ESP32-CAM: Set Static/Fixed IP Address (Arduino IDE)

This tutorial shows how to set a static/fixed IP address for your ESP32-CAM board. If you’re running a web server or Wi-Fi client with your ESP32-CAM and every time you restart your board, it has a new IP address, you can follow this tutorial to assign a static/fixed IP address.

ESP32-CAM Set Static Fixed IP Address Arduino IDE

Static/Fixed IP Address Sketch

To show you how to fix your ESP32-CAM IP address, we’ll use the CameraWebServer Example that comes with the Arduino IDE.

By the end of our explanation you should be able to fix your IP address regardless of the web server or Wi-Fi project you’re building.

In your Arduino IDE, go to File > Examples > ESP32 > Camera > CameraWebServer.
Then, modify the code to fix the IP address as we’ll explain.

Setting ESP8266 Static IP Address

Before the setup() and loop() functions, define the following variables with your own static IP address and corresponding gateway IP address.

By default, the next snippet assigns the IP address that works in the gateway

// Set your Static IP address
IPAddress local_IP(192, 168, 1, 184);
// Set your Gateway IP address
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional

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

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

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

You can download the complete code for this project here. It assigns the static IP address You just need to insert your network credentials and the code will work straight away.


After uploading the code to your board, open the Arduino IDE Serial Monitor at the baud rate 115200. Restart your ESP32-CAM board and the IP address defined earlier should be assigned to your board.

ESP32-CAM Set a Static IP Address Demonstration Serial Monitor

As you can see, it prints the IP address

Now, you can access that IP address on your local network to watch the video streaming web server.

Wrapping Up

In this tutorial, you’ve learned how to set up a static IP address for your ESP32-CAM. You can use what you’ve learned here in any of your ESP32-CAM sketches.

If you like the ESP32-CAM, take a look at our resources:

Thanks for reading.

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our weekly newsletter!

3 thoughts on “ESP32-CAM: Set Static/Fixed IP Address (Arduino IDE)”

  1. hi,

    thank you very much for this Tutorial, long time I was searching in that case, now every thing are clearly

    great work!

    all the best
    kind regards form Likya


Leave a Comment

Download our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.