How to blink an ESP32 onboard LED (Mac)

In this article I show you how to blink the onboard LED of an ESP32 Dev Kit board. These instructions were written using a Mac, but can easily be adapted for Windows.

To blink the onboard LED of an ESP32 Dev Kit board you can program it like an Arduino board. Once you add support for the board to the Arduino IDE, you can write and run a simple blink example.

In the steps below, I will show you how to do that.

Where to buy

Several manufacturers create their own version of the ESP32 board. If you would like to use the one that I used for this article, you can buy it from Amazon in the US using my affiliate link:

The model I use has a micro-USB connection. So I used a cable from one of my Android devices. You could try this cable:

Step 1. Plug the ESP32 into your Mac

The first thing that you need to do is plug the ESP32 board into your Mac. The board will be powered by the USB cable for this example. So you won’t need an external power supply.

  • Plug the USB cable into your laptop
  • Plug the USB cable into your ESP32 board
  • Confirm the power LED on the board is on (on my board it is a red LED)

Step 2. Download the Arduino IDE

This article was tested using the Arduino IDE version 1.8.10.

Mac Instructions

  • Double click the *.zip file to extract the application
  • Copy the Arduino app to the Applications folder

Step 3: Configure the Arduino IDE for ESP32 boards

This step was adapted from the Espressif arduino-esp32 repo.

  • Start the Arduino IDE
  • From the main menu select Arduino > Preferences…
  • For Additional Board Manager URLs enter in the field on its own line:
    https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
    
  • Select Tools > Board: * > Boards Manager…
  • Type in esp32
  • You should see a listing for esp32 by Espressif Systems
  • Click Install
  • Click Close

Step 4. Select your board

  • Select Tools > Board: *
  • Select your board (I selected ESP32 Dev Modules)

Step 5: Paste the code into the IDE

Paste the code below into the IDE window. You can completely replace any existing example or setup code that is already there:

#define ONBOARD_LED  2
 
void setup() {
  pinMode(ONBOARD_LED,OUTPUT);
}
 
void loop() {
  delay(1000);
  digitalWrite(ONBOARD_LED,HIGH);
  delay(100);
  digitalWrite(ONBOARD_LED,LOW);
}

Code description

  • The setup function sets up the onboard LED as an output pin, so it can be turned on and off
  • The loop repeatedly turns the LED on and off by toggling the voltage level between HIGH and LOW
  • Delays are used to control how quickly the LED turns on and off

Step 6: Upload the code to the ESP32

  • Click the Upload button (the right pointing arrow in the IDE tool bar)

Some versions of ESP32 boards require pressing the boot button on the device to upload new programs. Even a reviewer on Amazon said they had to do it for the board I used. But I did not and someone else said they did not either.

Step 7: Verify it works

  • Verify that you see the onboard LED blinking on and off

On my board the LED is blue.

Next step

You can experiment with this simple example by changing the delay values and uploading new code to the device. Make the delay different enough so that you can confirm that your changes are working.

Conclusion

The ESP32 board is part of a family of open hardware devices. Not all devices look or act the same but they are based on the same chipset. So if you are using a different device you may get different results.

Treating the ESP32 board as an Arduino is only one option. But a good place to start as a beginner.

See my related articles, where I show how to blink the LED for other types of Arduino board.

References

  • Arduino core for the ESP32 [1]



About the Author

Mitch Allen works for a robotics company in New England.