Looking for help running a L293D

I don't know if this is the correct forum because it's only a 5v circuit, but I can't get it to run so here we are.

I'm running a L293D motor controller with an Arduino Uno rev3

Basically what i hope to achieve is, at the push of a button the motor will run in a given direction stop then run again in the opposite direction one time.

Any help appreciated

int Button = 13;
int dir1 = 4;
int dir2 = 3;
int mSpeed = 255;
int Stspeed = 0;
int Speedpin = 5;

void setup() {
  // put your setup code here, to run once:

  pinMode(Button, INPUT);
  pinMode(Speedpin, OUTPUT);
  pinMode(dir1, OUTPUT);
  pinMode(dir2, OUTPUT);
  digitalWrite(Button, HIGH);
  Serial.begin(96000);

}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(Button) == LOW) {
    MotorRun();
  }
}

void MotorRun() {
  digitalWrite(dir1, HIGH);
  digitalWrite(dir2, LOW);
  analogWrite(Speedpin, mSpeed);
  delay(10000);
  analogWrite(Speedpin, Stspeed);
  delay(1000);
  digitalWrite(dir1, LOW);
  digitalWrite(dir2, HIGH);
  analogWrite(Speedpin, mSpeed);
  delay(10000);
  analogWrite(Speedpin, Stspeed);
  digitalWrite (Button, HIGH);
}

What happens when you run the code? What motor do you have? How is the motor powered?

Your line:

digitalWrite (Button, HIGH);

... turns on that pin's internal resistor. (It's the old way of doing INPUT_PULLUP).

But your Button is 13, and the manual says here (my emphasis):

NOTE: Digital pin 13 is harder to use as a digital input than the other digital pins because it has an LED and resistor attached to it that's soldered to the board on most boards. If you enable its internal 20k pull-up resistor, it will hang at around 1.7V instead of the expected 5V because the onboard LED and series resistor pull the voltage level down, meaning it always returns LOW. If you must use pin 13 as a digital input, set its pinMode() to INPUT and use an external pull down resistor.

That may or not be, or may or may not have a bearing on, your problem since you didn't say what the problem is.

I would in any case use another pin, and pinMode it as INPUT_PULLUP.

The Uno now uses a comparator (LM358) to drive the L (D13) LED, so the resistor/LED are no longer directly connected, thus there is minimal load (1-2uA) for an input to drive the pin.
This has been the case since 2015 when the Uno Rev 3 came out as the basic Arduino board for getting started with.

There is no issue using D13, unless one plans to also do SPI.transfer(), in which case the pin is committed as the SPI clock pin.

Nothing happens… It’s powered by a 5v power supply. The motor I’m using the motor from the Arduino ELEGOO kit.
I have no problem getting the the motor or button working separately so that’s why I suspect it’s a software problem.

Also I’m not sure how INPUT_PULLUP up works I wasn’t taught it that way I’ve been learning from the top tech boy tutorials. I’ll try switching pins and see what happens thanks.

that has been the case since like 2010

My quote was taken off the live page. I write documentation for a living. I'd have been fired 9.99 years ago if that was my documentation.

monekymage: Nothing happens...

First thing is to test your program logic with the L293 and motors out of play. Put an led (with resistor) on each of your Arduino outputs, dir1 and 2, and see if the leds do what you expect.

  • If the leds work ok, look into the l293/motor circuitry and power.
  • If the leds don't work ok, look into the logic.

edit... and stick some serial prints in the code at strategic spots so you can see where it's going.

And post the circuit schematic please.

i don't have a schematic drawing program i can draw it if you'd like a picture of a crude drawing. Im not sure how testing the inputs matters as I know to motor button controller as I can make them all work separately.

If something's not working, until you find out why, you, well, don't know why ;) so you need to take a systematic approach and isolate things so you can track down where the problem is.

A photo of rough pen and paper sketch is perfect I'm sure.

If you really do not have a separate power supply to the L293 and motor just the Arduino 5V supply then that is very likely your problem. The L293 typically drops 2.5 to 4V so you're possibly only getting 1V to the motor and that won't be enough to make it run.

Steve