Hello! I just joined this sub hoping to shed some light into a stepper motor cirquit/code issue I am running into for a project of mine.
The components I am using are:
- An Arduino Uno
- A L298N motor driver.
- A NEMA 8 Bipolar stepper Motor. ( 3.6V 1.8 degrees/step, 0.6A/Phase, 0.20kg.cm holding torque)
- A configurable power supply (set at 6V)
- 4X4 keypad
- Bread board
- Jumper cables
I have followed the exact circuit found on here and I have added a keypad in order to use two of its buttons (4,6) for directional control of the stepper motor.
I am trying it make it do one full revolution which for this motor is 200 steps (360/1.8). However no matter what RPM I choose the motor fails to do so, or barely makes it but with almost no torque. In some cases, usually when i choose very low or very high RPMS the shaft stays completely still, (while the motor is trying to spin).
I am trying to narrow done the cause of why this is heppening and so far I have come up with 3 possible explanations:
1)Wrong voltage input at the L298N driver
-
Wrong choice of Driver.
-
Problems with my code
I would greatly appreciate any input so I can move forward with my project.
Thank you!
My code:
#include <Keypad.h>
const int ROW_NUM = 1; //one row
const int COLUMN_NUM = 3; //three columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'4','5','6'},
};
byte pin_rows[ROW_NUM] = {7}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
#include <Stepper.h>
// Number of steps per output rotation
const int stepsPerRevolution = 200;
// Create Instance of Stepper library
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop()
{
char key = keypad.getKey();
if (key){
Serial.println(key);
if(key == '4') {
myStepper.step(-stepsPerRevolution);
Serial.print ("left");
}
if(key=='6'){
myStepper.step(stepsPerRevolution);
Serial.print ("right");
}
if(key=='5'){
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
Serial.print ("stop");
}
}
}