user1290: I have a stepper motor connected to my Arduino like this using the ULN2003A Darlington Array:


(Ignore the potentiometer)
And I have programmed it with the following code:
#include <Stepper.h>

int in1Pin = 22;
int in2Pin = 23;
int in3Pin = 24;
int in4Pin = 25;

Stepper motor(512, in1Pin, in2Pin, in3Pin, in4Pin);

void setup()
{
    pinMode(in1Pin, OUTPUT);
    pinMode(in2Pin, OUTPUT);
    pinMode(in3Pin, OUTPUT);
    pinMode(in4Pin, OUTPUT);

    motor.setSpeed(25);
}

void loop()
{
    int steps = 360;

    motor.step(steps);
    delay(500);
}

At the moment the motor rotates clockwise, how could I have it so it rotates in the opposite direction?
My code was copied and edited from here.

The problem was that I had the two middle wires the wrong way round as said here: http://forum.arduino.cc/index.php?PHPSESSID=kvi8dt2b5en5hhk02dlmjrotl5&topic=143276.msg‌​

user220: The answer is simple. Just pass a negative number of steps as an argument to motor.step();.
Another note: You forgot a semicolon on your second to last line. IIRC this doesn't matter in C, but it's just bad practice to do this. If you add a line of code below that, then it won't work.
Example code:
#include <Stepper.h>

int in1Pin = 22;
int in2Pin = 23;
int in3Pin = 24;
int in4Pin = 25;

Stepper motor(512, in1Pin, in2Pin, in3Pin, in4Pin);

void setup()
{
    pinMode(in1Pin, OUTPUT);
    pinMode(in2Pin, OUTPUT);
    pinMode(in3Pin, OUTPUT);
    pinMode(in4Pin, OUTPUT);

    motor.setSpeed(25);
}

void loop()
{
    int steps = 360;
    motor.step(steps);
    delay(100);

    steps = -360;
    motor.step(steps);
    delay(500); //Semicolon added
}


1290: <p>I have a stepper motor connected to my Arduino like this using the ULN2003A Darlington Array:</p>

<p><img src="https://arduino.cc/en/uploads/Reference/unipolar_stepper_four_pins.jpg" alt="Circuit Diagram"><br>
<img src="https://static.flickr.com/32/54357295_756c131217.jpg" alt="Image">
(Ignore the potentiometer)</p>

<p>And I have programmed it with the following code:</p>

<pre><code>#include &lt;Stepper.h&gt;

int in1Pin = 22;
int in2Pin = 23;
int in3Pin = 24;
int in4Pin = 25;

Stepper motor(512, in1Pin, in2Pin, in3Pin, in4Pin);

void setup()
{
    pinMode(in1Pin, OUTPUT);
    pinMode(in2Pin, OUTPUT);
    pinMode(in3Pin, OUTPUT);
    pinMode(in4Pin, OUTPUT);

    motor.setSpeed(25);
}

void loop()
{
    int steps = 360;

    motor.step(steps);
    delay(500);
}
</code></pre>

<p>At the moment the motor rotates clockwise, how could I have it so it rotates in the opposite direction?</p>

<p>My code was copied and edited from <a href="http://learn.adafruit.com/adafruit-arduino-lesson-16-stepper-motors/arduino-code" rel="nofollow noreferrer">here</a>.</p>

<hr>

<p>The problem was that I had the two middle wires the wrong way round as said here: <a href="http://forum.arduino.cc/index.php?PHPSESSID=kvi8dt2b5en5hhk02dlmjrotl5&amp;topic=143276.msg" rel="nofollow noreferrer">http://forum.arduino.cc/index.php?PHPSESSID=kvi8dt2b5en5hhk02dlmjrotl5&amp;topic=143276.msg</a>‌​</p>
 220: <p>The answer is simple. Just pass a negative number of steps as an argument to <code>motor.step();</code>.</p>

<p>Another note: You forgot a semicolon on your second to last line. IIRC this doesn't matter in C, but <strong>it's just bad practice to do this.</strong> If you add a line of code below that, then it won't work.</p>

<p>Example code:</p>

<pre><code>#include &lt;Stepper.h&gt;

int in1Pin = 22;
int in2Pin = 23;
int in3Pin = 24;
int in4Pin = 25;

Stepper motor(512, in1Pin, in2Pin, in3Pin, in4Pin);

void setup()
{
    pinMode(in1Pin, OUTPUT);
    pinMode(in2Pin, OUTPUT);
    pinMode(in3Pin, OUTPUT);
    pinMode(in4Pin, OUTPUT);

    motor.setSpeed(25);
}

void loop()
{
    int steps = 360;
    motor.step(steps);
    delay(100);

    steps = -360;
    motor.step(steps);
    delay(500); //Semicolon added
}
</code></pre>
