Problem controlling motors

Hello everyone , I have been trying to control a Nema 17 bipolar Stepper Motor and a mini water pump with a Keypad Matrix through an Arduino Mega 2560. The stepper motor is driven with a DRV8825 driver and powered with a 12V 2A DC wall wart . The pump is powered with 3 AA batteries and interfaced with a relay module in order to connect it to Arduino.
The main idea would be to press a specific button on the keypad so the Stepper motor would start spinning anti clockwise with 4 Revs , then it will wait for the water pump to turn on/off. Finally the stepper spins clockwise with 4 revs as well.
The problem is that the Stepper motor jitters when I power the whole circuit . The issue could be the way the circuit is wired or in the code, but I just can t figure out which is . I tested each component separately and they work just fine.

The specifications for the Stepper Motor are the following:

  • Step angle : 1.8 deg
  • Holding torque: 40 Ncm
  • Rated curreng/phase : 1.7 A
  • Phasde resistance: 1.5 Ohm
  • Insulation Resistance : 100 Mohm
  • Insulation Strength : 500 VAC
    The power source for the step motor is a 12V 2A DC wall wart and for the connection with the arduino board I am using this expansion board .
    The pump typically runs on 3-6 V and consumes 100-200 mA.
    Any help would be appreciated .

Here is the schematic of the circuit:

The code :


#include <Wire.h>
#include <Keypad.h>// Keypad library
const int dirPin = 37;
const int stepPin = 2;
const int stepsPerRevolution = 200;
int Relay = 52;

const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
byte rowPins[ROWS] = {12, 11, 10, 9};
byte colPins[COLS] = {8, 7, 6, 5};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup()
pinMode(Relay, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
void loop()
char customKey = customKeypad.getKey();
if (customKey == '1')
// Set the motor direction anticlockwise
digitalWrite(dirPin, LOW);

// Spin the motor with 4 revs
for (int x = 0; x < 4 * stepsPerRevolution; x++)
  digitalWrite(stepPin, HIGH);
  digitalWrite(stepPin, LOW);

//Turn on the water pump
digitalWrite(Relay, HIGH);
digitalWrite(Relay, LOW);

// Set motor direction clockwise
digitalWrite(dirPin, HIGH);
// Spin motor slowly with 4 revs
for (int x = 0; x < 4 * stepsPerRevolution; x++)
  digitalWrite(stepPin, HIGH);
  digitalWrite(stepPin, LOW);




What happens if you run your stepper test code with the other components connected?

Well , I have tried to do that but it has the same problem . I even tried to remove the Keypad from the circuit just to see if it works that way but still no results .

Your schematic doesn’t show how the Arduino is powered and what type of relay module you have ( ie can the Arduino drive it ?)

Yes sorry, I forgot to mention these things. The arduino is powered from the USB port and the relay is a typical 5V relay module compatible with the Arduino board .

Does the stepper jitter when its supposed to be moving, or all the time? The latter suggests noise getting into the step signal wire.

I'd strongly recommend using AccelStepper library to the stepper is speed-ramped - this
is normally required for reliable operation, motors cannot accelerate instantly.

Well , I have noticed a change in the stepper's behaviour. After I tested the circuit again , I noticed that the stepper starts well, moves with 4 revs but seems to jitter right before the pump is supposed to start.

Suggests interference from the motor circuit (where is the required free-wheel diode for instance - inductive loads need this).

Alternatively there might be poor layout with the step signal vulnerable to
noise pickup?

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