I’m trying to control robot path through UP, DOWN, LEFT and RIGHT through buttons in Blynk connected to virtual pins in Arduino. Is there any way I can push multiple commands under IF LOOP activating when virtual pin ==1 ?
Don’t forget to read the documentation
Try to stay away from blocking codes inside this function… but this is the normal way to use Virtual Pin control.
http://docs.blynk.cc/#blynk-main-operations-virtual-pins
BLYNK_WRITE(Vx) //Button Widget is writing to pin Vx
{
if (param.asInt() == 1) { // activate next commands when button pressed ON
// Do stuff here
// and here
// even here
}
}
thx, but there is one more problem when i tried to upload the code it says the following error (same appears for BareMinimum code):
Arduino: 1.8.3 (Windows 10), Board: “Arduino/Genuino Uno”
Archiving built core (caching) in: C:\Users\ANISHG~1\AppData\Local\Temp\arduino_cache_129790\core\core_arduino_avr_uno_4f102434c573a4283b83ba95af927dff.a
Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can’t open device “\.\COM3”: The semaphore timeout period has expired.
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
I have uploaded several codes in arduino before and they worked but it’s the first time this has happened. I checked port from device manager and its COM3 my arduino is updated and i also tried restarting my pc and changing arduino usb cable but nothing works…
Restarting windows worked for it.
For Virtual pin problem, it is still not working…
Here’s my code:
int ma1=2;
int mb1=3;
int ma2=7;
int mb2=8;
#define BLYNK_PRINT DebugSerial
#include <Servo.h>
int servoPin=5;
Servo myservo;
int i=0;
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(0, 1); // RX, TX
#include <BlynkSimpleStream.h>
char auth[] = "57ac041e2a054fdb8d2368735c403f8a";
BLYNK_WRITE(V0)
{
myservo.write(param.asInt());
}
BLYNK_WRITE(V1)
{/*command for UP*/
if(param.asInt()==1){
digitalWrite(ma1,LOW);
digitalWrite(mb1,HIGH);
digitalWrite(ma2,LOW);
digitalWrite(mb2,HIGH);
}
else{
digitalWrite(ma1,LOW);
digitalWrite(mb1,LOW);
digitalWrite(ma2,LOW);
digitalWrite(mb2,LOW);
}
}
BLYNK_WRITE(V2)
{/*command for RIGHT*/
if(param.asInt()==1){
digitalWrite(ma1,LOW);
digitalWrite(mb1,HIGH);
digitalWrite(ma2,LOW);
digitalWrite(mb2,LOW);
}
else{
digitalWrite(ma1,LOW);
digitalWrite(mb1,LOW);
digitalWrite(ma2,LOW);
digitalWrite(mb2,LOW);
}
}
BLYNK_WRITE(V3)
{
/*command for LEFT*/
if(param.asInt()==1){
digitalWrite(ma1,LOW);
digitalWrite(mb1,LOW);
digitalWrite(ma2,LOW);
digitalWrite(mb2,HIGH);
}
else{
digitalWrite(ma1,LOW);
digitalWrite(mb1,LOW);
digitalWrite(ma2,LOW);
digitalWrite(mb2,LOW);
}
}
BLYNK_WRITE(V4)
{
/*command for DOWN*/
if(param.asInt()==1){
digitalWrite(ma1,HIGH);
digitalWrite(mb1,LOW);
digitalWrite(ma2,HIGH);
digitalWrite(mb2,LOW);
}
else{
digitalWrite(ma1,LOW);
digitalWrite(mb1,LOW);
digitalWrite(ma2,LOW);
digitalWrite(mb2,LOW);
}
}
void setup()
{myservo.attach(servoPin);
DebugSerial.begin(9600);
Serial.begin(9600);
Blynk.begin(Serial, auth);
}
void loop(){
Blynk.run();
}
Should work… just perhaps not the way you want it to.
But it appears you haven’t set the pinmode() for any of those pins yet.