Issue my shield to drive 2 DC motor for my car but only left and reverse work

[Unformatted code removed by moderator]

@mukam please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

//ESP8266 Blynk Joystick Car
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define RightMotorSpeed 5 //14
#define RightMotorDir 0 //12
#define LeftMotorSpeed 4 //13
#define LeftMotorDir 2 //15

char auth[] = “”;
char ssid[] = “”;
char pass[] = “”;

int minspeed = 512;
int maxspeed = 1023;
int nospeed = 0;

void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);

pinMode(RightMotorSpeed, OUTPUT);
pinMode(LeftMotorSpeed , OUTPUT);
pinMode( RightMotorDir, OUTPUT);
pinMode(LeftMotorDir, OUTPUT);

digitalWrite(RightMotorSpeed, LOW);
digitalWrite(LeftMotorSpeed , LOW);
digitalWrite( RightMotorDir, LOW);
digitalWrite(LeftMotorDir, LOW);
}

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

BLYNK_WRITE(V1)
{
int x = param[0].asInt();
int y = param[1].asInt();

if (x==512) // stop
{
digitalWrite( RightMotorSpeed,LOW);
digitalWrite( LeftMotorSpeed ,LOW);
Serial.println(x);
Serial.println(“stop”);
}
else if(x > minspeed)
{
digitalWrite( RightMotorSpeed,HIGH);
digitalWrite( LeftMotorSpeed ,LOW);
Serial.println(x);
Serial.println(“motorFwd”);
}

else if(x == -0)
{
digitalWrite( LeftMotorSpeed ,HIGH);
digitalWrite( RightMotorSpeed,LOW);
Serial.println(x);
Serial.println(“motorRev”);
}
}

BLYNK_WRITE(V2)
{
int x = param[0].asInt();
int y = param[1].asInt();

if (x==512) // stop
{
digitalWrite( RightMotorDir,LOW);
digitalWrite( LeftMotorDir ,LOW);
Serial.println(x);
Serial.println(“stop”);
}
else if(x > minspeed)
{
digitalWrite( RightMotorDir,LOW);
digitalWrite( LeftMotorDir ,HIGH);
Serial.println(x);
Serial.println(“motorRight”);
}

else if(x < minspeed)
{
digitalWrite( LeftMotorDir ,LOW);
digitalWrite( RightMotorDir,HIGH);
Serial.println(x);
Serial.println(“motorLeft”);
}
}




It would have been better if you’d edited your original post rather than re-posting the code.
I’ve deleted the unformatted code from your original post.

How exactly is your motor shield wired-up to your ESP8266?

What do you see in your serial monitor? Do you ever see the “motorFwd” and “motorRight” messages. and do you see the correct messages when the car goes Left and Backwards?

Pete.

Ok Mr Pete I would also check that at serial.

Umm I think your left/right is a servo not a motor! Could you show a picture of it?

Edit: A servo would be hooked up to the other pins not the motor output.

Hi Dave
Both are DC motors

I had uploaded this new code but still the same issue the motor works fwd and left only V0,V1.
V1 is backward and it moves the second motor left .The steering wheel.left V1 is left

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define RightMotorSpeed 5
#define RightMotorDir   0
#define LeftMotorSpeed  4
#define LeftMotorDir    2

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";
char ssid[] = "";
char pass[] = "";


void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  pinMode(RightMotorSpeed, OUTPUT);
  pinMode(RightMotorDir, OUTPUT);
  pinMode(LeftMotorSpeed, OUTPUT);
  pinMode(LeftMotorDir, OUTPUT);
}

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

void halt()
{
  digitalWrite(RightMotorSpeed, LOW);
  digitalWrite(LeftMotorSpeed, LOW);
}

void forward()
{
  digitalWrite(RightMotorDir, HIGH);
  digitalWrite(LeftMotorDir, HIGH);
  digitalWrite(RightMotorSpeed, HIGH);
  digitalWrite(LeftMotorSpeed, HIGH);
}

void reverse()
{
  digitalWrite(RightMotorDir, LOW);
  digitalWrite(LeftMotorDir, LOW);
  digitalWrite(RightMotorSpeed, HIGH);
  digitalWrite(LeftMotorSpeed, HIGH);
}

void right()
{
  digitalWrite(RightMotorDir, LOW);
  digitalWrite(LeftMotorDir, HIGH);
  digitalWrite(RightMotorSpeed, HIGH);
  digitalWrite(LeftMotorSpeed, HIGH);
}

void left()
{
  digitalWrite(RightMotorDir, HIGH);
  digitalWrite(LeftMotorDir, LOW);
  digitalWrite(RightMotorSpeed, HIGH);
  digitalWrite(LeftMotorSpeed, HIGH);
}

BLYNK_WRITE(V0)
{
  if (param[0])
    forward();
  else
    halt();
}

BLYNK_WRITE(V1)
{
  if (param[0])
    reverse();
  else
    halt();
}

BLYNK_WRITE(V2)
{
  if (param[0])
    right();
  else
    halt();
}

BLYNK_WRITE(V3)
{
  if (param[0])
    left();
  else
    halt();
}

And the answers to my questions about the serial monitor output?

Pete.

Yes Mr Pete,I do see the command and all pins are working at serial output.One thing I notice is that the front and back motor works at one direction would I need to input variable -1 for it to work reverse both the motors?

:thinking::thinking:

ALL of my RCs that have a steering axle like this are actuated by a servo. I don’t see how it could be mechanically possible to be a DC motor. But hey I’ve been wrong before!

Can you open the front end and send a close up picture of the front motor where the wires enter?

Do you have a link to the specification for the car and the hardware (motors etc) that comes with it?

Pete.

Dave Let’s say the front steering axle is a servo. what about the back motor why it is working in only 1 direction and not the other as same goes for the front The issue is it accepts only one-directional spin but not the reverse.Do I need to change the blynk button? Like for V0 -1 and 1 as now its setup as 0 and 1

no Mr Pete ,Do you think the issue is wih the hardware or wires and not the code?

if your BLYNK_WRITE functions are buttons try using

if(param.asInt())

Instead of

if (param[0])

Also as @PeteKnight suggested create a display widget on say V5 and add a

Blynk.virtualWrite(V5, 1); 

In forward and a 2 in backward and see if it is even running the commands. And a 3 in halt();

I suggested a while ago that you add some serial print messages to get some visual feedback of the program flow and the variable values. You haven’t shared what you see here other than to say…

which makes it difficult to pin down the issue. As you don’t seem ton be able to decide if the front axle is a servo or a motor, it seems that we would get more solid data from a link to the car chassis, but you say that isn’t possible.
That make me think that this is an issue you need to work through yourself and solve.

Pete.

Mr Pete even its not a servo.The back and front are both DC motor with issues that only it rotates one side fwd and left.

Servos operate differently to regular DC drive motors and as @daveblynk has already said they need to be connected differently.

I’d disconnect the front motor and concentrate on getting the rear motor to run both forwards and backwards. I’d have it on the bench connected to a serial monitor that showed me exactly what values were being sent to the controller and observer the results. I’d experiment with different polarity of the wiring, and with different software commands until I understood where the issue lies. I’d probably connect my meter to the output of the controller as well, to correlate the readings with the action of the motor

I’d probably also try some demo software for the motor shield to ensure that this gave me the results I was expecting.

We cant do that for you, as you have some hardware we haven’t seen before and which you don’t know anything about.

Pete.

Hi mates!!
I’ve got a cheap RC car with a DC motor as steering axle.
I was as surprised as you are when I saw it:

@mukam, is this the kind of RC car you have?
Regards!!!

1 Like

So it is either left, right with a sprint to pull it center?