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

Reading Value from a widget and using it in hardware function

Hey everyone,

i have a question for my Project (ESP8266, Blynk 0.6.1).
First of all what i’ve done so far:
I am using the “Numeric Input” widget to print a number to a “value display” widget. It is because i want to adjust a certain water amount. For example when i write in the “Numeric Input” widget 5, the “Value Display” widget prints out 5L.

Now my problem:
I want to work with this certain amount of water to use it in an if-function controlling a Hardware component. For example if-function: if the “Value Display” (Blynk app) prints out 5L, the digital pin for a LED on the hardware side goes HIGH.

All in all my aim is, that my ESP8266 reads the value of the “Value Display” widget from Blynk app to use it for an if-function on hardway side.

Is this even possible? If not, is there any other way to solve my problem?

I would really appreciate it, if somebody helps me with this issue.
I am looking forward to a response.

Best regards
Timo

You’re taking the wrong approach here, based on what you’ve written about the numeric input widget.

You should attach your numeric input widget to a virtual pin, and whenever its value changes it will trigger the BLYNK_WRITE(virtual pin number) callback.
You can then capture the value from the numeric input widget using the parm.asInt or parm.asFloat function and save it to a variable (preferably a global variable).

This variable can then be used in your if statement.

When your ESP device starts-up you’ll want to get the current value from the numeric input widget (without having to change the value). This can be done using the BLYNK_CONNECTED callback and a Blynk.sync(virtual pin number) function.

The Sketch Builder includes some examples of code that can help to point you in the right direction.
https://examples.blynk.cc

Pete.

Pete, I’m eternally grateful. I’ve got it together now thanks to your advice.
By the way, I love how fast you responded.

Thanks a lot.
Timo

1 Like

No problems!
The Blynk functionality can be a bit difficult to grasp at first, so a few pointers in the right direction can be handy. Glad it was of help to you and that you were able to run with these ideas.

Pete.