#define BLYNK_TEMPLATE_ID "TMPL6KZ7o3XCg"
#define BLYNK_TEMPLATE_NAME "PWM LAMP"
#define BLYNK_AUTH_TOKEN "5euf8IVIosQ6kJk42_-hLGNPLNkMpJaW"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#define pin_led 23 // LED pin
#define LEDC_CHANNEL 0 // LEDC channel
// Your WiFi credentials.
// Set password to "" for open networks.
#define WIFI_AP "Wokwi-GUEST"
#define WIFI_PASS ""
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = WIFI_AP;
char pass[] = WIFI_PASS;
// This function will be called every time Slider Widget in Blynk app writes values to the Virtual Pin V0
BLYNK_WRITE(V0) {
int pinValue = param.asInt(); // Assigning incoming value from pin V0 to a variable
// You can also use: int pinValue = param[0].asInt();
// Write the value to the LED pin
ledcWrite(LEDC_CHANNEL, pinValue);
}
void setup() {
Serial.begin(115200);
Serial.println("Starting Blynk LED control");
// Setup WiFi
Blynk.begin(auth, ssid, pass);
// Initialize LED hardware
ledcSetup(LEDC_CHANNEL, 5000, 8); // Set up PWM channel
ledcAttachPin(pin_led, LEDC_CHANNEL); // Attach the channel to the GPIO to be controlled
}
void loop() {
Blynk.run(); // Initiates Blynk
}