ESP32 LiPo/First code/06. Blink the LED on GPIO 22
First code · 06 of 13

Blink the LED on GPIO 22

One board setting — ESP32 Dev Module — and a sketch that names its pin. The on-board LED is on GPIO 22 and lights when the pin is LOW, which is the opposite of most tutorials, and ESP32 Dev Module does not define LED_BUILTIN at all.

Set up the IDE once

Install the ESP32 boards in the Arduino IDE if you have not already — installing the toolchain covers it. Then three rows in the Tools menu:

Tools rowSet it to
Boardesp32 → ESP32 Dev Module
PortThe CH340 port: /dev/cu.usbserial-… on a Mac, COM… on Windows
Upload Speed921600, or 115200 if uploads stop partway

ESP32 Dev Module is the generic board for a classic ESP32 with 4 MB of flash, which is exactly what this is. The other rows can stay at their defaults.

Upload it

Paste the sketch, press Upload, and watch the bottom of the window. It finds the chip, reports an ESP32-D0WDQ6, writes the sketch and resets the board. The on-board LED should blink twice a second.

LOW is on

The LED on GPIO 22 lights when the pin is LOW
digitalWrite(22, LOW)
The sketch says
GPIO 22
0.0 V
Across LED + resistor
3.3 V
LED
on
LOW is on. The pin at 0 V leaves 3.3 V across the LED and its resistor, so current flows from the rail, through the LED and into the pin. The pin is the switch at the bottom of the LED, not the supply at the top.

The LED is wired so that the pin switches its ground end. Pull GPIO 22 LOW and current flows from 3.3 V through the LED into the pin; set it HIGH and both ends are at 3.3 V, so nothing flows. It is common on small ESP32 boards and it catches everyone once: a sketch that says "turn the LED on at the start" leaves it off.

If the upload stops partway

The log that means "slow down":

Changing baud rate to 921600...
Changed.
A fatal error occurred: The chip stopped responding.

The chip was found and talking, so the wiring and the driver are fine. The fast speed is not getting through — usually the cable. Tools → Upload Speed → 115200 and try again.

The code

blink_gpio22.ino

Blinks the on-board LED twice a second. Nothing to wire: USB-C to the computer is all it needs, with or without a cell.

// Lonely Binary ESP32 LiPo board: blink the on-board LED.
//
// Wiring: none. The LED is on the board, on GPIO 22.
//   USB-C -> the computer, for power and the upload
//
// Arduino IDE:
//   Tools > Board        > esp32 > ESP32 Dev Module
//   Tools > Port         > the CH340 port (usbserial on a Mac, COM on Windows)
//   Tools > Upload Speed > 921600, or 115200 if the upload stops partway

const int LED = 22;  // LOW lights it

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

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

The current ESP32 core does not define LED_BUILTIN for ESP32 Dev Module, so the IDE's own Blink example stops with an error. That is why this sketch names 22 itself. LOW is on.

When it does not work

The upload stops at 'Changing baud rate to 921600'

The chip is found, then stops answering at the fast upload speed — esptool says 'The chip stopped responding'. Set Tools > Upload Speed to 115200 and upload again. A shorter cable or a different USB port often lets 921600 work.

The upload cannot connect to the chip at all

The board has no BOOT button; the IDE uses the USB chip to put it into upload mode. If that fails, hold a jumper wire from GPIO 0 to GND, press and release RST, start the upload, and remove the wire once it says Writing.

'LED_BUILTIN' was not declared in this scope

The IDE's Blink example uses LED_BUILTIN, and ESP32 Dev Module does not define it in the current ESP32 core. Replace LED_BUILTIN with 22, or use the sketch on this page.

It uploaded, and the LED does nothing

The sketch drives pin 2, as many ESP32 tutorials do, because that is where a DevKit v1 has its LED. This board has nothing on GPIO 2. Change the pin number to 22.

There is no port to choose

That is a cable, a driver or the way up the USB-C plug is. The next article takes them in that order.

Where this goes next

A cable, a driver, or a USB-C plug that works one way up.

When the port will not appear

Edit this page — content/books/esplipo/blink-gpio-22.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

ESP32 LiPo Dev Kit: 3 Boards with LiPo Charger + 3 Shields

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum