Help - Irregular stepper motor behavior and overheating L298N driver

Project - Control speed and direction of 4 stepper motors with potentiometer and toggle switches respectively and display the speed of the stepper motor on a LCD.

Hardware -

Stepper motor - NEMA 17
Current - 1.5 A
Resistance - 2.8 ohms
Inductance - 5.5 mH
Holding Torque - 55 N.cm
Detent Torque - 2.6 N.cm
No. of Leads - 4 (bipolar)

Motor Driver - L298N
Logical Voltage - 5V
Drive voltage 5V - 35V
Logical currrent 0 - 36mA
Drive current - 2A
Max power - 25W

Power supply - 12V 10A

LCD - RG 1602 A

Arduino Mega

Problems -

1st - When the power is connected and pot value is changed to a non-zero value, the stepper motor rotates for 7-11 rotations as intended and then keeps taking a break of roughly 250ms, after every 0.75 - 1.5 rotation. Ideally the motors should run smoothly for a very long time.

2nd - As soon as I try to run even 3 motors together Arduino suffers a power outage and keeps restarting. Ideally all 4 motors should be able to run together at max speed and load.

3rd - After plugging in the power and not running any motor, the driver connecting the 5V to the Arduino gets extremely hot and starts smoking up.

Code -

#include <Stepper.h>
#include <LiquidCrystal.h>

#define switch1 31
#define switch2 33
#define switch3 35
#define switch4 37

const int stepsPerRevolution = 200;

Stepper myStepper1(stepsPerRevolution, 5, 4, 3, 2);
Stepper myStepper2(stepsPerRevolution, 9, 8, 7, 6);
Stepper myStepper3(stepsPerRevolution, 13, 12, 11, 10);
Stepper myStepper4(stepsPerRevolution, 23, 25, 27, 29);

LiquidCrystal lcd (38, 40, 42, 44, 46, 48);

int stepCount1 = 0;
int stepCount2 = 0;
int stepCount3 = 0;
int stepCount4 = 0;

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.clear();
  pinMode(switch1, INPUT_PULLUP);
  pinMode(switch2, INPUT_PULLUP);
  pinMode(switch3, INPUT_PULLUP);
  pinMode(switch4, INPUT_PULLUP);
}

void loop() {
  int sensorReading1 = analogRead(A0);
  int sensorReading2 = analogRead(A1);
  int sensorReading3 = analogRead(A2);
  int sensorReading4 = analogRead(A3);

  int toggle1 = digitalRead(switch1);
  int toggle2 = digitalRead(switch2);
  int toggle3 = digitalRead(switch3);
  int toggle4 = digitalRead(switch4);

  int motorSpeed1 = map(sensorReading1, 0, 1023, 0, 100);
  int motorSpeed2 = map(sensorReading2, 0, 1023, 0, 100);
  int motorSpeed3 = map(sensorReading3, 0, 1023, 0, 100);
  int motorSpeed4 = map(sensorReading4, 0, 1023, 0, 100);

  lcd.setCursor(0, 0);
  lcd.print("M1: " + (String) motorSpeed1 + " M2: " + (String) motorSpeed2 + " ");
  lcd.setCursor(0, 1);
  lcd.print("M3: " + (String) motorSpeed3 + " M4: " + (String) motorSpeed4 + " ");

  if (motorSpeed1 > 0 && toggle1 == 1)
  {
    myStepper1.setSpeed(motorSpeed1);
    myStepper1.step(stepsPerRevolution / 100);
  }
  if (motorSpeed1 > 0 && toggle1 == 0)
  {
    myStepper1.setSpeed(motorSpeed1);
    myStepper1.step(-(stepsPerRevolution / 100));
  }

  if (motorSpeed2 > 0 && toggle2 == 1)
  {
    myStepper2.setSpeed(motorSpeed2);
    myStepper2.step(stepsPerRevolution / 100);
  }
  if (motorSpeed2 > 0 && toggle2 == 0)
  {
    myStepper2.setSpeed(motorSpeed2);
    myStepper2.step(-(stepsPerRevolution / 100));
  }

  if (motorSpeed3 > 0 && toggle3 == 1)
  {
    myStepper3.setSpeed(motorSpeed3);
    myStepper3.step(stepsPerRevolution / 100);
  }
  if (motorSpeed3 > 0 && toggle3 == 0)
  {
    myStepper3.setSpeed(motorSpeed3);
    myStepper3.step(-(stepsPerRevolution / 100));
  }

  if (motorSpeed4 > 0 && toggle4 == 1)
  {
    myStepper4.setSpeed(motorSpeed4);
    myStepper4.step(stepsPerRevolution / 100);
  }
  if (motorSpeed4 > 0 && toggle4 == 0)
  {
    myStepper4.setSpeed(motorSpeed4);
    myStepper4.step(-(stepsPerRevolution / 100));
  }
  Serial.println(motorSpeed1);
  Serial.println(sensorReading1);
}

Circuit - image attached

An L298 is not suitable for controlling a 1.5Amp 2.8Ohms stepper motor. You need a specialised stepper motor driver such as the DRV8825 which can be adjusted to limit the current to protect the motor. Then you can use a high voltage (12v or more up to the limit of the DRV8825) for better performance.

The DRV8825 also takes a substantial amount of the computation load off the Arduino.

...R
Stepper Motor Basics
Simple Stepper Code