Blynk App Virtual Pin Read


I am using ESP32 with the PWM led. I want to control led by Blynk slider widget. I am reading reading V1 value. How to use int pinValue from V1 in loop function for ledcWrite

char auth[] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Network";
char pass[] = "password";

public BLYNK_WRITE(V1)
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  return 0;

void setup()
  // Debug console

  Blynk.begin(auth, ssid, pass);

void loop()
  ledcWrite(0, value);


Declare a global variable
Assign value to this variable in Blynk Read
Write it to led pin inside of Blynk Read


This might help


Thanks for your help.
So for my red led, code will be like this

int rrr,

  //===== RGB LED pin setup for ESP32 =====
  ledcSetup(2, 5000, 8); // For RGB-Red - channel 2, 5000 Hz, 8-bit width
  ledcAttachPin(25, 2);   // For RGB-Red - GPIO 25 assigned to channel 2

BLYNK_WRITE(V4) { // START Blynk Function
  rrr = param[0].asInt();

void RGBprocess() { 
ledcWrite(2, 256 - rrr);

  // zeRGBa pin to #HEX conversion
  String strRED = String(rrr, HEX);  // Convert RED DEC to HEX
  if (rrr < 16) {
    strRED = String("0" + strRED);  // Buffer with 0 if required
  }  // END if
}  // END Arduino Function

void loop() {;


Thanks for your help. I want to get value from app for the slider in my arduino code and want to use it in ledcWrite function call in loop function.


@davidkhan My example was a bit more complex becasue it was using the zeRGBa and mapping to HEX for changing widget colours

But if all you want to do is adjust the PWM range of a single LED with a slider on the ESP32 then it can be as simple as this (with the required ESP channel and frequency settings of course)…

ledcWrite(ledChannel, param.asInt());

Using the 8-bit range, you set your sliders MIN-MAX to 0-255, or perhaps 255-0 for inversely driven pins… adjust the range for higher bit rates if wanted, e.g. 10bit and 0-1024 or 12 bit 0-4096 for servos, etc.


Thanks Gunner for your help. Now controlling PWM on esp32 with Blynk slider.