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 build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

8 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

  2. Hi I m Ramesh. Currently I am working with esp32cam but I cannot connect to network it shows “Connecting………….” so on. SSID, password, speed wifi, good Usb everything is fine from my side but yet unable to connect. Please help me

  3. When I tried this with the suggested address and the gateway it did not work. I change to and and it worked because all the other devices use 192.168.0.nn. Not sure why. Can you explain?
    I would also like to know what the optional primary and secondary DNS line are for. Are they used if something else is already using 184? Please explain.

  4. Hi !! I would like to display ip adress of esp32 cam on mini oled . My project is portable so static ip won’t help . Can you help me ? Thanks in advance !!


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.