Approved, not published yet. Visible on the preview site only.

Build your own Wi-Fi LED strip dimmer with an ESP32

An ESP32 LED dimmer for 12 V or 24 V strips: parts and rough prices, safe wiring, the ESPHome config, and how to fix the common hum and flicker problems.

Hardware8 min read

A living room at dusk with a warm cove light running along the ceiling

It is nine in the evening and the ceiling cove is at full brightness, because the strip's supply has one setting: on.

Most LED strips are installed with a supply and a plain on/off switch. A small Wi-Fi board, a MOSFET and a page of configuration will dim any ordinary 12 V or 24 V strip from a phone, a wall button or Home Assistant. Here is what to buy, how to wire it and what to watch for.

Why build one, and when not to

One of the main reasons we build these in house: very few ready-made controllers handle high-power strips drawing several amps per channel, and the ones that do are either cheap and poorly made or very expensive. Most also need the maker's cloud and give you no say in how they fade or how low they go. The parts here come to about ₹600 to ₹1,000, and nothing leaves your network.

Do not build one if:

  • The strip runs on mains. 230 V LED rope lights and strips that plug straight into the wall run on rectified mains. None of these parts are rated for that. Use a dimmer made for mains LED lighting, or replace the strip with a low-voltage one.
  • You want no responsibility for the electrical side. If you do not want to size the fuse and the wire, buy a certified controller.
  • Your strip is addressable (WS2812B, SK6812, anything with a data wire). Those are dimmed through the data line, not by PWM on the supply; use WLED or an ESPHome addressable light instead. A MOSFET dimmer will not work on them.

How dimming works

The controller does not lower the voltage. It switches the full voltage on and off very fast, varying how much of each cycle is "on": pulse width modulation, or PWM. At 30 percent on, the strip gives roughly 30 percent of its light, and your eye blends the pulses into a steady glow.

The switch is a MOSFET in the strip's negative wire. The ESP32 drives its gate, and it connects and disconnects the strip from ground thousands of times a second.

Parts

You already have the strip and its 12 V or 24 V supply, sized for the strip's draw. If you are buying the strip now, buy the supply with it. Prices below are approximate Indian retail ranges and vary by seller.

  • ESP32 development board. We used a full-size 30-pin ESP32 DevKit. The budget option is an ESP32-C3 Super Mini: cheaper, much smaller and runs the same configuration. It has fewer pins, so count them before planning RGB.
  • MOSFET switch module that accepts a 3.3 V trigger (we used a small dual-MOSFET "XY-MOS" type), or a bare logic-level MOSFET. About ₹100 to ₹250 per channel.
  • Buck converter to make 5 V for the ESP32 from 12 V or 24 V. About ₹50 to ₹100.
  • Inline fuse and holder for the positive feed. About ₹50.
  • Wire of the right thickness, plus ferrules. A few hundred rupees.

Avoid the common "IRF520 module". It is sold for microcontroller projects, but the IRF520 is not a logic-level part. From a 3.3 V pin it only half switches, runs hot and never lets the strip reach full brightness.

Buy a module that states a 3.3 V trigger instead, or a bare logic-level MOSFET of the AOD4184 or IRLZ44N class whose datasheet quotes on-resistance at 2.5 V or 3.3 V gate drive. With a bare part, add about 100 Ω between pin and gate plus a 10 kΩ pull-down from gate to ground so the strip stays off while the board boots. For long, heavy runs, a gate driver chip removes most of the problems below.

Single-colour dimmer wiring: power supply, fuse, MOSFET module, buck converter, ESP32 and strip, with the controller ground on the module's input negative
Single-colour dimmer wiring: power supply, fuse, MOSFET module, buck converter, ESP32 and strip, with the controller ground on the module's input negative

How to build it

  1. Size the supply. Strips are rated in watts per metre; use the figure on your reel. Watts per metre × metres gives total watts, divided by voltage gives current. For example, 5 m at 14.4 W per metre on 12 V is 72 W, or 6 A; at 80 percent loading a common 12 V 10 A supply fits.

    Watts per metre depend on the LED type, not the count; many strips draw 5 to 15 W per metre. For RGB, size for white, all three colours at full. When it is right, the supply is warm, not hot, after an hour at full brightness.

  2. Choose 24 V for runs over about 5 m. Same power, half the current, so thinner wire, less voltage drop and less heat in the MOSFET.

  3. Plan power injection. Feed long strips at both ends, or inject every few metres with a pair of wires back to the supply. On a ring such as a cove, also join the two ends of the ring. All positive feeds come from the supply side; all strip negatives return to the MOSFET output.

  4. Fit the fuse. Put it in the positive wire right at the supply output, rated a little above the strip's full-load current and no higher than the wire can carry.

  5. Set the buck converter. Adjust it to 5 V with a meter before connecting the ESP32's VIN pin.

  6. Wire the ground to the input side. The MOSFET module has an input negative (VIN-) and an output negative (OUT-). The ESP32 ground goes to VIN-, which is the supply's own ground. OUT- is the switched strip return; a controller grounded there floats with the PWM and behaves oddly. The buck converter's negative input is the same point as VIN-.

  7. Pick a safe pin. Avoid the boot strapping pins (GPIO 0, 2, 5, 12 and 15 on the classic ESP32; GPIO 2, 8 and 9 on the C3), or the strip may flash at power-up. We used GPIO16; on a C3 Super Mini, GPIO4 works. When it is right, the strip stays dark while the board boots.

  8. Flash ESPHome. Flash once over USB with the configuration below; later updates go over Wi-Fi. Home Assistant discovers the device; accept it and a light with a brightness slider appears.

  9. Find the floor. Temporarily set min_power: 0 and gamma_correct: 1.0, then lower the brightness in Home Assistant one step at a time until the strip goes out. The lowest level that still lights evenly is your min_power (ours was 0.006, about duty 6 of 1023). Put gamma_correct back to 2.2. With the floor set, 1 percent on the slider is a faint but steady glow and 0 percent is properly off.

A long strip fed from both ends, with both negative returns going through the dimmer
A long strip fed from both ends, with both negative returns going through the dimmer

The ESPHome configuration

Our test firmware drives the ESP32's LEDC hardware at 20 kHz with 10-bit resolution (0 to 1023), a gamma of 2.2 and a floor of duty 6 out of 1023. Our own test ring is a 12 V cove drawing about 6.3 A: a dual-MOSFET XY-MOS module (two AOD4184) on GPIO16 with the controller ground on its VIN-, an MP1584 buck set to 5 V, a 10 A fuse and a 12 V 25 A supply, well oversized. On the bench it is silent at 20 kHz. The ESPHome YAML below reproduces the same settings; ESPHome picks the PWM resolution itself.

esphome:
  name: led-dimmer

esp32:
  board: esp32dev   # C3 Super Mini: esp32-c3-devkitm-1

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

api:
  encryption:
    key: !secret api_key

ota:
  - platform: esphome
    password: !secret ota_password

output:
  - platform: ledc
    id: strip_pwm
    pin: GPIO16
    frequency: 20000Hz
    min_power: 0.006        # floor: about duty 6 of 1023, find yours by testing
    zero_means_zero: true   # 0 % is really off

light:
  - platform: monochromatic
    id: strip
    name: "LED strip"
    output: strip_pwm
    gamma_correct: 2.2
    default_transition_length: 1s
    restore_mode: RESTORE_DEFAULT_OFF

ESPHome's default gamma is 2.8; try both and keep what looks even. restore_mode decides what happens after a power cut.

For RGB you need three MOSFET channels, one per colour wire, with the strip's positive common to all. Add three ledc outputs (for example GPIO16, 17 and 18) at the same 20 kHz and floor, then a light with platform: rgb naming them as red, green and blue.

For a wall switch, wire a momentary push button between GPIO19 and ground, and add:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO19
      mode:
        input: true
        pullup: true
      inverted: true
    name: "Wall button"
    filters:
      - delayed_on: 20ms
    on_click:
      - light.toggle: strip

It works even when Wi-Fi or the hub is down, and a push button, unlike a latching switch, never disagrees with the app.

Slider position against PWM duty: a straight line versus a gamma 2.2 curve that starts at a small floor above zero
Slider position against PWM duty: a straight line versus a gamma 2.2 curve that starts at a small floor above zero

What goes wrong

  • The supply whines at mid brightness. Our first test at about 1.2 kHz hummed across the room. Fix: raise PWM to 20 kHz, above most people's hearing.
  • The bottom of the slider does nothing, then the strip jumps on. At 20 kHz the pulses are very short, and a MOSFET driven gently from 3.3 V cannot switch on the shortest ones. Fix: set a floor (step 9). A gate driver lowers it further.
  • Half brightness looks almost like full. Eyes are far more sensitive at the dark end. Fix: gamma correction, 2.2 as a starting point.
  • The MOSFET is too hot to touch. It is not switching fully or is overloaded. Fix: a logic-level part or a gate driver, and real current margin.
  • One section never switches off. An extra negative wire runs straight to the supply, bypassing the MOSFET. Fix: every strip negative returns through the MOSFET output.
  • The far end is dim or orange. Voltage drop. Fix: thicker feed wire, power at both ends, or 24 V.
  • The strip flashes at power-up. Strapping pin or missing gate pull-down. Fix: step 7.

Safety

A 12 V supply that can deliver 15 A can melt a thin wire and start a fire. Fuse the positive feed, size the wire and give the supply and MOSFET some air. Any work on the mains side, including wiring the supply into a lighting circuit, should be done by a licensed electrician, with the circuit tested dead first.

Cost and time

With the full-size board, the board, buck and MOSFET module came to about ₹600 for us; a C3 Super Mini brings that to about ₹400. The fuse and wire add a couple of hundred rupees, all on top of the strip and its supply. RGB adds two MOSFET channels, about ₹200 to ₹500 more. Expect an afternoon to build and an evening to tune; RGB adds about an hour.

The short version

Size the supply with headroom, use 24 V for long runs, feed both ends, fuse it, ground the controller on VIN-, run PWM at 20 kHz with gamma 2.2 and a tested floor. Our test cove now dims silently to the bottom.

TDH Systems designs custom lighting and automation hardware. See what we automate.

Written by Siddharth Agrawal, Founder and Director, TDH Systems.

Tell us what you have in mind. We will come back with a plan and a quote.

Start a project

Prefer email? Write to info@thydarkhour.com.