Skip to content

First ESP32 project

Getting started with embedded development is much easier if you can see something happen on your board.
In this page you will wire a simple circuit, upload your first sketch, and make an LED react to a button.

We assume you are using an ESP32-S3 DevKit‑style board and a breadboard.


Prerequisites

Find the following items, most of these items are already in your embedded kit:

  • ESP32-S3 DevKit board
  • USB‑C cable to connect the ESP32-S3 DevKit to your computer.
    • This cable is not included in the kit.
  • Breadboard
    • In your embedded kit you will find two breadboards, the ESP32-S3 DevKit does not fit in one breadboard.
  • 1× LED (any color)
  • 1× 220 Ω resistor (anything between 150–330 Ω is fine)
  • 1× push button
  • A few male–male jumper wires

3.3 V only

⚠️ The ESP32 runs at 3.3 V logic. Do not connect 5 V signals directly to GPIO pins.


The easiest way to get started and to see something happen is to blink the built-in LED. Almost all Arduino boards have a built-in LED, but to control it you need to know the pin number.

Instead of knowing the pin number, you can use the LED_BUILTIN constant.

const int LED_PIN = LED_BUILTIN;

To make a fully functional sketch, you need to add the setup() and loop() functions. The setup() function is called once when the board starts, and the loop() function is called repeatedly.

The setup() function is used to initialize the LED pin as an output. The loop() function is used to blink the LED.

Here is the complete sketch:

// First ESP32 sketch: blink the built-in LED

const int LED_PIN = LED_BUILTIN;  // Built-in LED on many ESP32-S3 DevKit boards

void setup() {
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, HIGH); // LED on
  delay(500);
  digitalWrite(LED_PIN, LOW);  // LED off
  delay(500);
}

Upload the sketch. If the LED does not blink:

  • Check that the correct board (e.g. ESP32-S3 Dev Module) is selected.
  • Check that the correct port is selected.
  • Try pressing the EN/RESET button on the board after upload.

Using the Breadboards with the ESP32-S3 DevKit

To make use of the full functionality of the ESP32-S3 DevKit, you will need to use two breadboards. Otherwise you only have access to the GPIO pins on one side of the board.

We recommend to take off one side of the smaller breadboard and place it next to the larger breadboard.

Using both breadboards


External LED on a breadboard

Successfully made the built-in LED blink? Now let’s connect a separate LED to the breadboard. Connecting a separate LED makes pin usage more explicit.

Wire the LED like this:

  • Connect the long leg (anode) of the LED to a free GPIO pin, for example GPIO 25.
  • Put a 220 Ω resistor between the short leg (cathode) and GND.

Update your sketch:

const int LED_PIN = 25;  // External LED on GPIO 25

void setup() {
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, HIGH);
  delay(300);
  digitalWrite(LED_PIN, LOW);
  delay(300);
}

Is your LED reversed?

If nothing happens, try swapping the LED around: the long leg should go to the GPIO pin via the resistor, the short leg to GND.


Add a button to control the LED

Now add a push button so the LED only turns on while you press it.

Use the internal pull‑up resistor of the ESP32 to simplify wiring:

  • Connect one side of the button to GPIO 26.
  • Connect the other side of the button to GND.

Use this sketch:

const int LED_PIN    = 25; // external LED
const int BUTTON_PIN = 26; // button connected between GPIO 26 and GND

void setup() {
  pinMode(LED_PIN, OUTPUT);

  // Enable the internal pull-up resistor on the button pin
  pinMode(BUTTON_PIN, INPUT_PULLUP);
}

void loop() {
  // With INPUT_PULLUP, the pin reads HIGH when not pressed, LOW when pressed
  int buttonState = digitalRead(BUTTON_PIN);

  if (buttonState == LOW) {       // button pressed
    digitalWrite(LED_PIN, HIGH);  // LED on
  } else {
    digitalWrite(LED_PIN, LOW);   // LED off
  }
}

Next steps

From here you can:

  • Replace the LED with a buzzer or relay.
  • Read a sensor value (for example an LDR or potentiometer) and use it to control the LED.
  • Combine this page with Serial Monitor and communication protocols to send sensor data to your laptop or the web.