camera slider a2 design project

i am currently doing my second year of design technology systems and control. my project this year is to make a camera slider for this i needed to change the speed and direction of a nema 17 stepper motor without using pre made shields. my current plan is to connect the motor to uln 2003 or 2803 which will go to a uno board on pins 8-11 plus a ground along with a potentiometer on analog 0 as input for speed and a simple push button for setting the direction on digital 7 this is my first time coding with arduino and i am having a few problems understanding the language and can't find existing code that does this so need some help with the code. thank you for reading any help and recommendations are appreciated. if wrong section please notify me where it should go.

this is my first time coding with arduino and i am having a few problems understanding the language

The IDE comes packed with worked examples. Work through a few.

a nema 17 stepper motor

Incoming!

danielhudson170: for this i needed to change the speed and direction of a nema 17 stepper motor without using pre made shields. my current plan is to connect the motor to uln 2003 or 2803

This is madness.

You need a proper stepper motor driver board such as a Pololu A4988 (though that may not suit your particular motor).

Stepper motor driver boards are not shields. They are the only "professional" way to control a stepper motor.

A useful part of your project report could be an explanation of why a ULN2003 etc is NOT a good choice for controlling a stepper motor.

...R

Because it is for course work I have to design and make any PCBs I use so I can't use the driver you suggest as it comes tomorrow I will be posting the code I have written and the circuit I have designed so far also that driver is for bi polar not uni polar

danielhudson170: Because it is for course work I have to design and make any PCBs I use so I can't use the driver you suggest as it comes tomorrow I will be posting the code I have written and the circuit I have designed so far also that driver is for bi polar not uni polar

There is nothing to stop you buying a bare Allegro A4988 chip and mounting it on your own PCB.

Either you are on a very advanced course or the course requirement verges on stupidity. Having to build a system that effectively requires you to use an h-bridge to control a stepper motor is un-teaching if there is such a thing. Using a h-bridge to control a stepper motor implies that you (and your teacher) have no idea how stepper motors should be controlled.

The Pololu A4988 is a very small PCB and I can't see what difference it would make if you "plug" that into your PCB rather than an L298 or a ULN2003 (or whatever).

At the very least you need to have a serious discussion with your Tutor before continuing.

...R

thanks alot this is the help i was looking for

#include <Stepper.h>
const int stepsPerRevolution = 200;
const int buttonPin1 = 4;
const int buttonPin2 = 7;
Stepper myStepper(stepsPerRevolution, 8,9,10,11);
int stepCount = 0;
int buttonState = 0;
void setup(){
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}
void loop() {
int sensorReading = analogRead(A0);
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);

buttonState = digitalRead(buttonPin1);
if (buttonState == HIGH) {
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
myStepper.step(stepsPerRevolution/100);
}
}

buttonState = digitalRead(buttonPin2);
if (buttonState == HIGH) {
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
myStepper.step(-stepsPerRevolution/100);
}
}
}
this is the code i have writen so far is uses parts from the examples included in the software but it only turns the motor whilst
a button is pressed how would i make turn in that direction for x amount of time ?

You need to study the technique for timing using millis() in the Blink Without Delay example sketch and in the demo several things at a time. The Thread about Planning and Implementing a Program may also give some useful pointers.

Basically you record the value of millis() when you press the button and start the motor and then, elsewhere keep checking how much time has passed and in due course stop the motor.

Organizing your code into short functions will make it much easier to implement.

...R