Unsteady flickering ESP32 PWM dimmed led lights

I’m using a quite straightforward configuration for a ESP32­ WROOM­ 32 microcontroller for dimming 12 V DC Christmas LED lights via a RFP30N06LE mosfet transistor. I’m using the ledc module for controlling the mosfet through a hardware PWM channel from the esp32, essentially nothing more than the code example from the esphome documentation for the ledc module.

But unfortunately the LEDs are flickering unsteady, when dimmed (but not at 100% brightness), similar to real candles. While this may be a desired effect for Christmas lights for some people, I find it very irritating. :slight_smile:

Changing the PWM frequency doesn’t help against this unsteady flickering “effect”.

I’m suspecting a problem with the microcontroller not being able to accuratly maintaining the PWM frequency, causing the LEDs to flicker, but tbh. the sole reason I chose a esp32 with it’s hardware PWMs for such a simple task, was to avoid exactly such problems I’d expect from an underpowered esp8266 trying to maintian a software controlled PWM. :roll_eyes:

I’m using two H801 led controllers with esphome firmware for dimming other LED lights, that didn’t show any unsteady flickering at all, even if the PWM signals are software controlled in these devices.

Does anyone have an idea, what could cause this flickering and how I could get rid of it?

This is my config:

esphome:
  name: ${node_name}

esp32:
  board: esp32dev
  framework:
    type: arduino

substitutions:
  node_name: weihnachtsbaumlicht
  node_friendly_name: Weihnachtsbaumlicht

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  domain: !secret wifi_domain
  
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${node_friendly_name} AP"
    password: !secret wifi_ap_password

captive_portal:

logger:

ota:
  password: !secret ota_password_weihnachtsbaumlicht

mqtt:
  broker: !secret mqtt_broker
  username: !secret mqtt_username
  password: !secret mqtt_password
  
  on_message:
   - topic: ${node_name}/pwm_frequency
     then:
       - output.ledc.set_frequency:
           id: gpio_19
           frequency: !lambda 'return parse_number<float>(x).value();'

binary_sensor:
  - platform: status
    name: "${node_friendly_name} MQTT Status"

light:
  - platform: monochromatic
    output: gpio_19
    name: ${node_friendly_name}
    default_transition_length: 500ms
    
output:
  - platform: ledc
    pin: GPIO19
    id: gpio_19

sensor:
  - platform: wifi_signal
    name: "${node_friendly_name} WiFi"
    filters:
      - filter_out: nan

switch:
  - platform: restart
    name: "${node_friendly_name} Restart"
    
text_sensor:
  - platform: version
    name: "${node_friendly_name} ESPHome Version"

It should.

Unlikely, the ESP32 uses a hardware PWM module, completely independent of the processor clock.

Well, maybe it’s actually a problem with the power supply. I tried powering the lights with another supply (borrowed from my aquarium lights) and with that the flickering seems to be less obvious, although still visible especially on low brightness values.

The power supply I wanted to use should provide more than enough power needed for the lights, but could this be caused by the current provided from the supply not being smoothed enough and causing an interference between the frequency from the power supply and the pwm frequency?

Indeed, the power supply seems to be crucial for the problem. I also tested this with a second supply, which also doesn’t produce this obvious flickering. I’m now using the flicker inducing power supply with a non-dimmable LED strip for which it’s just working fine and the other one for the Christmas lights. :+1:

2 Likes