Trying to use L293D, UNO board, and a button to turn Motor on when button pushed

As in the description, I have a breadboard set up with all these but the code appears to be incorrect. No errors are shown when exporting but I have been unable to determine where the issue in my coding lies. Any help would be vastly appreciated. :slight_smile:

//On an arduino uno
const int Motor1 = 5; //one side of a motor controller output
const int Motor2 = 6; //and the other
const int keyPin1 = 11; //the input of a push button
const int keyPin2 = 12; //the input of a second button
const int ledpin = 13; //the output of an led to see if the code is working
void setup() {
pinMode(keyPin1,INPUT);
pinMode(keyPin2,INPUT);
pinMode(Motor1,OUTPUT);
pinMode(Motor2,OUTPUT);
}

void loop() {
  if(digitalRead(keyPin1) ==HIGH )
  {
    clockwise(500);
    digitalWrite(ledpin,HIGH);
    delay(1000);
  }
  if(digitalRead(keyPin2) ==HIGH )
  {
counterclockwise(500);
  }
  else
  {
    clockwise(0);
    digitalWrite(ledpin,LOW);
  }
}

void clockwise(int Speed)
{
  analogWrite(Motor1, Speed);
  analogWrite(Motor2, 0);
}
void counterclockwise(int Speed)
{
  analogWrite(Motor1, 0);
  analogWrite(Motor2, Speed);
}

Tandonto:
As in the description, I have a breadboard set up with all these but the code appears to be incorrect.

You need to tell us what makes you think there is an error in the code.
What does the program actually do?
What should it do?

Does the program work on an Uno?

Do other programs (such as BLINK) work on your breadboard?

...R

I think there's an error in the code because the motor will run without the if statements and buttons but when I press the button that's also connected to the LED, the led does turn on. The program should either, from what I know of of coding which is little, turn on the motor or at least turn it on for one second. The program doesn't work on an uno and that's what I've been using this whole time.

The problem has been resolved

Share code?

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