BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Writing data from hardware to Blynk

Hy blynkers,

I need your help. I have got an ESP32 with two switches and two LED´s. When I turn on switch1 the led1 and a led red in blynk schould turn on. When I turn on switch2 the led2 and led green in blynk schould turn on. The hardware already works correctly. But my code isn´t able to turn on any led an blynk. Here is my code:

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

BlynkTimer timer;

int Status_Tommy;
int pushButton1State;

int Status_Gabi;
int pushButton2State;



char auth[] = "XXX"; // Put your Auth Token here. (see Step 3 above)
char ssid[] = "XXX";    //WlAN Name
char pass[] = "XXX"; //WLAN Passwort



#define LED1      12  //red (Tommy)
#define LED2      13  //green (Gabi)


#define Button1     5   //Tommy
#define Button2    19   //Gabi


#define VPIN_BUTTON_1    V10
#define VPIN_BUTTON_2    V11




BLYNK_CONNECTED() {

  // Request the latest state from the server

  Blynk.syncVirtual(VPIN_BUTTON_1);
  Blynk.syncVirtual(VPIN_BUTTON_2);
}

// When App button is pushed - switch the state

void setup()
{

  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);

  pinMode(LED1, OUTPUT);
  pinMode(Button1, INPUT_PULLDOWN);
  digitalWrite(LED1, Status_Tommy);


  pinMode(LED2, OUTPUT);
  pinMode(Button2, INPUT_PULLDOWN);
  digitalWrite(LED2, Status_Gabi);



  // Setup a function to be called every 100 ms
  timer.setInterval(500L, checkPhysicalButton);
}

void checkPhysicalButton()
{
  if (digitalRead(Button1) == HIGH) {
    digitalWrite(LED1, HIGH);
    Blynk.virtualWrite(V10, HIGH);
  } else {
    Blynk.virtualWrite(V10, LOW);
    digitalWrite(LED1, LOW);
  }

  if (digitalRead(Button2) == HIGH) {
    digitalWrite(LED2, HIGH);

    // Update Button Widget
    Blynk.virtualWrite(V11, HIGH);

  } else {
    Blynk.virtualWrite(V11, LOW);
    digitalWrite(LED2, LOW);
  }
}

void loop()
{
  Blynk.run();
  timer.run();
}

Can you please help me?

@tommy1 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:
```

Pete.

HIGH in C++ is the same as the number 1.
LED widgets in Blynk have 256 brightness levels, from 0 (off) to 255 (maximum brightness).
Your code is isnstructing the Blynk LED widget to turn on at brightness level 1, which is so dim that it appears to be turned off.

Change HIGH to 255 and it will work fine.

Pete.

Hi Pete,

thank you very much! Now it works.