Simple problem with ports

Hey, I am having a problem activating output on 4 ports. I am using the ports to activate a series of external switches, which works great when I test them one at a time.

Here's my code:

int leftPin = 13; int rightPin = 12; int backwardPin = 6; int forwardPin = 7;

void setup() { Serial.begin(115200); pinMode(leftPin, OUTPUT); pinMode(rightPin, OUTPUT); pinMode(backwardPin, OUTPUT); pinMode(forwardPin, OUTPUT); }

void loop() { digitalWrite(rightPin, HIGH); delay(2000); digitalWrite(rightPin, LOW);

digitalWrite(leftPin, HIGH); delay(2000); digitalWrite(leftPin, LOW);

digitalWrite(forwardPin, HIGH); delay(2000); digitalWrite(forwardPin, LOW);

digitalWrite(backwardPin, HIGH); delay(2000); digitalWrite(backwardPin, LOW);


What happens is the rightPin and the forwardPin fire simultaneously, and then the rightPin continues to remain active during the backwardPin cycle. The leftPin never gets called. I want them to cycle through and fire one at a time.

I'm still super new at this.. I could be missing something very basic. Any ideas?



I do not see any logical errors in you code, and am surprised to hear that you're not getting the cycle you want.

Are you sure your test (LEDs?) are wired correctly?

And, please use the (#) button in the post 'editor' when posting code :)

I set up a prototype board with 4 leds, connected to poins 13, 12, 6, and 7, and ran your code. One led at a time lights up, and all 4 light up in turn.

As was suggested, check your wiring.

I'm with Paul and Alpha on this one. (works fine here)

It sounds like you have the hardware selection a little bit off. (Could you post pictures, or a schematic?)

Something you pointed out though you said you're using external switches? What do you mean by that? Transistors?

It sounds like you're trying to use some motors? What kind of external hardware's connected?

Hey, thanks for all the help so far.

What I’m doing may be a little unorthodox due to a lack of supplies on hand. I’m trying to use the Arduino to control an RC car. I took apart the controller of an RC car and soldered wires to the contacts of the controlled. I tested it with a 5volt power supply, and it worked! So I felt safe that I wouldn’t be frying anything if I experimented with this on the Arduino.

I hooked the ground from the RC controller up to the Arduino, and connected the left and right controls to the Arduino. I ran the code, and it worked like a charm! The wheels go left, pause, then right, pause, etc… I felt like I was basically there. I did a test by hooking up the forward and backwards controls, and they work as well!

So, I start running into trouble when I try to hook any more than 2 controls up to the board. Its like all the pins are being called, even when they are set to LOW. It calls multiple pins simultaneously, even when they shouldn’t have voltage on them.

I know this is kind of a hack way of doing this… but I’m just looking for a quick and dirty solution. I feel like I’m almost there, having the Arduino succesfully controlling some of the actions of the car.

Any ideas?

Thanks again for everyone expertise, not sure what I’d do if I wasn’t able to ask the experts for help.


What are you physically controlling with the Arduino? It sounds like you are using the Arduino to control servos, at least for the steering part. What device is being controlled to make the car go forward that is separate from the device for making it go backward?

Perhaps a picture would help.

I am using the Arduino to connect/disconnect the buttons on the remote control for the car. So I'm not controlling motors/servos directly, just the buttons on the remote control that send the car the signal to move.


In that case, it is (very) likely that the switches are single pole, double throw switches, and that that is not what you are emulating.

Ok. I may be misunderstanding this. I have four buttons, and I believe they are single pole, single throw. They each connect/disconnect a single connection, and perform a single action. They all share the same ground. Does that sound like single pole, single throw?

Still learning.. thanks for your patience.


It does. But, what prevents you from pushing multiple buttons at the same time? Left and forward makes sense, but forward and backwards together or left and right together do not. I suspect that there may be some sort of micro-controller built in that handles multiple button pushes. That micro-controller, if one exists, may be what's causing the problem.

Another thought. If the buttons share a common ground, the button is arranged in the circuit like this:

+V --> servo --> button --> ground.

In this case, you can't just set a pin HIGH and connect it to this circuit anywhere and expect to emulate pushing the button.

Cool. Thanks. I found this:

This is pretty much the same concept. Now if I can just find a comparable optoisolator.


This is also the same concept, except he is using transistors to do the trick. Much easier to find locally.