Hey guys, I copied a code off a website a couple months ago to be able to control the rotation of a my small 5v stepper motor with an analogue stick. The project worked, so when ever I pushed my analogue stick left or right it would cause my stepper motor to rotate accordingly (x axis). I then decided to add an additional stepper motor so that I can control Y axis. I managed to configure the code to move the second y-axis stepper motor when even the analogue stick way moving up down (y-axis). I added a laser pointer on one of the stepper motors and now I am able to control where the laser will point with the analogue stick.. cool.
Whenever I move the analogue stick left to right (x-axis), the first stepper motor moves accordingly and the LED's light up on the motor driver, when I let go of the analogue stick, the LED's on the driver board turn back off... this is corrects and has no problem. However, when I move the second analogue stick up or down (y-axis), the second stepper motor also moves accordingly with no problems, but the LED's on its driver board remain ON. Since the LED's are on for the second motor driver board, this indicates that the coils are energiesed in the motor, causing overheating. I've moticed the first stepper motor never gets hot, however the second stepper motor gets hot quick.
There is a problem with the code, but I cannot figure it out.
#include <Stepper.h>
const int stepsPerRevolution = 2048;
const int rolePerMinute = 10;
const int X_pin = 1;
const int Y_pin = 2;
const int laserPin = 6;
Stepper myStepper(stepsPerRevolution, 2, 4, 3, 5);
Stepper myStepper2(stepsPerRevolution, 9, 11, 10, 12);
void setup()
{
myStepper.setSpeed(rolePerMinute);
myStepper2.setSpeed(rolePerMinute);
pinMode(laserPin, OUTPUT);
digitalWrite(laserPin, HIGH);
}
void loop()
{
int a = analogRead(X_pin);
if (a > 400 && a < 520)
{
for (int i = 2; i < 6; i++)
{
digitalWrite(i, LOW);
}
}
else if (a < 400)
{
myStepper.setSpeed(rolePerMinute);
myStepper.step(-30);
}
else if (a > 530)
{
myStepper.setSpeed(rolePerMinute);
myStepper.step(30);
}
int b = analogRead(Y_pin);
if (b > 400 && b < 520)
{
for (int i = 2; i < 6; i++)
{
digitalWrite(i, LOW);
}
}
else if (b < 400)
{
myStepper2.setSpeed(rolePerMinute);
myStepper2.step(-30);
}
else if (b > 530)
{
myStepper2.setSpeed(rolePerMinute);
myStepper2.step(30);
}
}