Using a xy-1600d motor and an arduino mega. No matter the code I use I cannot get my stepper motor to go through a complete rotation. I'm just getting into using an arduino and I don't even know for sure what I don't know. Is there any way to find a mentor or a website that I can have a back and forth with an actual person so that I can get some answers to some questions?
Here is a good place for that
Please post your code and explain exactly what you want to do.
Please follow the advice given in the link below when posting code , use code tags and post the code here to make it easier to read and copy for examination
And, besides your code, we need information on your hardware and how it is wired. Post data sheets for the motor, motor driver and motor power supply.
Post a schematic of your wiring. See here for how to make and post a schematic.
What Arduino board?
I can't find any "xy-1600d" motor on the internet. Did you mean an XY-160D dual H-Bridge DC motor driver?
I have an arduino connected to a xy-160d motor driver. I have this motor 4218M-07connected to this motor controller.
The pin configuration is:
5V-5V
GND-GND
ENA-PIN 6
IN1-PIN 5
IN2-PIN 4
ENB-PIN 9
IN3-PIN 8
IN4-PIN7
const int IN1=5;
const int IN2=4;
const int ENA=6;
const int IN3=8;
const int IN4=7;
const int ENB=9;
void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(ENB, OUTPUT);
}
void loop() {
Motor1_Brake();
Motor2_Brake();
delay(100);
Motor1_Forward(200);
Motor2_Forward(200);
delay(1000);
Motor1_Brake();
Motor2_Brake();
delay(100);
Motor1_Backward(200);
Motor2_Backward(200);
delay(1000);
}
void Motor1_Forward(int Speed)
{
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
analogWrite(ENA,Speed);
}
void Motor1_Backward(int Speed)
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
analogWrite(ENA,Speed);
}
void Motor1_Brake()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
}
void Motor2_Forward(int Speed)
{
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
analogWrite(ENB,Speed);
}
void Motor2_Backward(int Speed)
{
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
analogWrite(ENB,Speed);
}
void Motor2_Brake()
{
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
}
With the code from above and 16V applied to the motor controller I can get movement from the motor. But the motor only turns a few degrees in about 1 second intervals. After a few movements it will just sit and buzz for a second then continue with it's movements. I've tried commenting out parts of the code, changing variables and delay times, and motor forward and reverse integers. I have some experience with javascript and C++ but even with watching youtube tutorials and reading articles I've not been able to crack this code. I haven't had to do any real coding in 15 years and I'm lost.
The motor controller that you linked to does not look to me to be suitable for use with the stepper motor that you linked to. How is the motor connected to the controller ?
Out1 and Out2 are connected to one coil. Out3 and OUT4 are connected to the other coil.
That is how you control two DC motors, not how you control one stepper. Look for an example of using the L298 to drive a stepper ant use that as an example.
Here is one such example:
The code with it look like this:
/* Example sketch to control a stepper motor with L298N motor driver, Arduino UNO and Stepper.h library. More info: https://www.makerguides.com */
// Include the Stepper library:
#include <Stepper.h>
// Define number of steps per revolution:
const int stepsPerRevolution = 200;
// Initialize the stepper library on pins 8 through 11:
Stepper myStepper = Stepper(stepsPerRevolution, 8, 9, 10, 11);
void setup()
{
// Set the motor speed (RPMs):
myStepper.setSpeed(100);
}
void loop()
{
// Step one revolution in one direction:
myStepper.step(stepsPerRevolution);
delay(2000);
// Step on revolution in the other direction:
myStepper.step(-stepsPerRevolution);
delay(2000);
}
That works. I appreciate the help. Thank you.
Is it ok if I ask more questions in this thread or do I need to start a new thread for each and every question I have? Looking under the faq I don't see any rule against it but I don't know if it's against the forum etiquette.
If the questions would benefit from posters knowing the background that is in this topic then continue here. If not, start a new topic
Thank all of you who have replied to me so far. I'm on call all week and I don't have much time to ask the questions I need to understand the project I've started. I will need to ask more questions in this thread, but until I get the chance to actually sit down at my work table and put some time on this how can I best support the forum?
The code works just fine for my smaller motor 4218M-07. However when I plug in my larger motor it just buzzes and vibrates a little. For the life of me I cannot find a data sheet for it. The label says C8984-9212E DC 5.4v 1.5A/phase 0.9°/STEP. I figured that since this one has double the steps I needed to double the stepsPerRevolution variable to 400 but it still just buzzes and shakes. What am I missing? I don't even need to use this motor, but I really want to understand.
For that motor you will need a current limiting stepper driver. The DRV8825 module from Pololu will work, but be sure to follow instructions on how to set the current limit to 1.5A or less. The motor power supply must be 8V minimum, and capable of supplying around 3A.
@ jremington. Is there any way I can direct messenger you? I've got a lot of questions and I'd love to ask you some of them if you can take the time to help me.
I don't answer PMs. Please keep the discussion open, in the forum.
There are countless tutorials on line about wiring and using stepper motors.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.