The Start


Hi, What and Why

Plug it in

Rule number 1

Water Sensor

Sound Sensor

Joystick

Tri Colour LED

RTC (Real Time Clock) DS1302

RTC (Real Time Clock) DS3231

Matrix LED step 1

LCD

Stepper Motor

LCD revisited with PCF8574T

Humidity Sensor

Shift Register

RFID tags (RC-522)

7 Segment display

Ultrasonic distance sensor

5V regulator

analogRead and analogWrite

Wiring an Array of Switches

The next step


Other things I have bought

Infra red and Processing

Programming a separate arduino chip

Creating your own PCB

L293D for a DC motor

4 digit 7 segment display

Starting with motors

RF433 Wireless Comms

Sort a character array

More stuff


I2C devices (SDA,SCL)

I2C scanner

SPI devices (MOSI,MISO)

HMC5883L Compass

MMA7361 Accelerometer

Added projects


Message Display System

4WD robot car
4WD robot car II

4WD robot car COMPLETE

MP3 Player

Stepper Motor 28BYJ-48


A stepper motor (28BYJ-48) and controller board (based on chip ULN2003APG). Stepper motor 28BYJ-48

This seems to be the most common stepper motor included as part of an Arduino kit. I spent quite a while tinkering with different libraries and techniques (some details at bottom of page), and it turned out that straightforward code was the best answer for this piece of kit.

Wired up and working.
IN1 - Arduino Pin 8
IN2 - Arduino Pin 9
IN3 - Arduino Pin 10
IN4 - Arduino Pin 11
Stepper motor 28BYJ-48

This straightforward code works perfectly for me; no additional libraries.

// This Arduino example demonstrates bidirectional operation of a
// 28BYJ-48, using a ULN2003 interface board to drive the stepper.
// The 28BYJ-48 motor is a 4-phase, 8-beat motor, geared down by
// a factor of 68. One bipolar winding is on motor pins 1 & 3 and
// the other on motor pins 2 & 4. The step angle is 5.625/64 and the
// operating Frequency is 100pps. Current draw is 92mA.
////////////////////////////////////////////////

//declare variables for the motor pins
int motorPin1 = 8;    // IN 1
int motorPin2 = 9;    // IN 2
int motorPin3 = 10;   // In 3
int motorPin4 = 11;   // IN 4

int motorSpeed = 1000;  //variable to set stepper speed
                        // Experiment with this; too small will not work.
int count = 0;          // count of steps made
int countsperrev = 512; // number of steps per revolution for this motor

int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};


void setup() 
  {
  //declare the motor pins as outputs
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  Serial.begin(9600);
  }

void loop()
  {
  int i;

  for (i = 0; i < countsperrev; i++)
    {
      clockwise();
    }
  for (i = 0; i < countsperrev; i++)
    {
      anticlockwise();
    }

  }

/////
//set pins to ULN2003 high in sequence from 1 to 4
//delay "motorSpeed" between each pin setting (to determine speed)
/////
void anticlockwise()
{
  for(int i = 0; i < 8; i++)
  {
    setOutput(i);
    delayMicroseconds(motorSpeed);
  }
}

void clockwise()
{
  for(int i = 7; i >= 0; i--)
  {
    setOutput(i);
    delayMicroseconds(motorSpeed);
  }
}

void setOutput(int out)
{
  digitalWrite(motorPin1, bitRead(lookup[out], 0));
  digitalWrite(motorPin2, bitRead(lookup[out], 1));
  digitalWrite(motorPin3, bitRead(lookup[out], 2));
  digitalWrite(motorPin4, bitRead(lookup[out], 3));
}
   		

I found, and experimented with, a few other libraries that you may want to investigate; AccelStepper is a curious one, and AFmotor from adafruit is a good one. Both need in-depth examination to see if they're suitable for your own needs.

This webpage by 4tronix contains an excellent wiring diagram,
and this webpage I also found useful information on.

Put a Gear on it

I have always found major problems finding a suitable gear for a motor. There are so many varieties and sizes of gear shaft. Here, I have bought a small pack of plastic gears, used an electric drill bit to slightly enlarge the hole, and shoved it on. This one is working well.

Plastic gear with resized hole, shoved on to the motor shaft. Try a google search for "5 Plastic Tooth Cogs Gears For 4mm & 2mm Motor Shaft" Stepper motor gear