LED Strip dimming

Hi, I tried to adjust the brightness of the white-led strip with the slider from the Blynk app and esp32. But when I move the slider just a little bit, the led strip lights up to the maximum brightness, so it’s just like the on/off button.

#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Blynk.h>

#define w 26

char auth[] = "";
char ssid[] = "";
char pass[] = "";

void setup()
  Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8080);

  pinMode(w, OUTPUT);

  int pinv = param.asInt();

  digitalWrite(w, pinv);

void loop()

I know something is missing in my code but don’t know what else to add.
(sorry for bad english, translated from google)

Hey there,
Blynk legacy or IOT ?

blynk legacy

Try this tutorial

Change digitalWrite to analogWrite.

1 Like

Thank you for the advice

actually esp32 doesn’t support analogwrite that’s why I used digitalwrite, but after reading your reply I searched the internet and found the analogwrite library for esp32, and it solved my problem.
Thanks for the advice.

That would be the solution with an ESP8266, but the ESP32 doesn’t support analogWrite. Instead you have to use ledcSetup(ledChannel, freq, resolution) and ledcAttachPin(GPIO, channel) then ledcWrite(channel, dutycycle) to do the dimming.

Of course, you’ll kill your ESP32 almost immediately if you attach any substantial length of 5v LED strip directly to your ESP32, and it will never run at full brightness anyway - because it needs 5v rather than the 3.3v that the ESP32 outputs.
You need to use a suitable MOSFET to achieve the correct result and to protect your ESP32.


Check this article

I just found a library for esp32 to run analogwrite.


It’s only really useful if you’re trying to re-use code written for the ESP8266 or Arduino boards and you don’t want to make too many changes to your sketch.
Otherwise the ESP32 commands are straightforward to use.


Ah, ESP32, yeah i should have realized from the includes … Sorry

// Thanks for the good ol’ 8266 … :slight_smile:

Interesting thing with the ESP8266…

I recently updated the code on one of my ESP8266 based RGB dimmers and suddenly they went to full brightness at 255 rather than 1023. After lots of head-scratching, I realised that recent versions of the ESP core (V3.0.0 onwards I think) changed the way that digitalWrite works - to make it backwards compatible with Arduino hardware.
This can be overridden, or even changed to 0-65k, but you can waste a lot of time if you don’t know about the change.


Great info Pete.

Im still on 2.7.1 …
As I have noted other problems on 3.n.n using PubSubClient. But that’s another story.

That’s interesting, what PubSub liens issues have you encountered?

I do get a compiler informational warning with PubSubClient and the latest 3.x.x core, but nothing to worry about.


I dont exactly rememeber but my notes say:

// NOTE:
// Sketch tested OK with pubsubclient=2.8.0 and esp8266=2.7.1 (with esp8266=2.5 tz setting will not compile)
// Sketch CRASHES with pubsublient=2.8.0 and esp8266=3.0.2

The code this happens for uses PUBLISH (and no SUBSCRIBE) but also provides a WEB SERVER for browser access.

The tz comment is about timezones which was fixed in other arduino libs after 2.5.