Reversing Direction of Motor

So I was hacking into a RC Car with a RF transmitter, There were 4 switches to control Left, Right, Forward and Reverse. I soldered wires to the circuit board of the transmitter and connected it to my arduino UNO.
But when I send a HIGH signal to the respective pin, it just goes left. Never RIGHT.
Same case with the Forward and Reverse. The car only goes forward.

void setup() {
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  analogWrite(13, 255);
  analogWrite(12, 0);
  delay(1000);
  analogWrite(13, 0);
  analogWrite(12, 255); 
 delay(1000);
}

How do i reverse the Direction of the motor?

Uno pins 12 & 13 are digital and do not support PWM.
analogWrite() to a digital pin is for PWM if the pin has that ability.
Try using digitalWrite(13, 1)
...and so on.

No schematic.

You mention 4 switches, and have only 2 pins used in the sketch.

Why are you using analogWrite?

Yes I've tried it with digitalWrite too.
Also there are only two pins because I was testing only for Right and Left.

nikhalster:
So I was hacking into a RC Car with a RF transmitter, There were 4 switches to control Left, Right, Forward and Reverse. I soldered wires to the circuit board of the transmitter and connected it to my arduino UNO.
But when I send a HIGH signal to the respective pin, it just goes right. Never LEFT.
Same case with the Forward and Reverse. The car only goes forward.

First, you mention four switches ... eg. switches A, B, C, D.

Then, next... you mention sending a 'high' to a pin.

There's no link between what you described.... ie. switches ... and pin. What's the link between switches and this 'pin' that you mentioned?

Well I connected a wire to the one of the switch’s four points which simulates the “pressed button operation”

I hope I’ve done it correctly.

For now I connected the left and right switch to 13 and 12 respectively.

void setup() {
  
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
}


void loop() {
  digitalWrite(13, HIGH);
  digitalWrite(12, LOW);
  delay(1000);                    
  digitalWrite(13, LOW);
  digitalWrite(12, HIGH);
  delay(1000);

I expected the car to turn left, delay for 1 second then turn right and wait for 1 second. But it goes only left both times.

nikhalster:
For now I connected the left and right switch to 13 and 12 respectively.

And the GND wire?

With the Arduino disconnected and the car responding properly to switch inputs, what are the voltages on the switches unpressed and pressed?

After further experimenting with the hardware I've got 4 wires connected to four different solder points on the circuit board. Which in turn have been connected to the Arduino.

When I Output HIGH to Pin 8, the car goes forward.
When I Output HIGH to Pin 7 and 8, the car goes reverse.

When I Output HIGH to Pin 13, the car goes left.
When I Output HIGH to Pin 12 and 13, the car goes right.

Great. But..When I try to use all the pins together in my code, it doesnt work.
So this works

void off() {
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(12, LOW);
  digitalWrite(13, LOW);
}

void setup() {
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);

  //pinMode(12, OUTPUT);
  //pinMode(13, OUTPUT);

  off();

}


void goForward() {
  digitalWrite(8, HIGH);

}

void goReverse() {
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
}


void loop() {
  goForward();
  delay(1000);
  off();
  goReverse();
  delay(1000);
  off();
}

But this wont work. All I did was set 12 and 13 as Output pins and the car will go only in the forward direction without any delay. Perhaps it gets stuck in the goforward function loop?

void off() {
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(12, LOW);
  digitalWrite(13, LOW);
}

void setup() {
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);

  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);

  off();

}


void goForward() {
  digitalWrite(8, HIGH);

}

void goReverse() {
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
}


void loop() {
  goForward();
  delay(1000);
  off();
  goReverse();
  delay(1000);
  off();
}

I believe I mentioned this:

Jiggy-Ninja:
And the GND wire?

THE GND pin of the Arduino is connected to the negative of the circuit whereas I’ve connected the 3.3V pin to the positive of the circuit board.

Put a delay after the off() .... just for testing purposes. And see what happens. So .... go forward. Delay. Off. Delay. Go backward. Delay. Off.

And if that works.... then decrease the delay duration after the off() to 1 millisecond.

nikhalster:
So this works

void off() {

digitalWrite(7, LOW);
 digitalWrite(8, LOW);
 digitalWrite(12, LOW);
 digitalWrite(13, LOW);
}

void setup() {
 pinMode(7, OUTPUT);
 pinMode(8, OUTPUT);

//pinMode(12, OUTPUT);
 //pinMode(13, OUTPUT);

off();

}

void goForward() {
 digitalWrite(8, HIGH);

}

void goReverse() {
 digitalWrite(7, HIGH);
 digitalWrite(8, HIGH);
}

void loop() {
 goForward();
 delay(1000);
 off();
 goReverse();
 delay(1000);
 off();
}

You disabled pinmode for 12 and 13. But you write to 12 and 13…inside the off() function.

Normally it’s good to know whether a pin is configured as an input or an output.