Stop a stepper motor without consuming current

I am trying to control a stepper motor using a potentiometer. When the potentiometer is at 0 the motor should run in reverse at full speed, in the middle, the stepper motor should stop, which it does fine and at maximum, the motor runs at full speed. The problem I am having is when the stepper motor stops it consumes a large amount of current and the controller would overheat even with the huge heatsink I have on it. I am using the standard stepper library and I am looking for a way just to make the motor stop without consuming current and holding the rotor in place.

My controller is an L298N

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor


// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

int stepCount = 0;  // number of steps the motor has taken

void setup() {
  // nothing to do inside the setup
}

void loop() {
  // read the sensor value:
  int sensorReading = analogRead(A0);
  // map it to a range from 0 to 100:
  int motorSpeed = map(sensorReading, 0, 1023, 140, 250);
  // set the motor speed:
  if (motorSpeed > 195) 
  {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution / 100);
  }
   if (motorSpeed < 195) 
  {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(-stepsPerRevolution / 100);
  }
}

RB358:
My controller is an L298N

Which is not suitable for stepper motors.
Leo..

If you want the stepper motor to hold position, it must be powered at all times (not necessarily full power).

Post a link to the motor product page or data sheet, and we can recommend a suitable, modern motor driver.

A low on the enable pin disables the driver outputs.

A low on the enable pin disables the driver outputs. That said, I echo the recommendation that you use a suitable modern driver.

I finally fixed it just by using the accel stepper library and the following program, I will work out getting it to run in reverse later on.

// ConstantSpeed.pde
// -*- mode: C++ -*-
//
// Shows how to run AccelStepper in the simplest,
// fixed speed mode with no accelerations
/// \author  Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2009 Mike McCauley
// $Id: ConstantSpeed.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
int motorspeed = 0;
int sensorread = 0;
void setup()
{  
   stepper.setMaxSpeed(1000);
   stepper.setSpeed(0);	
}

void loop()
{ 
  sensorread = analogRead(A0);
  motorspeed = map(sensorread, 0, 1023, 500, 1000);

  if (sensorread >= 10)
  {
  stepper.enableOutputs();
  stepper.setSpeed(motorspeed);  
  stepper.runSpeed();
  }
   if (sensorread < 10)
  {
    stepper.disableOutputs();
  }
}

Wawa:
Which is not suitable for stepper motors.
Leo..

Hi RB358,

What Leo is saying here right. Your Controller is for a DC MOTOR not a STEPPER MOTOR. (Sorry if im wrong Leo) they are totally different systems and not compatible.
(Quick edit add on: Upon further searching i find there are stepper motor units with that number (chip number) sorry for jumping the gun!

Daz

The L298 not being the right choice for a stepper motor has been discussed many times in the "Motors, Mechanics, and Power" part of this forum. Not going into that again here.
The poor choice for a low voltage, high current brushed DC motor also has been mentioned here many times.
This ancient lossy BJT-transistor based driver is really only suitable for high voltage/low current motors (12 or 24volt and <= 1Amp). The only reason it's popular is because it's cheap. There are much better mosfet-based H-bridges out there.
Leo..

Thank you for clarification.

Daz
(Karma added for good advice)

Daz1712:
(Quick edit add on: Upon further searching i find there are stepper motor units with that number (chip number) sorry for jumping the gun!

That it works/can be made to work doesn't necessarily make it a good solution. OP complaining about an overheating heat sink is a clear indication of that being the case here.

These links may be of interest
Stepper Motor Basics
Simple Stepper Code

...R