ESP32C3 Permanent MAC Address Change
What’s In This Page
This is a step by step guide that shows you how to change the MAC Address of an ESP32c3 and in a way that the change is permanent.
If you are using a phone, at the bottom of the page there are links to many supplies for modelers. Otherwise those links are in the sidebar to the right. You can also find other information by using the search function that is in the navigation bar above.
The Latest Information
Anything new and page updates are posted on X (formerly Twitter), Rumble and Facebook.
It is easy to keep up with the latest by following us on either of them.
The Guide
Open Arduino IDE.
Connect ESP32-C3 to Computer.
Go to Tools.
Tools – Board – ESP32 Arduino – ESP32C3 Dev Module
——————————————————
Find the Existing MAC Address
Create A new Sketch
Name it Find Existing MAC Address
#include <WiFi.h>
void setuo() {
Serial.begin(115200);
WiFi.mode(WIFI_MODE_STA);
Serial.print(“Original MAC: “);
Serial.println(WiFi.macAddress());
}
void loop() {
}
—————————————————————–
Read Current MAC Address
Open Serial Monitor
Read MAC Address that looks like:
Original MAC 7C:DF:A1:12:34:56
—————————————————————-
Create A Permanent Custom MAC System
Create A New Sketch
Name the sketch “Change ESP32-c3 MAC Permanently”
This is an example that sets MAC Address for Loco1
It will be upload.
#include <WiFi.h>
#include <Preferences.h>
#include “esp_wifi.h”
Preferences prefs;
unit8_t defaultMAC[6] = {
0x02, 0xAA, 0xBB, 0xCC, 0xDD, 0x01
//change the last term to another Loco number and upload to change to the new MAC address.
};
void loadMAC(unit8_t* mac) {
prefs.begin(“macstore”, true);
if (prefs.isKey(“mac”)} {
prefs.getBytes(“mac”, mac, 6);
} else {
memcpy(mac, defaultMAC, 6);
}
prefs.end();
}
void saveMAC(unit8_t* mac) {
prefs.begin(“macstore”, false);
prefs.putBytes(“mac”, mac, 6);
prefs.end();
}
void setup(){
Serial.begin(115200);
unit8_t mac[6];
loadMAC(mac);
WiFi.mode(WIFI_MODE_STA);
esp_wifi_set_mac(WIFI_IF_STA, mac);
Serial.print(“Active MAC: “);
Serial.printf(“%02X:%02X:%02X:%02X:%02X:%02X\n”,
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
saveMAC(mac);
}
void loop(){}
—————————————————–
Upload and open the Serial Monitor
The serial monitor should show Active MAC: 02:AA:BB:CC:DD:01
//the last term will show the Mac Address now on the ESP32-c3
————————————————–
Free Help
If you have questions, comments or need help with this ,or any other project, or animating your own diorama or train layout scene, either go to our Free Help page click on the button to the right.

