ESP32 MAC Address (Get & Change) in Arduino IDE

In this tutorial, you’ll learn how to Get the ESP32 MAC Address and how to Change the ESP32 MAC Address in Arduino IDE. The ESP32 WiFi MAC address is hard-coded in hardware by the manufacturer but it can be changed in software (temporarily) which we’ll learn to do in this tutorial.

Before proceeding with this tutorial, you should have installed the ESP32 Arduino Core in your Arduino IDE to be able to compile and build projects for ESP32 in Arduino IDE. Follow the tutorial below to get started if you haven’t done that already.

If you’re just starting with ESP32, it’s highly recommended to begin with the following tutorial to kickstart your journey with ESP32 microcontrollers. Then, go to the second link which directs you to the main page for ESP32 Tutorials Series, where you’ll find all ESP32 tutorials ordered and categorized in a logical way that guarantees you systematic progress in learning ESP32 programming and IoT.

Table of Contents

  1. ESP32 MAC Address
  2. Get ESP32 MAC Address
  3. Why To Change ESP32 MAC Address?
  4. Change ESP32 MAC Address (Arduino IDE)
  5. Concluding Remarks

ESP32 MAC Address

The MAC address is a unique identifier address that gets assigned to each device that will be connected to other networks by the manufacturer on a hardware level. This means it’s a unique ID for each device on the network and it takes the following form: 25:3A:42:CE:B7:FF (for example).

It’s a 6-Bytes array each byte of which is represented by 2 hexadecimal digits that can take any value between (0…9-A…F). And it doesn’t matter if the letters are upper-case or lower-case. The MAC address: 25:3A:42:CE:B7:FF is perfectly the same as 25:3a:42:ce:b7:ff MAC address.

Changing the MAC address is possible though, but it’s only on a software level. You need to do the same software configuration in each application where a custom MAC address is needed. Because the real hardware MAC address of the device is permanently assigned to the hardware by the manufacturer already and it can’t be changed in hardware.

Get ESP32 MAC Address

The MAC address of the ESP32 can be easily obtained using the WiFi library that’s already built into the Arduino Core for ESP32. You need to call the WiFi.macAddress() function that returns the MAC address in the form of a 6-byte array formatted as a string.

Here’s an example code that demonstrates how to get the MAC address of the ESP32:

And this is the result after running this code on my ESP32 board. You may need to restart your ESP32 if you didn’t catch the message on the serial monitor on the first run.


Why To Change ESP32 MAC Address?

In some applications, it can be interesting to change the MAC address of the ESP32 and set it to a custom value. Some networks may have an active MAC filter that doesn’t allow unknown devices to connect to it. Therefore, changing the MAC address can allow it to connect to a network if you’ve got a white-listed MAC address already available.

There are many possible applications in which you may need to change the WiFi MAC address for your ESP32 board. But keep in mind that it’s only a temporary change that gets whipped out when the ESP32 is restarted.

Change ESP32 MAC Address (Arduino IDE)

To change the ESP32 MAC address in Arduino IDE, you can use the esp_wifi_set_mac()function from the esp_wifi.h library. Which takes the WiFi mode and the MAC address array as arguments.

Here is an example code for MAC Address change to a custom address in Arduino IDE.

This was the result on the serial terminal after running this example code on my ESP32 board.


So we’ve now successfully changed the MAC address.

❕ Note

The MAC Address Change is temporary and it gets whipped out when the ESP32 is restarted. You need to include the same code for changing the MAC address in each application where it’s needed. Otherwise, the ESP32 default MAC address will be the effective address of the device.

ESP32 MAC Address Doesn’t Change

Sometimes you may not be able to change the MAC address to a custom address that you’ve made up. The most common reason behind this is that the ESP32 MAC address doesn’t accept a new address that has a 1 in the bit number 0 of the first byte.

Here is an example to demonstrate this: the MAC address C2:xx:xx:xx:xx:xx is acceptable by the ESP32, while the C3:xx:xx:xx:xx:xx MAC address is not. Because of the value of Bit-0, if it’s a 1, the address will be neglected, and if it’s a 0, the address will be confirmed and updated.

Parts List

Here is the full components list for all parts that you’d need in order to perform the practical LABs mentioned here in this article and for the whole ESP32 series of tutorials found here on DeepBlueMbedded. Please, note that those are affiliate links and we’ll receive a small commission on your purchase at no additional cost to you, and it’d definitely support our work.

Concluding Remarks

To conclude this tutorial, we’ll highlight the fact that the MAC address is hard-coded in the hardware itself by the ESP32’s manufacturer. But it can be changed by software which is not a permanent change. Restarting the ESP32 will make it revert to the hardware’s default MAC address.

If you’re just starting to learn about ESP32 WiFi, it’s highly recommended that you follow the tutorial below and keep it bookmarked in your browser. It is crafted specifically to help beginners with ESP32 WiFi to know everything about this huge topic and draw a clear roadmap for what to learn in a systematic way.

You can easily get overwhelmed when starting with ESP32 WiFi by the number of topics and libraries out there (e.g HTTP, TCP/IP, UDP, WebServers, AsyncWebServers, WebSocket, MQTT, ESP-NOW, etc…). There are too many libraries, modes, topologies, and protocols that make just getting started an even harder task than it should be. And the most reasonable question is where should I get started? The guide below is the perfect answer!

???? Also Read
ESP32 WiFi Tutorial & Library Examples

This is the ultimate guide for ESP32 WiFi, if you’re just starting with ESP32 WiFi, you should definitely check it out. It’ll provide you with a clear roadmap for what to learn and in which order to fully understand everything about ESP32 WiFi.

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

Leave a Comment