Motor rotating in a single way only

Hello everyone,

I am currently working on an IR operated system in which I need to operate motors. However since today, the motor in question seems to refuse to rotate in both ways.

When I try uploading a sketch made to check everything is working find, the motor either rotates clockwise or counter-clockwise (depending on the order they’re written in the code) but never both.

I already used those a few times and never had this problem.

I’m using an L293D to control the motor. I attached a photo of my circuit.

Here is my test code:

void setup() {
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
}

void loop() {

  

        analogWrite(10, 127);
        digitalWrite(9, LOW);
        digitalWrite(8, HIGH);
        delay(2000);

        analogWrite(10, 255);
        digitalWrite(9, HIGH);
        digitalWrite(8, LOW);
        
        delay(2000);

}

It is supposed to rotate the motor in both ways for 2 seconds each but it only does it for one. Which I don’t understand since this code and setup worked perfectly fine for the last two months.

Any Idea what’s going wrong?

Cecomog:
I attached a photo of my circuit.

Seems you forgot :slight_smile:

I didn’t but the first version of the photo was too big so the upload failed ^^
I edited the post and attached a smaller version :slight_smile:

OP’s pic inline here…

ff6a455f2bc5a6dd35b10b76a432e9af52a1f8a4.jpg

That's actually a surprisingly good photo.

I can't see a ground wire from the Arduino to the breadboard, although it's not perfectly clear what the red wire on the right is doing.

I don't see a ground from Arduino to the 293...

MorganS:
it's not perfectly clear what the red wire on the right is doing.

I think the red is 5V to 293 pin 16 the logic supply

MorganS:
I can't see a ground wire from the Arduino to the breadboard

My bad, I rewired the system so the photo would be clearer and forgot to reconnect the ground pin to the breadboard. However, when I tested the system it was connected.

The red wire is connected to the 5V pin of the arduino. It serves as the L93D Logic Supply Voltage.

I see you have 2 different analogWrite() values, not that there's anything wrong with that in principal.

BUT could it be the battery's a bit flat and it's the 127 that's not getting the motor going?

I tried a new battery and another value but it still rotates in one way only.

Swap the motor wires over on the 293....

I tried that and the motor operated the same as before only in the other direction.

Try the other side of the 293....

So after turning the L293D the other way, the motor started turning slower than before but still in one way only.

You mean you turned it without changing the wires? That will I think put 9V from the battery onto the 293 logic 5V pin, and 5V onto the motor supply.

How about changing to a different set of Arduino pins.

Yes, that's what I thought you meant. The datasheet of the 293 shows a maximum voltage of 36V for both this pins so I did not worry too much.

I tried connecting the 293 to pins 1,2 and 3 and got the same result...

9V battery is not enough to drive a motor - first fix that problem.

I don't think that's the problem. This is only a bench test. The battery doesn't have to last very long and the motor isn't under any load.

Why would it work one way and not the other? That's not the fault of the battery.

MorganS:
Why would it work one way and not the other?

And moreover, if I read it correctly, OP says this worked before.

Yeah 9V didn't pose any form of problem until now when testing.

Could the problem come from televersing the program to the arduino? My PC is pretty old and sometimes the USB 2.0 to which my board is connected has a few bugs.
I already tried another motor, L293D and arduino so it's the last thing I can think of.