> For the complete documentation index, see [llms.txt](https://brlabelectronics.gitbook.io/tutorials-1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://brlabelectronics.gitbook.io/tutorials-1/the-app-code/writing-the-code/blynk_write.md).

# BLYNK\_WRITE()

BLYNK\_WRITE() is a function that is called each time that the device gets an update from the server for a virtual pin.&#x20;

Therefore this is the function we will use to read and then write the current virtual pin value we get from the Blynk cloud when you change it in the mobile app or web dashboard.&#x20;

{% code lineNumbers="true" %}

```arduino
BLYNK_WRITE(V0)
{
    if(param.asint() != relayState1)
    {
        relayState1 = !relayState1; // Toggle state
        // set the relay output pin to the state of the of relayState1 variable
        digitalWrite(relay1, relayState1); 
}
BLYNK_WRITE(V1)
{
    if(param.asint() != relayState2)
    {
        relayState2 = !relayState2; // Toggle state
        // set the relay output pin to the state of the of relayState2 variable
        digitalWrite(relay2, relayState2); 
}
BLYNK_WRITE(V2)
{
    if(param.asint() != relayState3)
    {
        relayState3 = !relayState3; // Toggle state
        // set the relay output pin to the state of the of relayState3 variable
        digitalWrite(relay3, relayState3); 
}
BLYNK_WRITE(V3)
{
    if(param.asint() != relayState4)
    {
        relayState4 = !relayState4; // Toggle state
        // set the relay output pin to the state of the of relayState4 variable
        digitalWrite(relay4, relayState4); 
}
```

{% endcode %}
