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 https://www.makerlab-electronics.com/product/a4988-drv8825-stepper-motor-control-extension-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 :
Blockquote
#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);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
delay(3000);
//Turn on the water pump
digitalWrite(Relay, HIGH);
delay(2000);
digitalWrite(Relay, LOW);
delay(1000);
// Set motor direction clockwise
digitalWrite(dirPin, HIGH);
// Spin motor slowly with 4 revs
for (int x = 0; x < 4 * stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
delay(3000);
else
{
digitalWrite(Relay,LOW);
}
}
Blockquote