Controlling Speed and Direction of a Motor

Hello there. I am a beginner with Arduino and circuitry in general and have a question regarding the project I am doing. The goal of my project is to control a 12V, 21A DC motor using the Arduino Uno with LCD Keypad Shield and a DC Motor Driver. I am also using a 12V computer power supply to power both the motor and driver. I’ve followed the instructions on the Manufacturer’s website for the driver, and pieced together some of the code that they have provided, but have come across several issues.

Assuming that all of my connections are correct, the first issue is that the driver trips whenever I attempt to change the direction of the motor using the LCD and have to restart my power supply to power the driver again. The second issue is that raising or lowering the PWM values on the LCD does nothing to the motor, even at peak value. The last issue is that the LCD keypad layout is all wrong. Pressing the up and right buttons changes direction and the left and bottom buttons changes the PWM values.

Here is the code:

#include <LiquidCrystal.h>
#include <LCDKeypad.h>

#define None 0
#define Select 1
#define Left 2
#define Up 3
#define Down 4
#define Right 5

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
LCDKeypad lcdKeypad;

#define diy_pwm A2
#define pwm 3
#define dir 2
#define pot A1

void setup(){
  lcd.begin(16,2);
  lcd.clear();

  pinMode(pwm,OUTPUT);
  pinMode(dir,OUTPUT);
  pinMode(diy_pwm,OUTPUT);
  pinMode(pot,INPUT);
  
}

void loop(){
  int localKey;
  int pwm_value;

while (1){
  localKey=lcdKeypad.button();

  if(localKey==Left){
    digitalWrite(dir, !digitalRead(dir));
    delay(200);
  }

  if(localKey==Up){
    pwm_value++;
    delay(200);
    lcd.clear();
  }

  else if (localKey==Down){
    pwm_value--;
    delay(200);
    lcd.clear();
  }

  if(pwm_value>255)
  pwm_value=255;
  else if (pwm_value<0)
  pwm_value= 0;

  analogWrite(pwm, pwm_value);

  lcd.setCursor(0,0);
  lcd.print("PWM:");
  lcd.print(pwm_value);
  lcd.setCursor(0,1);
  lcd.print("DIR:");
  lcd.print(digitalRead(dir));
  
}
  
}

Any guidance would be appreciated. Thank you.

Why are you running an infinite loop in the loop() function? It appears that you do not understand that loop() loops.

You need to post links to the hardware you are using, and a schematic showing how it is connected to the Arduino.

http://tutorial.cytron.com.my/2013/07/29/controlling-md10c-with-arduino/fullscreen-capture-7182013-101845-am-3/

The wiring follows this schematic but I didn't include the pot. I included the datasheet for the driver in my previous post. I'm using the arduino uno r3 more specifically.

Also here's the tutorial I have been following

Any help would be appreciated.

Any help would be appreciated.

What would help would be links to the documentation that do NOT involve google docs.

the first issue is that the driver trips whenever I attempt to change the direction of the motor

No surprise there. If you rapidly reverse a DC motor, it can draw up to TWICE the startup/stall current.

Make sure that the motor comes to a full stop before reversing. Otherwise if your power supply doesn't trip, you will burn out the windings and brushes.

If the 21 amp specification is the rated running current, that motor driver is actually inadequate, because the startup current could be as high as 100 amps.