Send value to hardware from app based on an "if...then...else" condition

Hi

I have an ultrasonic distance sensor that is sending the distance to mobile app using virtualwrite and Bylnk timer and the value is displayed using the value widget. What I want to do is compare the value with a number such that if value > number then to write out back on a virtual pin back to the hardware.

The application is a tank with 2 joysticks one for each motor with an ultrasonic distance sensor. If the tank comes within a certain distance then the joystick values are overridden and set to 0. Since I do not think I can write directly to a virtual pin that has already been assigned to a widget i.e. the joysticks then my idea is just to write to another virtual pin (e.g. 1 or a zero) and use this value to override the motor controller.

This would require something like:
If (value>x) write 1 to a virtual pin else if (value<x) write 0 to the virtual pin

It looks as if Blynk Eventor might work. The alternative is to manage the process completely with in the ESP8266 but the disadvantage is that the x value would have to be hardcoded, updating the project in the phone is easier. It would be really nice if there was a keypad widget so I could enter a value to send to the ESP8266

First of all, there is nothing that can be done in Eventor that can’t also be done in code. In fact, the opposite is true - Eventor has a limited instruction set so doing this in code is much more powerful

No, that’s not true. You can input parameter via the app which can then be used as variables within your sketch, so the system can be as configurable as you want.

.I think you’re approaching the logic side of this the wrong way. This statement is incorrect:

You can do digital writes to the virtual pin(s) used by the joystick to set it’s position. Obviously is a person is controlling the joystick then this virtual write is immediately overwritten, but that’s not a problem. Your logic within the sketchy would disregard any forward input from the widget if the distance from an object is too close, the return the joystick to it’s neutral position (128,128 by default) when released.

It’s not the joystick that is controlling the motors directly. You are taking the values from the joystick and energising the motors accordingly - provided your safety requirements are being met.

Pete.

Hi
Thanks for your input.
“Input parameter via the app”.
I guess you are referring tot he terminal widget and although I could use a slider to get a value but this would be less flexible than
terminal.write(param.getBuffer(), param.getLength()); but I do not see how to directly access the buffer so that I can convert the string to a number or write the string to an OLED display

“You can do digital writes to the virtual pin(s) used by the joystick to set it’s position” I think we may looking at this from different ends. I was referring to be able to write to a virtual joystick pin in the app based on the app making an if then else decision which I see now cannot be done. I can move this if then else to the In the Arduino sketch if i can get the value sent by the Bylnk terminal widget and use this to set a flag which is used with in the Blynk.write to ignore the input while I stop and reverse the motors/turn then clear the flag.

TBH, the Terminal widget would be my last choice. If it’s a number that you want to input then the Numeric Input or Step H/V widgets would be a far better choice.

Do you understand how to obtain the value from widgets attached to virtual pins, when that value changes?
It’s done using the BLYNK_WRITE(vPin) command, more info about working with virtual pins here:

Pete.

I am happy with how to use Blynk in the Arduino Sketch. What I cannot find is any reference to a Numeric Input widget in the Blynk documentation or in the App.

Its not really documented, but it’s not really different to any other widget. You get the value into your sketch in exactly the same was as described in the link I provided.

Pete.

But where is it I do not see any numeric input widget to select in the mobile app or is it called something else in the app. Or are you just saying use the button widget to send a value.

Steve

Maybe a trip to the opticians is required?

Pete.

I think you are right, one of those cases where I couldn’t see it for looking, sorry to waste your time.

Steve

1 Like