ESP32 fails to boot when a sensor is on GPIO 12 (MTDI)

GPIO 12 is a strapping pin on many ESP32 modules, and a high level at reset selects the wrong flash voltage. Move the signal to a safer pin.

What the message means

ESP32 chips read strapping pins at reset to set boot options. On common 3.3 V flash modules GPIO 12 must be low at reset. A pull-up or a sensor driving it high can cause boot failure.

Fix it in this order

  1. Disconnect the part from GPIO 12 and reset. If the board boots, the pin was the cause.
  2. Move the signal to a general-purpose pin such as 16, 17, 18, 19, 21 or 22 where your board allows.
  3. Avoid pull-ups on GPIO 12. Use a pull-down if you must keep it.
  4. Check the strapping pins on your own board data: 0, 2, 5, 12 and 15.

Why it happens

GPIO 12 (MTDI) is a strapping pin on the classic ESP32. Its level at reset selects the flash voltage. If something pulls it high during boot, such as a sensor or a pull-up, the chip can fail to boot with a flash error.

Disconnect whatever is on GPIO 12 and try again. For a permanent fix, move the signal to another pin. Keeping GPIO 12 low at boot is the safe default on the common 3.3 V flash modules.

If you see this, do this

You seeDo this
Boots without the partMove the part to another pin.
Still fails bareSee the invalid header page.

invalid header, ESP32 pinout for robotics.

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.

Why this happens

On the classic ESP32 the pin GPIO 12, also called MTDI, is sampled at reset. The level decides the voltage of the internal supply that feeds the flash chip. Low selects 3.3 V and high selects 1.8 V. Most common modules use 3.3 V flash, so if something pulls the pin high during reset the flash is given the wrong voltage and the ROM loader cannot read it. The serial log then shows a flash read error or the board stays in a reset loop.

The sampling happens only for a moment at reset. After the program starts the pin behaves like any other, so the trouble appears only on power-up or reset, and a board can seem to work once it is running. A sensor with a pull-up resistor, or one that powers up before the ESP32 and drives its output high, is enough to cause it.

How to confirm the cause

  • Disconnect everything from GPIO 12, press reset and read the boot text on the serial monitor at 115200 baud. If a clean start appears, the pin was the cause.
  • Reconnect only the part you suspect. If the failure returns, that part is pulling the pin high at reset.
  • Measure the pin to ground with a multimeter while the board is held in reset. A level near 0 V is what you want. A level near 3.3 V is the fault.
  • Look for a pull-up on the sensor board, such as a 10 k resistor from the signal line to the supply.
  • Check the datasheet of your exact module. A few modules use different flash, so confirm the voltage it expects.

Worked example

Moving the signal to another pin is the clean fix. This sketch reads a digital sensor on GPIO 27 instead of 12, and it can be tested on the same board once the wire is moved.

const int SENSOR_PIN = 27;   // was GPIO 12
void setup() {
  Serial.begin(115200);
  pinMode(SENSOR_PIN, INPUT);
}
void loop() {
  Serial.println(digitalRead(SENSOR_PIN));
  delay(500);
}

Common mistakes

  • Adding an external pull-up on GPIO 12 for I2C or a button.
  • Changing the pin in the sketch but leaving the old wire in place.
  • Trusting that other boards’ pin labels are the same, as the silkscreen and the module can differ.
  • Treating every boot loop as a flash fault without reading the serial text first.

If this did not fix it

  • The other strapping pins, GPIO 0, 2, 5 and 15, which also affect boot.
  • The power supply: a brownout during start-up gives resets that look similar.
  • A damaged or wrongly written flash, which needs the board erased and reflashed.