Maze Runner Robot

hello, I'm currently building a maze runner robot. it is supposed to work with 4 dc motors, I'm using an Arduino Uno and a motor shield attached to it. I plugged the 4 motors into the motor shield and burned the following code to the Arduino:

#include <AFMotor.h>

AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

void setup() {


void loop() {;;;;


and only two dc motors (2,3) are working. does anyone know the reason?

Unlikely to be related to your problem, but should there be a couple of commands in the loop rather than duplicate commands?

EDIT: A few other thoughts:

  1. Do you need to stop the motor before changing its direction?
  2. What happens if you have just 1 motor wired up to the controller and move it between the 4 channels?
  3. You need another delay after the commands in the loop.

the duplication was an innocent mistake because I did too many edits on the code while I was trying to get the motors to run
however now I'm just trying to get all 4 dc motors to run before working on the maze algorithm

I did wire one motor and changed between the channels only channel 2 and 3 are working.

when I plugged the motor which was in channel 4 into channel 3 it moved poorly and slow and stopped for a long time then it started to run again

I don't know if there is a faulty in the motor shield or the dc motors or the code or I should just provide 2 more batteries and connect them to the shield

Can you run every motor if you do them one at a time?

Also, you're using pin one for a motor and for serial.

@hixoop I would suggest that you try and identify a working channel and a working motor. Then use that working motor to determine which other channels are working correctly.

yes I can but when I plug them into channel 2 or 3 only

I don't understand how am I using pin one for a motor and for serial.... and how can I fix this?

i did that and channel 2 and 3 only are working. do you think it's a faulty in motor shield?

Pins zero and one are used for serial. Pick another one for your motor.

how may I do that?

I'm not sure why @wildbill thinks you are using pin 1 of the Arduino (which is used for serial comms). I found a schematic for what might be the correct/similar motor driver board and it doesn't use the serial pins at all.

Assuming that channel 2 & 3 refer to M2 and M3 on the board, they are on separate driver chips.

If you suspect that there may be a fault with the driver chips, then by the looks of your photo, the chips are in DIL sockets. You could try removing the 2 driver chips and swapping them over to see if channels 2 and 3 still work.

If you just have the code for 1 motor on channel 1, does that work? (Trying to establish if it's a channel fault or an issue to do with using multiple motors).

Are you using the correct library to drive the board? The Adafruit website shows a v1 motor driver shield that they no longer make which looks very similar to yours.

I did change the code to work only with channel 1 and plugged the motor's wire into the channel and nothing happened

And when I burned the same code but for channel 2 and plugged the motor it worked just fine

Ok, if you are sure that the library you are using matches the board that you have, then there could be an issue with the L293D driver chips.

But first, I would triple check the library/board compatibility as it could easily go wrong if the shift register outputs on the driver board don't match the pin definition in the library.

turned out that there was a faulty in the l293D I changed it and the code worked just fine thank your mark

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