Light switch with virtual pin

I need your help please.
I need to turn on a light with the “Widgets” “Time Imput” which only works with virtual pins (not digital), I have the light connected to the physical D2 pin of the ESP8266 (LoLin). this is my sketch
Thank you in advance for your great help!

[Unformatted code removed by moderator]

@leoquar8 please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:


Thank you very much for your quick response, I send code between ```

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//#include <SimpleTimer.h>
#include <DHT.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “vlKIPDZ2Oz2E6T3qwyv9S******”; //Enter the Auth code which was send by Blink

// Your WiFi credentials.
// Set password to “” for open networks.
char ssid[] = “ITC”; //Enter your WIFI Name
char pass[] = “********”; //Enter your WIFI Password

#define DHTPIN 2 // Digital pin 4

// Uncomment whatever type you’re using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301

SimpleTimer timer;

// This function sends Arduino’s up time every second to Virtual Pin (5).
// In the app, Widget’s reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

if (isnan(h) || isnan(t)) {
Serial.println(“Failed to read from DHT sensor!”);
// You can send any value at any time.
// Please don’t send more that 10 values per second.
Blynk.virtualWrite(V5, h); //V5 is for Humidity
Blynk.virtualWrite(V6, t); //V6 is for Temperature

void LUZ(){
int pinValue = !digitalRead(4);
if (pinValue == 1) {
Blynk.virtualWrite(V10, HIGH); //coloca a 1
} else {
Blynk.virtualWrite(V10, LOW); // coloca a 0

void setup()
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, ssid, pass);


// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);

void loop()
{; // Initiates Blynk; // Initiates SimpleTimer

Use the sketch builder time input example. In if statement do a digital write to your D2 pin. After that it should be pretty easy to add your DHT code to that.

Thank you very much for your answer daveblynk, what I do not understand is how to indicate to my program that the virual pin 10 corresponds to the physical pin D2. I would appreciate your help with this. Thank you

When the state of V10 changes, the callback function BLYNK_WRITE(V10) will be executed.

If you add this callback function to your code then you can then extract the value from the V10 widget using x=param.asInt()
x can then be tested to see if it is an On (1) or Off(0) and a digitalWrite(HIGH) or (LOW) used to control the status of your physical pin.

If you take a look at the examples in the Sketch Builder you’ll see how this works, and incorporate those examples into your code.