Forgive my lack of knowledge I am very much a noob at this kind of thing.
I'm in the process of creating my first Arduino project, it requires two stepper motors (28BYJ-48's) linked to the arduino using two ULN2003 Driver boards.
These are being powered currently by a Breadboard Power Supply module connected to a 9V battery.
This all seems to work fine with a single stepper but stops with the introduction of the second.
I'm pretty certain from extensive research that this should be possible with the set up I have and that the circuitry is correct (I'm having problems finding an application to draw out the circuit I have that includes these stepper motors and the Driver boards I am using, tinkerCad seems to be lacking in this department, if there is one I am missing, perhaps someone could provide me a link?)
So the first problem is just that, I am unable to get both steppers to work together, and not just vibrate, is this a power issue? or is there something obvious I am missing?
The second issue is related to the code.
//Libraries
#include "Stepper.h"
#include "IRremote.h"
//Variables
#define STEPS 32
int Steps2Take; // 2048 = 1 Revolution
int Steps2TakeRight; // 2048 = 1 Revolution
int receiver = 12; // Signal Pin of IR receiver to Arduino Digital Pin 6
boolean walkCycle;
//Objects
Stepper stepperLeft(STEPS, 8, 10, 9, 11);
Stepper stepperRight(STEPS, 4, 6, 5, 7);
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
void setup()
{
irrecv.enableIRIn(); // Start the receiver
Serial.begin(9600);
}
void loop()
{
if (irrecv.decode(&results)) // Check for IR signal
{
switch(results.value)
{
case 0xFFA25D: // POWER Button Pressed
if (walkCycle == 0){walkCycle = 1;}
else{walkCycle = 0;}
Serial.println("POWER");
Serial.println(walkCycle);
break;
case 0xFFA857: // VOL+ button pressed
stepperLeft.setSpeed(500);
Steps2Take = 2048; // Rotate once CW
stepperLeft.step(Steps2Take);
Serial.println("VOL+");
break;
case 0xFF629D: // VOL- button pressed
stepperLeft.setSpeed(500);
Steps2Take = -2048; // Rotate once CCW
stepperLeft.step(Steps2Take);
break;
}
irrecv.resume(); // receive the next value
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}
if (walkCycle == 1)
{
stepperLeft.setSpeed(500);
stepperRight.setSpeed(500);
Steps2Take = -10; // Rotate CW <---- Why am I having to make this -ve for CW rotation?
Steps2TakeRight = 10; // Rotate CCW
Serial.println("walkCycle Active");
stepperLeft.step(Steps2Take);
//stepperRight.step(Steps2TakeRight);
}
}
In the switch statement, I am able to control the direction of the rotation correctly, with a +ve Steps2Take rotating the motor Clockwise and -ve going Counter Clockwise.
But using the if statement below I have to invert this to get the correct direction, why is this? I know from prior coding experience forcing something to do what you want by hardcoding backward like I have done here is generally a bad idea and can cause issues later, I just wondered if anyone has any suggestions as to why this is.
Finally, the Breadboard power module is clearly not intended for use in the final project, should I be looking into getting a something such as a Adafruit Power Boost Shield for the final project.