Delay on controlling my Bluetooth Controlled RC Car

Uhhh hii, I'm new to robotics and a highschool student

So I have a problem about the delay of my RC car, because if i push the left and right buttons it has a delay for like 2-4 secs before it moves (let's say its like lagging dunno if its the right term to say, I suck at english). Also my forward and backward isn't responding and i guess its because of the code or what. Need help and maybe could get some tips :>
here is the Code:

char t;
 
void setup() {
pinMode(12,OUTPUT);   //left motors   forward
pinMode(11,OUTPUT);   //left motors reverse
pinMode(10,OUTPUT);   //right   motors forward
pinMode(9,OUTPUT);   //right motors reverse
Serial.begin(9600);
 
}
 
void loop() {
if(Serial.available()){
   t = Serial.read();
  Serial.println(t);
}
 
if(t == 'F'){            //move   forward(all motors rotate in forward direction)
  digitalWrite(12,HIGH);
   digitalWrite(10,HIGH);
}
 
else if(t == 'B'){      //move reverse (all   motors rotate in reverse direction)
  digitalWrite(11,HIGH);
  digitalWrite(9,HIGH);
}
   
else if(t == 'L'){      //turn right (left side motors rotate in forward direction,   right side motors doesn't rotate)
  digitalWrite(11,HIGH);
}
 
else   if(t == 'R'){      //turn left (right side motors rotate in forward direction, left   side motors doesn't rotate)
  digitalWrite(12,HIGH);
}
 
else if(t == 'S'){      //STOP (all motors stop)
   digitalWrite(12,LOW);
  digitalWrite(11,LOW);
  digitalWrite(10,LOW);
   digitalWrite(9,LOW);
}
delay(100);
}

Hi! Welcome to the forum!

Since you added a 100 ms delay in your code, I don´t know how to explain a 2 sec. delay based on the info provided. However, I can tell you that a DC motor direction is controlled setting one wire HIGH while the other wire is LOW. You´re just setting them HIGH.

I mean, when you want both motors forward it´s not enough to set:

if(t == 'F'){            //move   forward(all motors rotate in forward direction)
  digitalWrite(12,HIGH);
   digitalWrite(10,HIGH);
}

It would be necessary to do:

if(t == 'F'){            //move   forward(all motors rotate in forward direction)
  digitalWrite(12,HIGH);
  digitalWrite(10,HIGH);
  digitalWrite(9,LOW);
  digitalWrite(11,LOW);
}

The same applies to the other movements.

After changing that in your code, if you still have the delay problem, please share more details on your setup (wiring, components...).

Have fun! :upside_down_face:

What is sending these characters? Maybe the delay is there.

Does it print the characters that mean it should then do forward and backward?

As for the lag, have you tried seeing how fast just printing the received character is?

And I have no idea how your motors work. Perhaps a schematic would clarify that. But

if(t == 'F'){            //move   forward(all motors rotate in forward direction)
  digitalWrite(12,HIGH);
  digitalWrite(10,HIGH);
}
 
else if(t == 'B'){      //move reverse (all   motors rotate in reverse direction)
  digitalWrite(11,HIGH);
  digitalWrite(9,HIGH);
}

when you write 12 and 10 HIGH, should you not also set 11 and 9 LOW?

And similarly other places.

a7

Hello, so i tried using another application and the delay is gone, however the problem is that if i push the right button it powers all of the right dc motors; left button powers all right dc motors and the forward button and backward buttons doesn't do any but it make the moving dc motors to stop. Also did the thing you told to add a LOW or HIGH

also here is my schematic diagram (still not connecting my servos cuz I'm focusing on the dc motors first but maybe needing some help after if i encounter any on servos)
ps. sorry if the diagram very messy i dont know how to make a proper one xD

Uhh, hello, but i couldn't understand what you mean abt sending characters, can i you explain it for me if its ok?

Hello, I fixed my problem with the movements and its working fine now, i just fixed the code since the pins i put in the code were errors thus, the movement was a mess

It was supposed to be
LEFT MOTOR
Input 1 = pin9 (FORWARD)
Input 2 = pin11 (BACKWARD)

RIGHT MOTOR
Input 3= pin10 (FORWARD)
Input 4 = pin12 (BACKWARD)

but i might need help later on about servos if i encounter one

Thanks yall for being so nice =D

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.