Need help with blynk+arduino project

Hello,

I have 4 vibration motors attached to 4 different pins on the Arduino Uno with USB setup. With the Blynk app, using 4 buttons/sliders, I am able to control the 4 motors.

But I wanted to use a single Joystick/Segmented switch and control the 4 motors. 4 motors represent 4 directions. So if the left motor vibrates, it is an indication that we have to go left. But joystick has only 2 pin configurations and segmented switch has 1 pin.
Can anyone help?
I am using an iPhone.

Thanks.

Segmented switch has at least 4 because that what I have set up on one of my apps.

If you are doing directions controls though, F, B, L, R a joystick would work well, you just need to code it to suit.

Post what code you have and we will have a look for you.

Edit: Segmented switch has up to 5 inputs.

A little laggy on my emulator but here you go for an example:
(The lag on my example is the virtual writes going back to the server id imagine.)
Counter

BLYNK_WRITE(V6)
{
  int x = param.asInt();
  if (x < -5)
  {
    Blynk.virtualWrite(V3, 255);
  } else {
    Blynk.virtualWrite(V3, 0);
  }
  if (x > 5)
  {
    Blynk.virtualWrite(V5, 255);
  } else {
    Blynk.virtualWrite(V5, 0);
  }
}
BLYNK_WRITE(V7)
{
  int y = param.asInt();
  if (y < -5)
  {
    Blynk.virtualWrite(V2, 255);
  } else {
    Blynk.virtualWrite(V2, 0);
  }

  if (y > 5)
  {
    Blynk.virtualWrite(V4, 255);
  } else {
    Blynk.virtualWrite(V4, 0);
  }
}

Thank you so much for your help. I am trying your code, but I am a bit confused with virtual and digital pins.
My code was similar to yours, I had different values, and I had written pins D5, and D6 since my motors are connected to digital pwm pins on Arduino, but I have now modified it according to your code.

[unformatted code removed by moderator]

This is my first Arduino project, So I’m very new to this!
As you can see, I have 4 vibration motors attached to digital pins.

After uploading this code, and running it via the command prompt, I cannot see any difference.

Please edit your post to:

  1. include backticks at the beginning and then end (not quotes as you have) backticks are these > ```
  2. post your original working code

I was using only the virtual write to show the led on screen for forwards/reverse etc


#define BLYNK_PRINT DebugSerial

#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#include <BlynkSimpleStream.h>

char auth[] = "rQQYJBZO8DIjXqtxCnIGaDIWtbZ3i9qR";

BLYNK_WRITE(D5)
{
  int x = param.asInt();
  if (x < -5)
  {
    Blynk.digitalWrite(D5, 153);
  } else {
    Blynk.digitalWrite(D5, 0);
  }
  if (x > 5)
  {
    Blynk.digitalWrite(D6, 153);
  } else {
    Blynk.digitalWrite(D6, 0);
  }
}
BLYNK_WRITE(D6)
{
  int y = param.asInt();
  if (y < -5)
  {
    Blynk.digitalWrite(D10, 155);
  } else {
    Blynk.digitalWrite(D10, 0);
  }

  if (y > 5)
  {
    Blynk.digitalWrite(D11, 155);
  } else {
    Blynk.digitalWrite(D11, 0);
  }
}

void setup()
{
  // Debug console
  DebugSerial.begin(9600);

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);
}

void loop()
{
  Blynk.run();
}

Change in your app and in your code BLYNK_WRITE(D…) to BLYNK_WRITE(V…) this changes from digital pins to virtual pins.

Also then remove the Blynk. from your digital writes

Blynk.digitalWrite(D6, 153); >>> digitalWrite(D6, 153);

I did the changes you suggested but still only two motors vibrate since only 2 pins are connected. D5, D6.
Motors connected on D10, and D11 don’t vibrate. Is it possible that a single Joystick can work for 4 pins?

In the image below, I have D5, and D6, and would like to include two more pins.

#define BLYNK_PRINT DebugSerial

#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#include <BlynkSimpleStream.h>

char auth[] = "rQQYJBZO8DIjXqtxCnIGaDIWtbZ3i9qR";

BLYNK_WRITE(V5)
{
  int x = param.asInt();
  if (x < -5)
  {
    digitalWrite(V5, 155);
  } else {
    digitalWrite(V5, 0);
  }
  if (x > 5)
  {
    digitalWrite(V6, 155);
  } else {
    digitalWrite(V6, 0);
  }
}
BLYNK_WRITE(V6)
{
  int y = param.asInt();
  if (y < -5)
  {
    digitalWrite(V10, 153);
  } else {
    digitalWrite(V10, 0);
  }

  if (y > 5)
  {
    digitalWrite(V11, 153);
  } else {
    digitalWrite(V11, 0);
  }
}

void setup()
{
  // Debug console
  DebugSerial.begin(9600);

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);
}

void loop()
{
  Blynk.run();
}

On the app, you need to change D5 to V5 and D6 to V6.

Oh yes, I tried that, But none of the motors vibrate if its V5, and V6.

In your code you need to change your digitalWrites back to what they were before…
Only in your app did you need to change to V5 and V6.

This should now work:

#define BLYNK_PRINT DebugSerial

#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#include <BlynkSimpleStream.h>

char auth[] = "rQQYJBZO8DIjXqtxCnIGaDIWtbZ3i9qR";

BLYNK_WRITE(V5)
{
  int x = param.asInt();
  if (x < -5)
  {
    digitalWrite(D5, 155);
  } else {
    digitalWrite(D5, 0);
  }
  if (x > 5)
  {
    digitalWrite(D6, 155);
  } else {
    digitalWrite(D6, 0);
  }
}
BLYNK_WRITE(V6)
{
  int y = param.asInt();
  if (y < -5)
  {
    digitalWrite(D10, 153);
  } else {
    digitalWrite(D10, 0);
  }

  if (y > 5)
  {
    digitalWrite(D11, 153);
  } else {
    digitalWrite(D11, 0);
  }
}

void setup()
{
  // Debug console
  DebugSerial.begin(9600);

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);
}

void loop()
{
  Blynk.run();
}

Thank you so much for your help all way long @JustBertC :slight_smile:

1 Like