How to Get the MAC Address of an ESP-01

 

The MAC (Media Access Control) address is a unique identifier assigned to network interfaces for communications on the physical network segment. In the world of IoT, it’s crucial to know the MAC address of your devices for various reasons, such as network troubleshooting, device identification, and secure communication. In this blog post, we will guide you through the process of obtaining the MAC address of an ESP-01 module and provide some troubleshooting tips.

 

Materials Needed

  1. ESP-01 Module  (Affiliate) – https://s.click.aliexpress.com/e/_DETsfWR
  2. USB ESP-01 Programming Adapter with a CH340G chip (Affiliate) – https://s.click.aliexpress.com/e/_DETsfWR
  3. Computer with Arduino IDE installed

Step 1: Setting Up the Arduino IDE for ESP8266

The Arduino IDE doesn’t support the ESP8266 platform by default, so we need to add it:

 

 

 

 

 

 

 

 

 

  • Go to Tools -> Board -> Boards Manager, search for ESP8266 and install it.

 

 

 

 

 

Selecting the correct ESP8266 board:

  • Go to Tools > Board.
  • Find and select your specific board that is the Generic Esp8266

 

 

Step 2: Setting Up the Hardware

 

To put the CH340G adapter in programming mode, follow these steps:

  • Before plugging the USB ESP-01 programming adapter into a USB port on your computer, Press and hold the push button switch that you soldered in Step 2 for a few seconds.
  • Plug the USB ESP-01 programming adapter into a USB port on your computer with the button pressed.
  • Release the button: After a few seconds, release the push button switch. The Esp-01 should be in programming mode, and you can upload code to the ESP-01 module using your preferred development environment.

 

If having trouble, go to my previous blog post. It explains with images: https://www.edgemicrotech.com/preparing-the-usb-esp-01-programming-adapter-a-step-by-step-guide/

 

Step 3: Code -> Version 1

This code will make the Mac address appear on the serial monitor only once.

  • The code inside the IF statement will run only once because the boolean variable STOP is switched to false. The void loop function will continue to run but won’t do anything else.

 

#include <ESP8266WiFi.h>

boolean stop= true;

void setup() {
}

void loop() {
  delay(1000);
  if (stop == true) {    
    Serial.begin(115200);
    delay(1000);
    Serial.println();
    Serial.print("MAC address: ");
    Serial.println(WiFi.macAddress());
  }
  stop = false;

}

 

Step 3: Code -> Version 2 (Beginners should use this version)

This code will make the mac address appear on the serial monitor every approx. 2 seconds.

 

#include <ESP8266WiFi.h>


void setup() {
}

void loop() {
    delay(1000);   
    Serial.begin(115200);
    delay(1000);
    Serial.println();
    Serial.print("MAC address: ");
    Serial.println(WiFi.macAddress());
}

 

 

Step 4: Uploading the Code and Getting the MAC Address

After the programming of the board is successful, remove the adapter from the USB port and insert it again (without pressing the button). Pay attention to the serial monitor; the Mac address should appear.

 

 

Troubleshooting

 

If you encounter any issues while trying to obtain the MAC address of the ESP-01, here are some troubleshooting tips:
  1. No MAC address is printed to the serial monitor: Make sure the baud rate of the serial monitor matches the baud rate specified in the Serial.begin() function in your code (115200 in the example code). Try using the Version 2 of the code.
  2. The code fails to upload to the ESP-01: Make sure the correct board (Generic ESP8266 Module) and PORT are selected in the Tools menu. If you are using the adapter, follow the steps of the previous blog post to put it in programming mode: https://www.edgemicrotech.com/preparing-the-usb-esp-01-programming-adapter-a-step-by-step-guide/

 

Conclusion

In this blog post, we have shown you how to obtain the MAC address of an ESP-01 module and provided some troubleshooting tips. Knowing the MAC address of your devices is crucial for network troubleshooting, device identification, and secure communication. We hope you found this guide helpful and encourage you to experiment with the ESP-01 and other ESP8266-based modules in your own projects.