Go Down

### Topic: Stepper motor help (Read 325 times)previous topic - next topic

#### johannesr95

##### May 19, 2017, 11:27 pm
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.

#### AWOL

#1
##### May 19, 2017, 11:33 pm
I don't see any code
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Robin2

#2
##### May 19, 2017, 11:34 pm
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.

...R
Stepper Motor Basics
Simple Stepper Code
Two or three hours spent thinking and reading documentation solves most programming problems.

#### johannesr95

#3
##### May 19, 2017, 11:34 pm
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:
myStepper.setSpeed(70);
// initialize the serial port:
Serial.begin(9600);
}

void loop() {
// step one revolution  in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);

// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}

#### johannesr95

#4
##### May 19, 2017, 11:42 pm
This is the motor: http://www.velleman.eu/products/view/?country=be&lang=en&id=411638

This is the controlller: http://www.velleman.eu/products/view/?country=be&lang=en&id=435576

#### Robin2

#5
##### May 20, 2017, 08:15 am
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.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### TomGeorge

#6
##### May 20, 2017, 11:06 am
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,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..
Everything runs on smoke, let the smoke out, it stops running....

#### joeblogs

#7
##### May 26, 2017, 02:50 am
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"

Go Up