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

How to control DC motors using Blynk with Arduino..?


#1

I’m trying to control 2 DC motors and one servo motor using Blynk app connecting arduino through Bluetooth HC-05.
Servo motor is running successfully, but the DC motors are not responding one bit.
Here’s my code:

int ma1=2;
int mb1=4;
int ma2=7;
int mb2=8;
int U=0;int L=0;int R=0;int D=0;
#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*/
          int U1=param.asInt();
          U=U1;
        }
BLYNK_WRITE(V2)
        {/*command for RIGHT*/
          int R1=param.asInt();
          R=R1;
        }
BLYNK_WRITE(V3)
        {
          /*command for LEFT*/
          int L1=param.asInt();
          L=L1;
        }
BLYNK_WRITE(V4)
        {
          /*command for DOWN*/
         int D1=param.asInt();
         D=D1;
        }
void setup()
{myservo.attach(servoPin);
  
  DebugSerial.begin(9600);
  Serial.begin(9600);
  Blynk.begin(Serial, auth);
}

void loop(){
  Blynk.run();
  if(U==1){
    digitalWrite(ma1,LOW);
    digitalWrite(mb1,HIGH);
    digitalWrite(ma2,LOW);
    digitalWrite(mb2,HIGH);
  }
  else if(R==1){
    digitalWrite(ma1,LOW);
    digitalWrite(mb1,HIGH);
    digitalWrite(ma2,LOW);
    digitalWrite(mb2,LOW);
  }
  else if(L==1){
    digitalWrite(ma1,LOW);
    digitalWrite(mb1,LOW);
    digitalWrite(ma2,LOW);
    digitalWrite(mb2,HIGH);
  }
  else if(D==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);
  }
}

#2

Please STOP spamming the forum with multiple (but related) topics… at this point it is somewhat clear you are new to programming, so spend some time in the Documentation, Help Center and Searching (Links all at the upper right of this page) around this forum for others who have made robots and cars etc. And are using DC motors and even Servos with Blynk.

Blynk - RE-SEAR-CH

And as already asked once before, please start formatting ALL code that you post here… this was directed in the Welcome Topic that you should have red at the beginning.

And repeated in another topic

Blynk - FTFC

As for your code… for one thing, you have too much on the void loop, you need to break functions out and use timers to poll them.