Zhengqian Kuang
Zhengqian Kuang

Reputation: 1109

ESP32 pin output not working with Arduino IDE

I was trying to setup my first ESP32 board with Arduino IDE. It works fine with built-in LED but does not work with pins. Here is my code:

int LED_BUILTIN = 2; // works fine
int LED_OUT = 25; // not working, even other pins

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(LED_OUT, OUTPUT);
  Serial.begin(115200);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  // turn the LED on (HIGH is the voltage level)
  delay(1000); // wait for a second
  digitalWrite(LED_BUILTIN, LOW);
  // turn the LED off by making the voltage LOW
  delay(1000); // wait for a second
  digitalWrite(LED_OUT, HIGH);
  // turn the LED on (HIGH is the voltage level)
  delay(1000); // wait for a second
  digitalWrite(LED_OUT, LOW);
  // turn the LED off by making the voltage LOW
  delay(1000); // wait for a second
}

The on-board built-in LED is blinking according to my code but GPIO 25 is not outputting anything. I tried other pins and found none of them works. I happened to try GPIO 4 and found it blinking together with the built-in LED. It seems like GPIO 4 is connected to the built-in LED.

So did I miss anything setting up the pin mode or whatever? How can I select a pin and make it work as output to blink my LED on breadboard?

Thanks in advance.

Upvotes: 3

Views: 10137

Answers (2)

Imran Mumtaz
Imran Mumtaz

Reputation: 39

Make sure the pinout diagram you are following matches with the board hardware you are using. You can do that by counting the number of pins in the diagram you're following and counting pins of your hardware. This is a simple check. Sometimes, you are using different version of the ESP32 board and following pinout of different version due to which it does not work. Pin 2 works fine because normally GPIO_2 is connected to build in led but others wouldn't work.

Upvotes: 0

Asad
Asad

Reputation: 31

  1. Make sure Positive(+ive) terminal is connected to Pin 25 .
  2. Make sure, Pin number matched with pin name printed on board, there are different variants. If you select ESP32-DEV module and use pin layout in following link, most probably it will work. esp32-arduino-pin-layout
static const uint8_t A18 = 25;

Upvotes: 3

Related Questions