[Solved] Web PUT request for Button PUSH acts like Switch - doesn't stop / debounce / shut off -

Hi Dimitry and Team and Community people:

Using IFTTT to make a web PUT request to an Arduino UNO for a Button.
When i just push the button on my phone, it stops as expected when I let go. Perfect!
With the Web request, the button stays On for random amounts of time, often forever.

In IFTTT:
Request Code http://blynk-cloud.com:8080/-PERSONAL STRING THINGY - /pin/D9
JSON body is [“1”]

I’ve seen the Debounce threads but can’t find any answer for this.
Hope you have a hack to to fix this!

Best, Alex

I would advice you to ditch the direct controlling of a digital pin and use Virtual Pins. They seem to be more stable.

Thanks so much! I was about to start campaigning IFTTT to fix it!

I’m using the BlynkBlink sample to switch a relay.
How’d you recommend I do it with VPin instead?

Typical usage of a Vpin looks like (Arduino style):

BLYNK_WRITE(V0)
{
int blabla = param.asInt();
if(blabla == 1)
{
digitalWrite(D3, HIGH);
{
else
{
digitalWrite(D3, LOW);
}

You can probably see the advantage here for Vpins. You can combine more actions at the press of a button instead of directly just switching a pin on and off. Vpin’s for certain widgets can hold more values in the form of an arrray (see the ZeRGBa widget for example) or they can hold a limited range of numbers ( 0-10 on a slider, you can set that in the app). Loads of advantages in using them over directly controlling. And on the better hardware you get 128 Vpins! :wink:

@Lichtsignaal
Apologies, this is over my head: I tried copying this into the BlynkBlink and broke it. (was thinking it’s pseudo code but hoping it’d still work)

BlynkBlinkWORKS:61: error: ‘param’ was not declared in this scope
int blabla = param.asInt();
^
BlynkBlinkWORKS:62: error: expected unqualified-id before ‘if’
if (blabla == 1)
^
exit status 1
‘param’ was not declared in this scope

Actually, I looked at it and it should work. param.asInt() should get the value from the button attached to a widget on V0 (in the app).

I see I forgot one closing } bracket for the BLYNK_WRITE(V0), but other than that it should work.

It won’t compile. Keep getting errors, so I clearly did it wrong.
Thought this was supposed to be easy :slight_smile: Is there an example I could rip off?

Here are all the errors I get and below these are the sketch:
Thanks again for all your help!

Arduino: 1.6.13 (Mac OS X), Board: “Arduino/Genuino Uno”

In file included from /Users/Alex/Documents/Arduino/libraries/Blynk/src/Blynk/BlynkApi.h:17:0,
from /Users/Alex/Documents/Arduino/libraries/Blynk/src/BlynkApiArduino.h:14,
from /Users/Alex/Documents/Arduino/libraries/Blynk/src/Adapters/BlynkEthernet.h:18,
from /Users/Alex/Documents/Arduino/libraries/Blynk/src/BlynkSimpleEthernet.h:20,
from /Users/Alex/Downloads/Blynk_Release_v0.4.4 2/libraries/Blynk/examples/GettingStarted/BlynkBlink/BlynkBlink.ino:57:
/Users/Alex/Documents/Arduino/libraries/Blynk/src/Blynk/BlynkHandlers.h:155:5: error: expected initializer before ‘void’
void BlynkWidgetWrite ## pin (BlynkReq BLYNK_UNUSED &request, const BlynkParam BLYNK_UNUSED &param)
^
/Users/Alex/Documents/Arduino/libraries/Blynk/src/Blynk/BlynkHandlers.h:163:31: note: in expansion of macro ‘BLYNK_WRITE_2’
#define BLYNK_WRITE(pin) BLYNK_WRITE_2(pin)
^
/Users/Alex/Downloads/Blynk_Release_v0.4.4 2/libraries/Blynk/examples/GettingStarted/BlynkBlink/BlynkBlink.ino:68:1: note: in expansion of macro ‘BLYNK_WRITE’
BLYNK_WRITE(V0)
^
exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.

/*******************************************************************
Blynk lets you create beautiful drag-and-drop visual interfaces
for your projects in 5 minutes. And it works with almost every
hardware out there.

Docs, Tutorials, everything: http://www.blynk.cc
Github: http://github.com/blynkkk
Blynk Community: http://community.blynk.cc
Follow Us: http://www.facebook.com/blynkapp
http://twitter.com/blynk_app

Blynk library is licensed under MIT license
This example code is in public domain.


You’ll need, in general:

  • Blynk App (download from AppStore or Google Play)
  • Arduino UNO or similar microcontroller board
  • Decide how to connect Arduino to the Internet
    (USB, Ethernet, Wi-Fi, Bluetooth, …)

There is a bunch of great example sketches included to show you how to get
started. Think of them as LEGO bricks and combine them as you wish.
For example, take the Ethernet Shield sketch and combine it with the
Servo example, or choose a USB sketch and add a code from SendData
example.


Let’s turn ON your LED with Blynk!
In this example we’ll use Arduino UNO + Ethernet Shield

5 Steps guide:
(watch video tutorial here: )

  1. Connect LED to Pin 9
    ( http://arduino.cc/en/uploads/Tutorial/simplefade_bb.png )

In the Blynk App:
2. Create New Project
3. Email yourself Auth Token. You can do it later at any time
4. Add a Button Widget. Select Pin D9 in Widget’s Settings
5. Press Play icon. Enjoy Blynking!

You can find a QR code for easy setup of this project here:
https://github.com/blynkkk/blynk-library/tree/master/examples/GettingStarted/BlynkBlink

********************************************************************/

#define BLYNK_PRINT Serial // Enables Serial Monitor

// Following includes are for Arduino Ethernet Shield (W5100)
// If you’re using another shield, see Boards_* examples
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

char auth[] = “YourAuthToken”; // Put your Auth Token here. (see Step 3 above)

void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth); // Here your Arduino connects to the Blynk Cloud.
}

void loop()
BLYNK_WRITE(V0)
{
int blabla = param.asInt();
if(blabla == 1)
{
digitalWrite(D3, HIGH);
{
else
{
digitalWrite(D3, LOW);
}
Blynk.run(); // All the Blynk Magic happens here…

// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}

I see it al ready, you are doing it a bit wrong :slight_smile:

It should be:

BLYNK_WRITE(V0)
{
int blabla = param.asInt();
if(blabla == 1)
{
digitalWrite(D3, HIGH);
{
else
{
digitalWrite(D3, LOW);
}

void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth); // Here your Arduino connects to the Blynk Cloud.
}
void loop()
{
Blynk.run(); // All the Blynk Magic happens here...
}

BLYNK_WRITE is a function in it’s own, so it should be outside any other functions like loop or setup.

Thanks so much yet again @Lichtsignaal think we’re getting there! :sweat:
But where and how do I declare D3 in this context?
I now get this error when trying to compile (full sketch below it)

Arduino: 1.8.1 (Windows 10), Board: “Arduino/Genuino Uno”

C:\Users\ALEXSH~1\AppData\Local\Temp\arduino_modified_sketch_312792\BlynkBlink.ino: In function ‘void BlynkWidgetWrite0(BlynkReq&, const BlynkParam&)’:

BlynkBlink:65: error: ‘D3’ was not declared in this scope

digitalWrite(D3, HIGH);

          ^

BlynkBlink:67: error: expected ‘}’ before ‘else’

else

^

BlynkBlink:67: error: expected ‘}’ before ‘else’

BlynkBlink:69: error: ‘D3’ was not declared in this scope

digitalWrite(D3, LOW);

          ^

BlynkBlink:73: error: a function-definition is not allowed here before ‘{’ token

{

^

BlynkBlink:78: error: a function-definition is not allowed here before ‘{’ token

{

^

exit status 1
‘D3’ was not declared in this scope

/*******************************************************************
 Blynk lets you create beautiful drag-and-drop visual interfaces
 for your projects in 5 minutes. And it works with almost every
 hardware out there.

 Docs, Tutorials, everything:  http://www.blynk.cc
 Github:                       http://github.com/blynkkk
 Blynk Community:              http://community.blynk.cc
 Follow Us:                    http://www.facebook.com/blynkapp
                               http://twitter.com/blynk_app

 Blynk library is licensed under MIT license
 This example code is in public domain.

*********************************************************************

 You’ll need, in general:
  - Blynk App (download from AppStore or Google Play)
  - Arduino UNO or similar microcontroller board
  - Decide how to connect Arduino to the Internet
    (USB, Ethernet, Wi-Fi, Bluetooth, ...)

 There is a bunch of great example sketches included to show you how to get
 started. Think of them as LEGO bricks  and combine them as you wish.
 For example, take the Ethernet Shield sketch and combine it with the
 Servo example, or choose a USB sketch and add a code from SendData
 example.

*********************************************************************

 Let’s turn ON your LED with Blynk!
 In this example we'll use Arduino UNO + Ethernet Shield

 5 Steps guide:
 (watch video tutorial here: )

  1. Connect LED to Pin 9
  ( http://arduino.cc/en/uploads/Tutorial/simplefade_bb.png )

 In the Blynk App:
  2. Create New Project
  3. Email yourself Auth Token. You can do it later at any time
  4. Add a Button Widget. Select Pin D9 in Widget's Settings
  5. Press Play icon. Enjoy Blynking!

  You can find a QR code for easy setup of this project here:
  https://github.com/blynkkk/blynk-library/tree/master/examples/GettingStarted/BlynkBlink
    indent preformatted text by 4 spaces
********************************************************************/

#define BLYNK_PRINT Serial // Enables Serial Monitor

// Following includes are for Arduino Ethernet Shield (W5100)
// If you're using another shield, see Boards_* examples
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

char auth[] = "YourAuthToken"; // Put your Auth Token here. (see Step 3 above)
BLYNK_WRITE(V0)
{
int blabla = param.asInt();
if(blabla == 1)
{
digitalWrite(D3, HIGH);
{
else
{
digitalWrite(D3, LOW);
}

void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth); // Here your Arduino connects to the Blynk Cloud.
}
void loop()
{
Blynk.run(); // All the Blynk Magic happens here...
}

  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

Not sure about D3 but you have your braces messed up.
Replace

{
digitalWrite(D3, HIGH);
{
else
{
digitalWrite(D3, LOW);
}

With

   {
      digitalWrite(D3, HIGH);
   }
   else
   {
      digitalWrite(D3, LOW);
   }
}

just use 3 and not D3. I think there is an alias or something missing. 3 will also refer to the digital pin.

@Lichtsignaal @Costas
You are rockstars and thank you! Lots of progress. This now compiles and runs! :grin:
One problem though with the new VPin setup it still doesn’t turn off - ever - after IFTTT switches it on.

The button’s aware of it’s state and shows ‘ON’ in the app. It’s in ‘Push’ mode but acting like a ‘Switch’.

Ideally, I’d love to control how long it stays on once activated.
But if it acts like a Pushed the button briefly, that could be OK for this too.

Thanks yet again!

/*******************************************************************
Blynk lets you create beautiful drag-and-drop visual interfaces
for your projects in 5 minutes. And it works with almost every
hardware out there.

 Docs, Tutorials, everything:  http://www.blynk.cc
 Github:                       http://github.com/blynkkk
 Blynk Community:              http://community.blynk.cc
 Follow Us:                    http://www.facebook.com/blynkapp
                               http://twitter.com/blynk_app

 Blynk library is licensed under MIT license
 This example code is in public domain.

*********************************************************************

 You’ll need, in general:
  - Blynk App (download from AppStore or Google Play)
  - Arduino UNO or similar microcontroller board
  - Decide how to connect Arduino to the Internet
    (USB, Ethernet, Wi-Fi, Bluetooth, ...)

 There is a bunch of great example sketches included to show you how to get
 started. Think of them as LEGO bricks  and combine them as you wish.
 For example, take the Ethernet Shield sketch and combine it with the
 Servo example, or choose a USB sketch and add a code from SendData
 example.

*********************************************************************

 Let’s turn ON your LED with Blynk!
 In this example we'll use Arduino UNO + Ethernet Shield

 5 Steps guide:
 (watch video tutorial here: )

  1. Connect LED to Pin 9
  ( http://arduino.cc/en/uploads/Tutorial/simplefade_bb.png )

 In the Blynk App:
  2. Create New Project
  3. Email yourself Auth Token. You can do it later at any time
  4. Add a Button Widget. Select Pin D9 in Widget's Settings
  5. Press Play icon. Enjoy Blynking!

  You can find a QR code for easy setup of this project here:
  https://github.com/blynkkk/blynk-library/tree/master/examples/GettingStarted/BlynkBlink
    indent preformatted text by 4 spaces
********************************************************************/

#define BLYNK_PRINT Serial // Enables Serial Monitor

// Following includes are for Arduino Ethernet Shield (W5100)
// If you're using another shield, see Boards_* examples
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

char auth[] = "AuthCodeHere"; // Put your Auth Token here. (see Step 3 above)

BLYNK_WRITE(V0)
{
int blabla = param.asInt();
if(blabla == 1)
{
      digitalWrite(3, HIGH);
   }
   else
   {
      digitalWrite(3, LOW);
   }
}

void setup()
{
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(3, OUTPUT);

Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth); // Here your Arduino connects to the Blynk Cloud.
}
void loop()
{
Blynk.run(); // All the Blynk Magic happens here...
}

  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!

It would seem, from my understanding, that when you use the HTTP API, you dont get a button simulation,
so in order to solve it you must simulate the button behavior.
In comes the SimpleTimer library (Basically a must for blynk, learn it!)

from IFTTT send another value, perhaps a ‘2’

Download and install SimpleTimer library if you don’t have it already.

Study code changes below

#define BLYNK_PRINT Serial // Enables Serial Monitor

// Following includes are for Arduino Ethernet Shield (W5100)
// If you're using another shield, see Boards_* examples
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>

char auth[] = "AuthCodeHere"; // Put your Auth Token here. (see Step 3 above)
SimpleTimer timer;
int buttonSimMillis = 500; // 500 miliseconds simulation

BLYNK_WRITE(V0)
{
int blabla = param.asInt();
if(blabla == 2)
{
      digitalWrite(3, HIGH);
      timer.setTimeout(buttonSimMillis, buttonOff); // This will call the function buttonOff after 
                                                    //buttonSimMillis duration specified above
}
else
    if(blabla == 1)
    {
        digitalWrite(3, HIGH);
    }
    else
    {
        digitalWrite(3, LOW);
    }
      
}

void buttonOff()
{
     digitalWrite(3, LOW);
}

void setup()
{
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(3, OUTPUT);

Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth); // Here your Arduino connects to the Blynk Cloud.
}
void loop()
{
Blynk.run(); // All the Blynk Magic happens here...
}

Thanks, @Fetkeewl !
I didn’t quite ‘study’ it - but I did copy your code :slight_smile: after making sure the library’s installed and IFTTT now PUTs 2 to the Vpin.

It didn’t work, sadly. It still stays on forever.
Below’s the copy / paste of the whole sketch again.

/*******************************************************************
 Blynk lets you create beautiful drag-and-drop visual interfaces
 for your projects in 5 minutes. And it works with almost every
 hardware out there.

 Docs, Tutorials, everything:  http://www.blynk.cc
 Github:                       http://github.com/blynkkk
 Blynk Community:              http://community.blynk.cc
 Follow Us:                    http://www.facebook.com/blynkapp
                               http://twitter.com/blynk_app

 Blynk library is licensed under MIT license
 This example code is in public domain.

*********************************************************************

 You’ll need, in general:
  - Blynk App (download from AppStore or Google Play)
  - Arduino UNO or similar microcontroller board
  - Decide how to connect Arduino to the Internet
    (USB, Ethernet, Wi-Fi, Bluetooth, ...)

 There is a bunch of great example sketches included to show you how to get
 started. Think of them as LEGO bricks  and combine them as you wish.
 For example, take the Ethernet Shield sketch and combine it with the
 Servo example, or choose a USB sketch and add a code from SendData
 example.

*********************************************************************

 Let’s turn ON your LED with Blynk!
 In this example we'll use Arduino UNO + Ethernet Shield

 5 Steps guide:
 (watch video tutorial here: )

  1. Connect LED to Pin 9
  ( http://arduino.cc/en/uploads/Tutorial/simplefade_bb.png )

 In the Blynk App:
  2. Create New Project
  3. Email yourself Auth Token. You can do it later at any time
  4. Add a Button Widget. Select Pin D9 in Widget's Settings
  5. Press Play icon. Enjoy Blynking!

  You can find a QR code for easy setup of this project here:
  https://github.com/blynkkk/blynk-library/tree/master/examples/GettingStarted/BlynkBlink
    indent preformatted text by 4 spaces
********************************************************************/

#define BLYNK_PRINT Serial // Enables Serial Monitor

// Following includes are for Arduino Ethernet Shield (W5100)
// If you're using another shield, see Boards_* examples
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>

char auth[] = "a66cbb0139bf410c9a107a067b9bf7dc"; // Put your Auth Token here. (see Step 3 above)
SimpleTimer timer;
int buttonSimMillis = 500; // 500 miliseconds simulation

BLYNK_WRITE(V0)
{
int blabla = param.asInt();
if(blabla == 2)
{
      digitalWrite(3, HIGH);
      timer.setTimeout(buttonSimMillis, buttonOff); // This will call the function buttonOff after 
                                                    //buttonSimMillis duration specified above

   }
   else
   if(blabla == 1)
   {
      digitalWrite(3, HIGH);
     }
    else
    {
        digitalWrite(3, LOW);
    }
      
}

void buttonOff()
{
     digitalWrite(3, LOW);
}

void setup()
{
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(3, OUTPUT);

Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth); // Here your Arduino connects to the Blynk Cloud.
}
void loop()
{
Blynk.run(); // All the Blynk Magic happens here...
}

  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!

Apologies, add timer.run();
To your loop, I think that is all that’s missing. Somehow I guess it wouldn’t be needed for timer.setTimeout but perhaps it is.

[SOLVED]

Wanted to make sure to say Big Thanks to you and the Community. This works as I need now. For future reference of everyone, here’s how we’re using SimpleTimer to debounce / turn-off the Blynk button after IFTTT activates it!

/*******************************************************************
Blynk lets you create beautiful drag-and-drop visual interfaces
for your projects in 5 minutes. And it works with almost every
hardware out there.

Docs, Tutorials, everything: http://www.blynk.cc
Github: http://github.com/blynkkk
Blynk Community: http://community.blynk.cc
Follow Us: http://www.facebook.com/blynkapp
http://twitter.com/blynk_app

Blynk library is licensed under MIT license
This example code is in public domain.


You’ll need, in general:

  • Blynk App (download from AppStore or Google Play)
  • Arduino UNO or similar microcontroller board
  • Decide how to connect Arduino to the Internet
    (USB, Ethernet, Wi-Fi, Bluetooth, …)

There is a bunch of great example sketches included to show you how to get
started. Think of them as LEGO bricks and combine them as you wish.
For example, take the Ethernet Shield sketch and combine it with the
Servo example, or choose a USB sketch and add a code from SendData
example.


Let’s turn ON your LED with Blynk!
In this example we’ll use Arduino UNO + Ethernet Shield

5 Steps guide:
(watch video tutorial here: )

  1. Connect LED to Pin 9
    ( http://arduino.cc/en/uploads/Tutorial/simplefade_bb.png )

In the Blynk App:
2. Create New Project
3. Email yourself Auth Token. You can do it later at any time
4. Add a Button Widget. Select Pin D9 in Widget’s Settings
5. Press Play icon. Enjoy Blynking!

You can find a QR code for easy setup of this project here:
https://github.com/blynkkk/blynk-library/tree/master/examples/GettingStarted/BlynkBlink
indent preformatted text by 4 spaces
********************************************************************/

#define BLYNK_PRINT Serial // Enables Serial Monitor

// Following includes are for Arduino Ethernet Shield (W5100)
// If you’re using another shield, see Boards_* examples
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>

char auth[] = “YourAuthCodeHere”; // Put your Auth Token here. (see Step 3 above)
SimpleTimer timer;
int buttonSimMillis = 15000; // 500 miliseconds simulation

BLYNK_WRITE(V0)
{
int blabla = param.asInt();
if (blabla == 2)
{
digitalWrite(3, HIGH);
timer.setTimeout(buttonSimMillis, buttonOff); // This will call the function buttonOff after
//buttonSimMillis duration specified above

}
else if (blabla == 1)
{
digitalWrite(3, HIGH);
}
else
{
digitalWrite(3, LOW);
}

}

void buttonOff()
{
digitalWrite(3, LOW);
}

void setup()
{
// initialize digital pin LED_BUILTIN as an output.
pinMode(3, OUTPUT);

Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth); // Here your Arduino connects to the Blynk Cloud.
}
void loop()
{
timer.run();
Blynk.run(); // All the Blynk Magic happens here…
}

// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!