How do you manually control the onboard blue LED for ESP32?

I’d like to be able to manually toggle the onboard blue LED for a ESP32 board. I believe it is under GPIO2. Anyone have an example of how to do this? I found some stuff related to ESP8266 boards, but not ESP32.

I have tried the following but it does not work:

light:
  - platform: monochromatic
    id: onboard_led_light
    output: onboard_led

output:
  - platform: ledc
    id: onboard_led
    pin:
      number: GPIO2

...

- lambda: |-
  id(onboard_led_light).turn_on();

...

If you’re just trying to turn it off/on here’s an example

output:
  - platform: gpio
    id: gpio_3V3
    pin: 2

  on_boot:
    - priority: 700
      then:
        lambda: |-
          // power for the dhts and keys (gpio)
          id(gpio_3V3).turn_on();

@micque

For some reason, this doesn’t seem to work for me. I am using board type esp32doit-devkit-v1

I’m not using that particular ESP32 board but from what I see the led should be hooked up to pin 2 like mine. Have you ever seen the led light up? Is it possible it is not functioning?

Yes, there is the main red LED for power and another blue led. I want to manually control the blue led. I can turn on the following for the standard status_led in esphome and the blue LED works for that purpose:

status_led:
  pin: GPIO2

Okay. And you defined the output platform as gpio, not ledc, right?

My own.

esphome:
  name: esp32_luanode_1
  platform: ESP32
  board: esp32doit-devkit-v1


status_led:
  pin:
     number: GPIO2
     inverted: TRUE

board type luanode esp32

I meant that you changed ledc to gpio here

output:
  - platform: gpio   # not ledc
    id: gpio_led
    pin: 2

and then called the lambda somewhere like this

lambda: |-
  id(gpio_led).turn_on();

Or if you inverted the signal like your status_led shows did you try turn_off() instead?

like

switch:
  - platform: gpio
    id: blue_led
    pin:
      number: GPIO2
      inverted: true

should work

this works on my lolin 32

binary_sensor:
  - platform: gpio
    name: "Keys Missing"
    id: "keys_missing"
    filters:
      - delayed_on_off: 1s
    pin:
      number: GPIO12
      mode: INPUT_PULLUP
    on_state:
      then:
        - if:
            condition:
              lambda: 'return id(keys_missing).state;'
            then:
              - switch.turn_off: onboardLED
            else:
              - switch.turn_on: onboardLED


switch:
  - platform: gpio
    name: "onboardLED"
    id: onboardLED
    pin:
      number: GPIO22
      inverted: True
      mode: OUTPUT
    restore_mode: ALWAYS_OFF

Yes, I tried the answer that you posted.

The first and most obvious thing would be to find a schematic for that board and look at it.

If you cannot find the schematic, trace the wiring to find out which gpio the led is connected to.

Isn’t it obviously on GPIO2 if the status_led works with:

status_led:
  pin: GPIO2

??

Here is the latest that I have tried and it is not turning on still.

switch:

  - platform: gpio
    id: onboard_led
    pin:
      number: GPIO2
      inverted: True
      mode: OUTPUT
    restore_mode: ALWAYS_OFF

binary_sensor:

  - platform: gpio
    name: "Test Button"
    pin:
      number: GPIO22
      mode: INPUT_PULLUP
      inverted: True
    on_click:
        then:
          - switch.turn_on: onboard_led
[13:18:24][D][binary_sensor:036]: 'Test Button': Sending state ON
[13:18:24][D][binary_sensor:036]: 'Test Button': Sending state OFF
[13:18:24][D][switch:021]: 'onboard_led' Turning ON.
[13:18:25][D][binary_sensor:036]: 'Test Button': Sending state ON
[13:18:25][D][binary_sensor:036]: 'Test Button': Sending state OFF
[13:18:25][D][switch:021]: 'onboard_led' Turning ON.

I see you turning gpio2 on have you ever explicitly tried turn_off? Just wondering since you have inverted the output.

Hah, that was it. Looks like it works with this final configuration.

switch:

  - platform: gpio
    id: onboard_led
    pin:
      number: GPIO2
      mode: OUTPUT
    restore_mode: ALWAYS_OFF

binary_sensor:

  - platform: gpio
    name: "Test Button"
    pin:
      number: GPIO22
      mode: INPUT_PULLUP
      inverted: True
    on_click:
        then:
          - switch.toggle: onboard_led

Thanks for the help.

2 Likes