Things used in this project

Parts & Materials:
Stepper Motor 28byj-48
×1
Fairchild semiconductor pn2222abu. image
General Purpose Transistor NPN
×4
09590 01
LED (generic)
×4
Mfr 25fbf52 221r sml
Resistor 221 ohm
×4
Mfr 25frf52 10k sml
Resistor 10k ohm
×1
Omron b3f 1000 image 75px
Tactile Button Switch (6mm) Single
×1
11026 02
Jumper wires (generic)
×1
A000066 iso both
Arduino UNO & Genuino UNO
×1
12002 04
Breadboard (generic)
×1
Software apps and online services:
Ide web
Arduino IDE

Schematics

Schematics
The schematics of the Circuit for driving a stepper motor from an Arduino
Slider schem lmc8xhsm2d
Breadboard
The breadboard of a circuit to drive a unipolar stepper motor from an Arduino
Slider bb s8dme4ebmg

Code

TinyStepperArduino
ArduinoISP code for the Arduino.
int directionPin = 4;
int motorPins[4] = {0,1,2,3};
byte motorSequence[8] = {B1000,B1100,B0100,B0110,B0010,B0011,B0001,B1001}; 
int motorDirection = 0;
int motorSpeed = 2; // Lower is faster.
//byte motorSequence[8] = {B0111,B0011,B1011,B1001,B1101,B1100,B1110,B0110}; 
//byte motorSequence[8] = {B1000,B0100,B0010,B0001,B1000,B0100,B0010,B0001};
 
void stepMotor(byte motorDirection,int stepSpeed) {
  int readStep = 0;
  int readBit = 0;
  int HIGHLOW = 0;
  for (readStep =0;readStep<8;readStep++) {
    for (readBit=0;readBit<4;readBit++) {
      HIGHLOW = bitRead(motorSequence[readStep],readBit);
      digitalWrite(motorPins[abs((motorDirection*3)-readBit)], HIGHLOW);
    }
    delay(stepSpeed);
  }
}

void stopMotor() {
  int readBit = 0;
  for (readBit=0;readBit<4;readBit++) {
    digitalWrite(motorPins[readBit], LOW);
  }
}


void setup() {
  pinMode(motorPins[0],OUTPUT);
  pinMode(motorPins[1],OUTPUT);
  pinMode(motorPins[2],OUTPUT);
  pinMode(motorPins[3],OUTPUT);
  pinMode(directionPin,INPUT);
}

int pressed = 1;

void loop() {
  while (digitalRead(directionPin) == 1) {
    pressed = 1;
    stepMotor(abs(motorDirection-1),motorSpeed);
  }
  if (pressed == 1) {
      stopMotor();
      motorDirection = abs(motorDirection-1);
      pressed = 0;
  } else {
    stepMotor(motorDirection,motorSpeed);
  }
}

Credits

509f148d252c095177dfab08c0364567
Ian Cumming

I like stuff, from building rockets to elctronics.

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login
Community Projects Magazine Maker Faire Shop Share
Respect project