Drive of Remote Control Car

Hello all,
Sorry I’m pretty crap at explaining but… I’ve been writing some code to drive a remote control cars motors depending on the values that I input into the Analog inputs(with the remote control transmitter). It works all well, for example if i press forward it will go forward and if i press back it will go back. However, the last command I input will go on infinitely. Like if I press forward it will keep going forward when I only want it to go forward for the time in-which I press forward. I guess I’m going amiss with my delays or something?
This code is to go as part of a Collision Avoidance System

const int motor1 = 12;
const int motor2 = 9;

const int steer1 = 13;
const int steer2 = 8;

const int PWM_M = 3;

int up = 0;
int down = 0;
int left = 0;
int right = 0;

void setup()
  Serial.begin (9600);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);

  pinMode(motor1, OUTPUT); 
  pinMode(motor2, OUTPUT); 
  pinMode(steer1, OUTPUT); 
  pinMode(steer2, OUTPUT);

void loop(){
left = analogRead(A0);
Serial.print("left:  ");
right = analogRead(A1);
Serial.print("right:  ");
down = analogRead(A3);
Serial.print("down:  ");
up = analogRead(A2);
Serial.print("up:  ");

if (down < 400){
  if (up < 400){
  if (left > 400){
  if (right > 400){
void turnleft(int t){
  digitalWrite (13, HIGH);                              
  digitalWrite (8, LOW);
  digitalWrite (11, HIGH);
void turnright(int t){
  digitalWrite (8, HIGH);                              
  digitalWrite (13, LOW);
  digitalWrite (11, HIGH);
void stopmotors(int t){
  digitalWrite (9, HIGH);                              
  digitalWrite (8, HIGH); 
  digitalWrite (3, HIGH);
  digitalWrite (11, HIGH);
  void forward(int t){
  digitalWrite(12, HIGH);
  digitalWrite(9, LOW);
  analogWrite(PWM_M, 120);
void backward(int t){
  digitalWrite (9, LOW);                              
  digitalWrite (12, LOW);
  analogWrite(PWM_M, 120); 

Remove the delays in your direction functions. Those are causing you to lock out the rest of the system while they run. I would look into Blink without Delay to see how to hand polling every some milliseconds so your car doesn't get too twitchy, but I imagine the delays are not helping. What you probably want to do is have the car update its direction commands every 100ms based on the position of the inputs, and make sure to make them all exclusive.

Also, you never call stopmotor() which is why it won't stop.

Thanks for the advice, I will look into blink without delay in the near future.
I have tried calling from the stopmotor but when I do, it doesn’t seem to like it at all. I must not be using it properly. I’m not so good with the control of the car

Something like:

  if (up < 400){