### 8 responses to “Arduino 28BYJ-48 stepperbot”

1. Your sketch can be a lot simpler by using helper functions and lookup tables.
Here are some suggestions to get you started.
(None of this has been tested for syntax or function, but if you can understand
what I’m suggesting, you will see how to shrink your code.)

// What are the current positions of the motors
// Start them all at position zero
int8_t currentSteps = [0,0,0,0];

// What pattern to use for each step phase
const uint8_t steptable = [
[HIGH,LOW,LOW,LOW],[HIGH,HIGH,LOW,LOW],
[LOW,HIGH,LOW,LOW],[LOW,HIGH,HIGH,LOW],
[LOW,LOW,HIGH,LOW],[LOW,LOW,HIGH,HIGH],
[LOW,LOW,LOW,HIGH],[HIGH,LOW,LOW,HIGH]];

const int8_t speedForward = [1,1,1,1];
const int8_t speedBackward = [-1,-1,-1,-1];

// motor 1 = backward / motor 2 = forward / motor 3 = forward / motor 4 = backward
// From your comment for sideleft. By the way, a software person
// would number the motors starting from 0
const int8_t speedSideLeft = [-1,1,1,-1];
//etc.

// Motor is 0,1,2,3 .
// Step can be any number, but then it gets divided down by 8 and the
// remainder is the step that’s used
int StepMotor(int motor, int step)
{
step = step % 8; // The % operator takes the remainder when divided by 8
if (step < 0) step += 8; // The remainder can be negative (-7 to -1), so fix that
for (int wire = 0; wire < 4 ; wire++)
{
setRegisterPin(wire + 4*motor, steptable[step][wire]);
}
return step;
}

void StepBySpeed(const int8_t speed)
{
for (int motor = 0 ; motor = previousMicros)
{
previousMicros = previousMicros+stepInterval;
StepBySpeed(speedForward);
}
}

// etc.

2. // Some of the code got mangled. Starting with StepBySpeed:

void StepBySpeed(const int8_t speed)
{
for (int motor = 0 ; motor = previousMicros)
{
previousMicros = previousMicros+stepInterval;
StepBySpeed(speedForward);
}
}

// etc.

3. WordPress keeps corrupting the code. I sent you the code by email instead.

4. To publish code use Sytanx Highlighter plugin. You can then publish nice code with all indentations and proper formating.

5. where did you get the wheels, and how did you fix them to the motor?

This site uses Akismet to reduce spam. Learn how your comment data is processed.