Skip to main content

More about Blynk

More about Blynk

Blynk also offers several advanced features that you can use to enhance your ESP32 project, such as:

  • Virtual Pins: Virtual pins are pins that do not correspond to physical pins on your ESP32 but are linked to virtual pins in your Blynk project. You can use virtual pins to exchange various types of data between your ESP32 and Blynk app, such as strings, arrays, or custom objects. Virtual pins also allow you to implement custom functions and logic for your ESP32, such as timers, triggers, and actions. To use virtual pins, you need to use the BLYNK_WRITE(), Blynk.virtualWrite(), and BLYNK_READ() functions, as explained in the previous section.

  • Blynk.syncVirtual(): This function synchronizes the value of a virtual pin between your ESP32 and your Blynk app. You can use this function to update widget values in your Blynk app with values from your ESP32, or vice versa. This function can also trigger the BLYNK_WRITE() or BLYNK_READ() callback functions for the virtual pin. You need to specify the virtual pin number as a parameter. Example:

    // Sync the value of pin V6 from ESP32 to the Blynk app
    Blynk.syncVirtual(V6);
    // Sync the value of pin V7 from the Blynk app to ESP32
    // This will also execute the BLYNK_WRITE(V7) callback function
    Blynk.syncVirtual(V7);
    
  • Custom Functions: Custom functions are functions that you can define in your Arduino sketch to perform specific tasks or actions for your ESP32. You can use custom functions to implement complex logic and behavior for your ESP32, such as controlling multiple devices, performing calculations, sending notifications, and more. Custom functions can also handle events from your Blynk app, such as pressing buttons, moving sliders, or sending commands. To use custom functions, use the BLYNK_WRITE() function to call the custom function and pass the widget value as a parameter. Example:

    // Define a custom function to blink an LED
    void blinkLED(int value) {
      // Turn on the LED
      digitalWrite(LED_BUILTIN, HIGH);
      // Wait for the specified value in milliseconds
      delay(value);
      // Turn off the LED
      digitalWrite(LED_BUILTIN, LOW);
      // Wait for the specified value in milliseconds
      delay(value);
    }
    
    // Call the custom function from pin V8
    BLYNK_WRITE(V8) {
      // Get the value from the widget
      int value = param.asInt();
      // Call the custom function
      blinkLED(value);
    }