Start/Stop DC Motor Control Using Momentary Button and LCD. Help Please

Hello,
I have tried a few different codes from what I was able to find online regarding Start/Stop or toggle circuits. The issue is they don’t have much info for dual buttons with an adjustable motor speed pot. Here is the code I have so far. It doesn’t work as I had hoped. I was hoping for the start button to turn the motor on and the stop to stop it. The led’s and messages would be displayed accordingly. Using a 12V DC motor with an H bridge module. I think I’m close and hopefully it’s something simple. Any suggestions or help would be amazing! Thanks

#include <LiquidCrystal.h>
int in1 = 8; 
int in2 = 9;
int enA = 10;
int speed1;
int buttonPin1 = 6; //START BUTTON
int buttonPin2 = 7; //STOP BUTTON
int buttonNew1;//Start
int buttonNew2;//Stop
int buttonOld1 = 1;
int buttonOld2 = 1;
int motorState = 0;//start with motor off
int dt = 100;

LiquidCrystal lcd(11, 12, 2, 3, 4, 5);

void setup() {
   Serial.begin(9600);
  lcd.begin(16, 2);  
   lcd.print("XENTRIC GUITARS         ");
  pinMode(in1, OUTPUT);//motor
  pinMode(enA, OUTPUT);//motor
  pinMode(in2, OUTPUT);//motor
  pinMode(buttonPin1, INPUT);// Button Green
  pinMode(buttonPin2, INPUT);// Button Red
  pinMode(13, OUTPUT);// LED Yellow
  pinMode(A1, OUTPUT);//Green LED
  pinMode(A2, OUTPUT);//Red LED
  pinMode(A0, INPUT);// POTENTIOMETER
  delay(5000);
}
void TurnMotorA(){
  digitalWrite(in1, LOW); //Switch between this HIGH and LOW to change direction
  digitalWrite(in2, HIGH);
  speed1 = analogRead(A0);
  speed1 = speed1*0.2492668622; 
  analogWrite(enA,speed1);
}

void loop() {
  lcd.print("MACHINE READY     ");
  digitalWrite(13, HIGH);//Yellow LED On
  buttonNew1 = digitalRead(buttonPin1);
  buttonNew2 = digitalRead(buttonPin2);
  if (buttonOld1 == 0 && buttonNew1 == 1){
    if(motorState == 0){
      TurnMotorA();
      lcd.print("MACHINE RUNNING    ");
  digitalWrite(A1, HIGH);//GREEN LED On
  digitalWrite(13, LOW);//YELLOW LED OFF
  digitalWrite(A2, LOW);//RED LED OFF
      motorState = 1;}
  if (buttonOld2 == 0 && buttonNew2 == 1){
    if(motorState == 1){
      digitalWrite(in2, LOW);
      digitalWrite(A2, HIGH);//RED LED ON
       digitalWrite(A1, LOW);//GREEN LED OFF
       digitalWrite(13, LOW);//YELLOW LED OFF
      motorState = 0;}
        buttonOld1 = buttonNew1;
        buttonOld2 = buttonNew2;
        delay(dt);
        
    }


  }
  }

Format your code and repost, use ‘CTRL T’ in the IDE.

Add a blank line after }

Thank you for the reply. It looks ok in the post preview once formatted but it says I have exceeded the number of allowed characters.

Might be just a simple change of ‘{’ locations.

in your example you nested the button2 ‘if’ within the button1 if.

See if this works?

#include <LiquidCrystal.h>
int in1 = 8;
int in2 = 9;
int enA = 10;
int speed1;
int buttonPin1 = 6; //START BUTTON
int buttonPin2 = 7; //STOP BUTTON
int buttonNew1;//Start
int buttonNew2;//Stop
int buttonOld1 = 1;
int buttonOld2 = 1;
int motorState = 0;//start with motor off
int dt = 100;

LiquidCrystal lcd(11, 12, 2, 3, 4, 5);

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.print("XENTRIC GUITARS         ");
  pinMode(in1, OUTPUT);//motor
  pinMode(enA, OUTPUT);//motor
  pinMode(in2, OUTPUT);//motor
  pinMode(buttonPin1, INPUT);// Button Green
  pinMode(buttonPin2, INPUT);// Button Red
  pinMode(13, OUTPUT);// LED Yellow
  pinMode(A1, OUTPUT);//Green LED
  pinMode(A2, OUTPUT);//Red LED
  pinMode(A0, INPUT);// POTENTIOMETER
  delay(5000);
}
void TurnMotorA() {
  digitalWrite(in1, LOW); //Switch between this HIGH and LOW to change direction
  digitalWrite(in2, HIGH);
  speed1 = analogRead(A0);
  speed1 = speed1 * 0.2492668622;
  analogWrite(enA, speed1);
}

void loop() {
  lcd.print("MACHINE READY     ");
  digitalWrite(13, HIGH);//Yellow LED On
  buttonNew1 = digitalRead(buttonPin1);
  buttonNew2 = digitalRead(buttonPin2);
  if (buttonOld1 == 0 && buttonNew1 == 1) {
    if (motorState == 0) {
      TurnMotorA();
      lcd.print("MACHINE RUNNING    ");
      digitalWrite(A1, HIGH);//GREEN LED On
      digitalWrite(13, LOW);//YELLOW LED OFF
      digitalWrite(A2, LOW);//RED LED OFF
      motorState = 1;
    }
  }
  if (buttonOld2 == 0 && buttonNew2 == 1) {
    if (motorState == 1) {
      digitalWrite(in2, LOW);
      digitalWrite(A2, HIGH);//RED LED ON
      digitalWrite(A1, LOW);//GREEN LED OFF
      digitalWrite(13, LOW);//YELLOW LED OFF
      motorState = 0;
    }

  }
  buttonOld1 = buttonNew1;
  buttonOld2 = buttonNew2;
  delay(dt);

}

It is closer! The LCD is giving me trouble displaying random characters and the motor wont start running. Thank you

FWIW, I’d pump the brakes a little and work one problem at a time.

Focus on a single element and get it working properly and then move on to another.

Because you’re using TWO distinct switches to start/stop, you don’t really need the state change check.

  if (buttonOld1 == 0 && buttonNew1 == 1) {
    if (motorState == 0) {
       //motor stuffs...
    }
  }

can become this:

  if ( digitalRead(buttonPin1) == 1) {   //  CHECKS FOR BUTTON PRESS
    if (motorState == 0) {  // IF MOTOR IS <OFF> THEN DO STUFF WITH IT...
       //motor stuffs...
    }
  }

maybe try the below code and see if it moves at all?

NOTE: For your button pins, I changed the pinmode to INPUT_PULLUP to handle the debounce. wiring them will be ---->Button----> So that when you press the button you’re passing it ground. This change makes the buttons trigger on ‘LOW’ instead of ‘HIGH’

#include <LiquidCrystal.h>
int in1 = 8;
int in2 = 9;
int enA = 10;
int speed1;
int buttonPin1 = 6; //START BUTTON
int buttonPin2 = 7; //STOP BUTTON
int buttonNew1;//Start
int buttonNew2;//Stop
int buttonOld1 = 1;
int buttonOld2 = 1;
int motorState = 0;//start with motor off
int dt = 100;

LiquidCrystal lcd(11, 12, 2, 3, 4, 5);

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.print("XENTRIC GUITARS         ");
  pinMode(in1, OUTPUT);//motor
  pinMode(enA, OUTPUT);//motor
  pinMode(in2, OUTPUT);//motor
  
  ///////////////////////////////
  pinMode(buttonPin1, INPUT_PULLUP);// Button Green [[[  PIN6----->BUTTON------>GND
  pinMode(buttonPin2, INPUT_PULLUP);// Button Red   [[[  PIN7----->BUTTON------>GND
  ///////////////////////////////
  
  pinMode(13, OUTPUT);// LED Yellow
  pinMode(A1, OUTPUT);//Green LED
  pinMode(A2, OUTPUT);//Red LED
  pinMode(A0, INPUT);// POTENTIOMETER

  
  delay(5000);
}
void TurnMotorA() {
  digitalWrite(in1, LOW); //Switch between this HIGH and LOW to change direction
  digitalWrite(in2, HIGH);
  
  //speed1 = analogRead(A0);
  //speed1 = speed1 * 0.2492668622;
  
  speed1 = 100;  //  TODO:  ADD Analog read to control speed AFTER basic motion works.
  
  analogWrite(enA, speed1);
}

void loop() {
  
  //lcd.print("MACHINE READY     ");
  digitalWrite(13, HIGH);//Yellow LED On
  
  if ( digitalRead(buttonPin1) == LOW ) {
    if (motorState == 0) {
      TurnMotorA();
      //lcd.print("MACHINE RUNNING    ");
      digitalWrite(A1, HIGH);//GREEN LED On
      digitalWrite(13, LOW);//YELLOW LED OFF
      digitalWrite(A2, LOW);//RED LED OFF
      motorState = 1;
    }
  }

  if ( digitalRead(buttonPin2) == LOW ) {
    if (motorState == 1) {
      digitalWrite(in2, LOW);
      digitalWrite(A2, HIGH);//RED LED ON
      digitalWrite(A1, LOW);//GREEN LED OFF
      digitalWrite(13, LOW);//YELLOW LED OFF
      motorState = 0;
    }
  }

  delay(dt);

}

How are your button switches wired?

Did some formatting, probably will not work.

Please try and report back.

//Version 1.0

#include <LiquidCrystal.h>

const byte buttonPin1 = 6; //START BUTTON +5V---[INPUT_PULLUP]---(input Pin 6)---[Switch]---GND
const byte buttonPin2 = 7; //STOP BUTTON  +5V---[INPUT_PULLUP]---(input Pin 7)---[Switch]---GND
const byte in1        = 8;
const byte in2        = 9;
const byte enA        = 10;

int speed1;
int dt = 100;

byte buttonNew1;           //Start
byte buttonNew2;           //Stop
byte buttonOld1       = 1;
byte buttonOld2       = 1;
byte motorState       = 0; //start with motor off

unsigned long switchMillis;

LiquidCrystal lcd(11, 12, 2, 3, 4, 5);

//********************************************************************************
void setup()
{
  Serial.begin(9600);

  pinMode(in1, OUTPUT);                //motor
  pinMode(in2, OUTPUT);                //motor
  pinMode(enA, OUTPUT);                //motor

  pinMode(buttonPin1, INPUT_PULLUP);   //Button Green
  pinMode(buttonPin2, INPUT_PULLUP);   //Button Red
  pinMode(13, OUTPUT);                 //LED Yellow
  pinMode(A1, OUTPUT);                 //Green LED
  pinMode(A2, OUTPUT);                 //Red LED

  //pinMode(A0, INPUT);                //POTENTIOMETER  <----<<<< line not needed

  lcd.begin(16, 2);
  //                   111111
  //         0123456789012345
  lcd.print("XENTRIC GUITARS ");
  delay(2000);

  lcd.setCursor(0, 0);
  //                   111111
  //         0123456789012345
  lcd.print("MACHINE READY   ");

  delay(5000);

} //END of setup()


//********************************************************************************
void loop()
{
  digitalWrite(13, HIGH);       //Yellow LED On <------<<<< WHY?

  //*******************************************
  //time to check the switches?
  if (millis() - switchMillis > 50)
  {
    switchMillis = millis();

    checkSwitches();
  }

  //*******************************************
  //other none blocking code goes here
  //*******************************************


} //END of loop


//********************************************************************************
void TurnMotorA()
{
  digitalWrite(in1, LOW);      //Switch between this HIGH and LOW to change direction
  digitalWrite(in2, HIGH);

  speed1 = analogRead(A0);
  speed1 = speed1 * 0.2492668622;
  speed1 = speed1 / 4;

  analogWrite(enA, speed1);

} //END of TurnMotorA()


//********************************************************************************
void checkSwitches()
{
  //*******************************************
  //buttonPin1 switch
  buttonNew1 = digitalRead(buttonPin1);
  if (buttonOld1 != buttonNew1)
  {
    //update to the new state
    buttonOld1 = buttonNew1;

    //********************
    if (buttonNew1 == LOW && motorState == 0)
    {
      motorState = 1;
      TurnMotorA();

      lcd.setCursor(0, 0);
      //                   111111
      //         0123456789012345
      lcd.print("MACHINE RUNNING ");

      digitalWrite(A1, HIGH);  //GREEN LED On
      digitalWrite(13, LOW);   //YELLOW LED OFF
      digitalWrite(A2, LOW);   //RED LED OFF

    }
  }

  //*******************************************
  //buttonPin2 switch
  buttonNew2 = digitalRead(buttonPin2);

  if (buttonOld2 != buttonNew2)
  {
    //update to the new state
    buttonOld2 = buttonNew2;

    //********************
    if (buttonNew2 == LOW && motorState == 1)
    {
      motorState = 0;
      digitalWrite(in2, LOW);

      lcd.setCursor(0, 0);
      //                   111111
      //         0123456789012345
      lcd.print("MACHINE STOPPED ");

      digitalWrite(A1, LOW);   //GREEN LED OFF
      digitalWrite(13, LOW);   //YELLOW LED OFF
      digitalWrite(A2, HIGH);  //RED LED ON

    }

    delay(dt);

  }

} //END of switchMillis()


//********************************************************************************

Please comment major lines in this sketch and re-post.

Thank you all for your help! I am trying these new codes as we speak. My switches are momentary buttons with 2 terminals. I have them wired now with pull-down 10k resistors. I am going to try with the pull-up methods you provided. I can't thank you enough! I will let you know!

Ok I tried both codes and both are very close to being perfect. Crowspost - your code only stopped the motor while the stop button was physically pressed. Larryd - your code just wouldn't allow the motor to turn back on with the start button once stopped. This is a business job I was assigned and I really appreciate you helping! Oh and both switches are now without resistors, just wired one side to ground and one side to the digital pin on arduino. Is that correct for am internal pullup?

Do the red and green LEDs alternate on to off?

What happens on the LCD?

//Version 1.01

//#define serialLCD

#ifdef  serialLCD

//********************************************************************************
#include <Wire.h>

//Use I2C library:     https://github.com/duinoWitchery/hd44780
//LCD Referance:       https://www.arduino.cc/en/Reference/LiquidCrystal
#include <hd44780.h>   //main hd44780 header

//NOTE:
//hd44780_I2Cexp control LCD using I2C I/O exapander backpack (PCF8574 or MCP23008)
//hd44780_I2Clcd control LCD with native I2C interface (PCF2116, PCF2119x, etc...)

#include <hd44780ioClass/hd44780_I2Cexp.h> //I2C expander i/o class header

//If you do not know what your I2C address is, first run the 'I2C_Scanner' sketch
hd44780_I2Cexp lcd(0x27);

//********************************************************************************

#else
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, 12, 2, 3, 4, 5);

#endif

//********************************************************************************

const byte buttonPin1 = 6; //START BUTTON +5V---[INPUT_PULLUP]---(input Pin 6)---[Switch]---GND
const byte buttonPin2 = 7; //STOP BUTTON  +5V---[INPUT_PULLUP]---(input Pin 7)---[Switch]---GND

const byte in1        = 8;
const byte in2        = 9;
const byte enA        = 10;

const byte yellowLED  = 13;
const byte greenLED   = A1;
const byte redLED     = A2;


int speed1;
int dt = 100;

byte buttonNew1;           //Start
byte buttonNew2;           //Stop
byte buttonOld1       = 1;
byte buttonOld2       = 1;
byte motorState       = 0; //start with motor off

unsigned long switchMillis;


//********************************************************************************
void setup()
{
  Serial.begin(9600);

  pinMode(in1, OUTPUT);                //motor
  pinMode(in2, OUTPUT);                //motor
  pinMode(enA, OUTPUT);                //motor

  pinMode(buttonPin1, INPUT_PULLUP);   //Button Green
  pinMode(buttonPin2, INPUT_PULLUP);   //Button Red
  pinMode(yellowLED, OUTPUT);          //LED Yellow
  pinMode(greenLED, OUTPUT);           //Green LED
  pinMode(A2, OUTPUT);                 //Red LED

  //pinMode(A0, INPUT);                //POTENTIOMETER  <----<<<< line not needed

  lcd.begin(16, 2);
  //                   111111
  //         0123456789012345
  lcd.print("XENTRIC GUITARS ");
  delay(2000);

  lcd.setCursor(0, 0);
  //                   111111
  //         0123456789012345
  lcd.print("MACHINE READY   ");

  delay(2000);

} //END of setup()


//********************************************************************************
void loop()
{
  digitalWrite(yellowLED, HIGH);       //Yellow LED On <------<<<< WHY?

  //*******************************************
  //time to check the switches?
  if (millis() - switchMillis > 50)
  {
    switchMillis = millis();

    checkSwitches();
  }

  //*******************************************
  //other none blocking code goes here
  //*******************************************


} //END of loop


//********************************************************************************
void TurnMotorA()
{
  digitalWrite(in1, LOW);      //Switch between this HIGH and LOW to change direction
  digitalWrite(in2, HIGH);

  speed1 = analogRead(A0);
  speed1 = speed1 * 0.2492668622;
  speed1 = speed1 / 4;

  analogWrite(enA, speed1);

} //END of TurnMotorA()


//********************************************************************************
void checkSwitches()
{
  //*******************************************
  //buttonPin1 switch
  buttonNew1 = digitalRead(buttonPin1);
  if (buttonOld1 != buttonNew1)
  {
    //update to the new state
    buttonOld1 = buttonNew1;

    //********************
    if (buttonNew1 == LOW && motorState == 0)
    {
      motorState = 1;
      TurnMotorA();

      lcd.setCursor(0, 0);
      //                   111111
      //         0123456789012345
      lcd.print("MACHINE RUNNING ");

      digitalWrite(greenLED, HIGH);   //GREEN LED On
      digitalWrite(yellowLED, LOW);   //YELLOW LED OFF
      digitalWrite(redLED, LOW);      //RED LED OFF

    }
  }

  //*******************************************
  //buttonPin2 switch
  buttonNew2 = digitalRead(buttonPin2);

  if (buttonOld2 != buttonNew2)
  {
    //update to the new state
    buttonOld2 = buttonNew2;

    //********************
    if (buttonNew2 == LOW && motorState == 1)
    {
      motorState = 0;
      digitalWrite(in2, LOW);

      lcd.setCursor(0, 0);
      //                   111111
      //         0123456789012345
      lcd.print("MACHINE STOPPED ");

      digitalWrite(greenLED, LOW);    //GREEN LED OFF
      digitalWrite(yellowLED, LOW);   //YELLOW LED OFF
      digitalWrite(redLED, HIGH);     //RED LED ON

    }

    delay(dt);

  }

} //END of switchMillis()


//********************************************************************************

Yes and they are working correctly. Basically when the motor is idle at startup the yellow LED is on. Then green is on when running and red is only on if stopped by the stop button.

The LCD is also working correctly now. It is only used to display the motor state.

Potentiometer in this version is disabled.

//Version 1.04

//#define serialLCD

#ifdef  serialLCD

//********************************************************************************
#include <Wire.h>

//Use I2C library:     https://github.com/duinoWitchery/hd44780
//LCD Referance:       https://www.arduino.cc/en/Reference/LiquidCrystal
#include <hd44780.h>   //main hd44780 header

//NOTE:
//hd44780_I2Cexp control LCD using I2C I/O exapander backpack (PCF8574 or MCP23008)
//hd44780_I2Clcd control LCD with native I2C interface (PCF2116, PCF2119x, etc...)

#include <hd44780ioClass/hd44780_I2Cexp.h> //I2C expander i/o class header

//If you do not know what your I2C address is, first run the 'I2C_Scanner' sketch
hd44780_I2Cexp lcd(0x27);

//********************************************************************************

#else
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, 12, 2, 3, 4, 5);

#endif

//********************************************************************************

const byte buttonPin1 = 6; //START BUTTON +5V---[INPUT_PULLUP]---(input Pin 6)---[Switch]---GND
const byte buttonPin2 = 7; //STOP BUTTON  +5V---[INPUT_PULLUP]---(input Pin 7)---[Switch]---GND

const byte in1        = 8;
const byte in2        = 9;
const byte enA        = 10;

const byte yellowLED  = 13;
const byte greenLED   = A1;
const byte redLED     = A2;

int speed1;
int dt = 100;

byte buttonNew1;           //Start
byte buttonNew2;           //Stop
byte buttonOld1       = 1;
byte buttonOld2       = 1;
byte motorState       = 0; //start with motor off

unsigned long switchMillis;
unsigned long potMillis;

//********************************************************************************
void setup()
{
  //Serial.begin(9600);

  pinMode(in1, OUTPUT);                //motor
  pinMode(in2, OUTPUT);                //motor
  pinMode(enA, OUTPUT);                //motor

  pinMode(buttonPin1, INPUT_PULLUP);   //Button Green
  pinMode(buttonPin2, INPUT_PULLUP);   //Button Red
  pinMode(yellowLED, OUTPUT);          //LED Yellow
  pinMode(greenLED, OUTPUT);           //Green LED
  pinMode(redLED, OUTPUT);             //Red LED
  digitalWrite(redLED, HIGH);

  //pinMode(A0, INPUT);                //POTENTIOMETER  <----<<<< line not needed

  lcd.begin(16, 2);
  //                   111111
  //         0123456789012345
  lcd.print("XENTRIC GUITARS ");
  delay(2000);

  lcd.setCursor(0, 0);
  //                   111111
  //         0123456789012345
  lcd.print("MACHINE READY   ");

  delay(2000);

} //END of setup()


//********************************************************************************
void loop()
{
  digitalWrite(yellowLED, HIGH);       //Yellow LED On <------<<<< WHY?

  //*******************************************
  //time to check the switches?
  if (millis() - switchMillis > 50)
  {
    switchMillis = millis();

    checkSwitches();
  }

  //*******************************************
  //time to display the pot setting?
  if (millis() - potMillis > 500)
  {
    potMillis = millis();

    displayPot();
  }


  //*******************************************
  //other none blocking code goes here
  //*******************************************


} //END of loop


//********************************************************************************
void TurnMotorA()
{
  digitalWrite(in1, LOW);      //Switch between this HIGH and LOW to change direction
  digitalWrite(in2, HIGH);

  speed1 = analogRead(A0);
  speed1 = 127;

  //  speed1 = speed1 * 0.2492668622;

  analogWrite(enA, speed1);

} //END of TurnMotorA()


//********************************************************************************
void checkSwitches()
{
  //*******************************************
  //buttonPin1 switch
  buttonNew1 = digitalRead(buttonPin1);
  if (buttonOld1 != buttonNew1)
  {
    //update to the new state
    buttonOld1 = buttonNew1;

    //********************
    if (buttonNew1 == LOW && motorState == 0)
    {
      motorState = 1;
      TurnMotorA();

      lcd.setCursor(0, 0);
      //                   111111
      //         0123456789012345
      lcd.print("MACHINE RUNNING ");

      digitalWrite(greenLED, HIGH);   //GREEN LED On
      digitalWrite(yellowLED, LOW);   //YELLOW LED OFF
      digitalWrite(redLED, LOW);      //RED LED OFF

    }
  }

  //*******************************************
  //buttonPin2 switch
  buttonNew2 = digitalRead(buttonPin2);

  if (buttonOld2 != buttonNew2)
  {
    //update to the new state
    buttonOld2 = buttonNew2;

    //********************
    if (buttonNew2 == LOW && motorState == 1)
    {
      motorState = 0;
      digitalWrite(in2, LOW);
      analogWrite(enA, 0);

      lcd.setCursor(0, 0);
      //                   111111
      //         0123456789012345
      lcd.print("MACHINE STOPPED ");
      lcd.setCursor(0, 1);
      //                   111111
      //         0123456789012345
      lcd.print("Speed =         ");
      lcd.setCursor(8, 1);
      lcd.print("0");

      digitalWrite(greenLED, LOW);    //GREEN LED OFF
      digitalWrite(yellowLED, LOW);   //YELLOW LED OFF
      digitalWrite(redLED, HIGH);     //RED LED ON

    }

    delay(dt);

  }

} //END of switchMillis()


//********************************************************************************
void displayPot()
{
  lcd.setCursor(0, 1);
  //                   111111
  //         0123456789012345
  lcd.print("Pot =           ");
  lcd.setCursor(8, 1);
  lcd.print(analogRead(A0)/4);

} //END of displayPot()

//********************************************************************************

Thank you! Do you know what would cause the LCD contrast to fade over time once the program has been running for a bit?

jre414:
Thank you! Do you know what would cause the LCD contrast to fade over time once the program has been running for a bit?

Show us a good image of your wiring.

The pot is enabled in this version but you will have to work on these lines yourself:

speed1 = analogRead(A0);
speed1 = speed1 / 4 ; <-----<<<< //this is not be needed if you keep the next line

// speed1 = speed1 * 0.2492668622; <-----<<<< Remember, you are using integer * float here

analogWrite(enA, speed1);

//Version 1.05

//#define serialLCD

#ifdef  serialLCD

//********************************************************************************
#include <Wire.h>

//Use I2C library:     https://github.com/duinoWitchery/hd44780
//LCD Referance:       https://www.arduino.cc/en/Reference/LiquidCrystal
#include <hd44780.h>   //main hd44780 header

//NOTE:
//hd44780_I2Cexp control LCD using I2C I/O exapander backpack (PCF8574 or MCP23008)
//hd44780_I2Clcd control LCD with native I2C interface (PCF2116, PCF2119x, etc...)

#include <hd44780ioClass/hd44780_I2Cexp.h> //I2C expander i/o class header

//If you do not know what your I2C address is, first run the 'I2C_Scanner' sketch
hd44780_I2Cexp lcd(0x27);

//********************************************************************************

#else
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, 12, 2, 3, 4, 5);

#endif

//********************************************************************************

const byte buttonPin1 = 6; //START BUTTON +5V---[INPUT_PULLUP]---(input Pin 6)---[Switch]---GND
const byte buttonPin2 = 7; //STOP BUTTON  +5V---[INPUT_PULLUP]---(input Pin 7)---[Switch]---GND

const byte in1        = 8;
const byte in2        = 9;
const byte enA        = 10;

const byte yellowLED  = 13;
const byte greenLED   = A1;
const byte redLED     = A2;

int speed1;
int dt = 100;

byte buttonNew1;           //Start
byte buttonNew2;           //Stop
byte buttonOld1       = 1;
byte buttonOld2       = 1;
byte motorState       = 0; //start with motor off

unsigned long switchMillis;
unsigned long potMillis;

//********************************************************************************
void setup()
{
  //Serial.begin(9600);

  pinMode(in1, OUTPUT);                //motor
  pinMode(in2, OUTPUT);                //motor
  pinMode(enA, OUTPUT);                //motor

  pinMode(buttonPin1, INPUT_PULLUP);   //Button Green
  pinMode(buttonPin2, INPUT_PULLUP);   //Button Red
  pinMode(yellowLED, OUTPUT);          //LED Yellow
  pinMode(greenLED, OUTPUT);           //Green LED
  pinMode(redLED, OUTPUT);             //Red LED
  digitalWrite(redLED, HIGH);

  //pinMode(A0, INPUT);                //POTENTIOMETER  <----<<<< line not needed

  lcd.begin(16, 2);
  //                   111111
  //         0123456789012345
  lcd.print("XENTRIC GUITARS ");
  delay(2000);

  lcd.setCursor(0, 0);
  //                   111111
  //         0123456789012345
  lcd.print("MACHINE READY   ");

  delay(2000);

} //END of setup()


//********************************************************************************
void loop()
{
  digitalWrite(yellowLED, HIGH);       //Yellow LED On <------<<<< WHY?

  //*******************************************
  //time to check the switches?
  if (millis() - switchMillis > 50)
  {
    switchMillis = millis();

    checkSwitches();
  }

  //*******************************************
  //time to display the pot setting?
  if (millis() - potMillis > 500)
  {
    potMillis = millis();

    displayPot();
  }


  //*******************************************
  //other none blocking code goes here
  //*******************************************


} //END of loop


//********************************************************************************
void TurnMotorA()
{
  digitalWrite(in1, LOW);      //Switch between this HIGH and LOW to change direction
  digitalWrite(in2, HIGH);

  speed1 = analogRead(A0);
  speed1 = speed1 / 4 ;

  //  speed1 = speed1 * 0.2492668622;

  analogWrite(enA, speed1);

} //END of TurnMotorA()


//********************************************************************************
void checkSwitches()
{
  //*******************************************
  //buttonPin1 switch
  buttonNew1 = digitalRead(buttonPin1);
  if (buttonOld1 != buttonNew1)
  {
    //update to the new state
    buttonOld1 = buttonNew1;

    //********************
    if (buttonNew1 == LOW && motorState == 0)
    {
      motorState = 1;
      TurnMotorA();

      lcd.setCursor(0, 0);
      //                   111111
      //         0123456789012345
      lcd.print("MACHINE RUNNING ");

      digitalWrite(greenLED, HIGH);   //GREEN LED On
      digitalWrite(yellowLED, LOW);   //YELLOW LED OFF
      digitalWrite(redLED, LOW);      //RED LED OFF

    }
  }

  //*******************************************
  //buttonPin2 switch
  buttonNew2 = digitalRead(buttonPin2);

  if (buttonOld2 != buttonNew2)
  {
    //update to the new state
    buttonOld2 = buttonNew2;

    //********************
    if (buttonNew2 == LOW && motorState == 1)
    {
      motorState = 0;
      digitalWrite(in2, LOW);
      analogWrite(enA, 0);

      lcd.setCursor(0, 0);
      //                   111111
      //         0123456789012345
      lcd.print("MACHINE STOPPED ");
      lcd.setCursor(0, 1);
      //                   111111
      //         0123456789012345
      lcd.print("Speed =         ");
      lcd.setCursor(8, 1);
      lcd.print("0");

      digitalWrite(greenLED, LOW);    //GREEN LED OFF
      digitalWrite(yellowLED, LOW);   //YELLOW LED OFF
      digitalWrite(redLED, HIGH);     //RED LED ON

    }

    delay(dt);

  }

} //END of switchMillis()


//********************************************************************************
void displayPot()
{
  lcd.setCursor(0, 1);
  //                   111111
  //         0123456789012345
  lcd.print("Pot =           ");
  lcd.setCursor(8, 1);
  lcd.print(analogRead(A0) / 4);

} //END of displayPot()

//********************************************************************************

You should now go through the sketch and document the major lines of code.

Two months from now you will be able to figure you what's happening ;),

I've deleted your other cross-post @jre414.

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Here is what I have. I tried to lay it out flat as it all fits in a small control panel. I also included the diagrams I used as references. I am using a 12v power supply rather than the 9V shown. The third button is just wired as a reset. Thank you very much!

Let’s see a good image of your actual wiring.

Edit:
You should not use pin D1 as it is used for serial communications.

Ok the image loaded finally as an attachment in the last reply