Stepper motor help

Hello !

I'm working on a home automation project where my curtains open and close, i'm using a stepper motor to control this action, i used the included stepper motor library to get the motor moving but now i need some help with the code to make it move either clockwise or counter-clockwise depending on a input.

I don't see any code

What have you tried? Post your program code.

Post a link to the datasheet for your stepper motor.
And tell us what stepper motor driver you are using.

Stepper Motor Basics
Simple Stepper Code

Ooops Sorry really new to this forum, but here is the code.

Stepper Motor Control - one revolution

This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.

The motor should revolve one revolution in one direction, then
one revolution in the other direction.

Created 11 Mar. 2007
Modified 30 Nov. 2009
by Tom Igoe


#include <Stepper.h>

const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
// set the speed at 60 rpm:
// initialize the serial port:

void loop() {
// step one revolution in one direction:

// step one revolution in the other direction:

This is the motor: MOTS3: STEPPER MOTOR 24VDC/600mA (ANGLE 7.5° / 48 STEPS) – Velleman – Wholesaler and developer of electronics

This is the controlller:

The program you posted in Reply #3 makes the motor move in both directions. So all you now need is some code to change the value of a variable from (say) 'F' to 'R' so that you can control the direction.


Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

you need to code in an input.

limit switches at top or bottom, read if they are on or off with digital read.

you could count the steps or revolutions and work out how many you need to get to the top bottom

or both

start with learning how to use a "switch statement", and how to put pieces of code into "functions"