I'm very new at this and I’ve read the tutorials and got the hang of basic stuff, like editing pin inputs, outputs , but when it comes to creating a sketch that will do what i need, i’m lost.
I've read the basic tutorials and got to a point where i need a sketch that will perform a very basic function (so i believed), so here is a breakdown of where I’m at:
Equipment being used:
1 x Uno
1 x 28BYJ-48 Stepper
1 x ULN2003 stepper driver board
1 x Button (5v pin , 10Kh on gnd pin, output pin 2)
(i will add the other button once i've figured out how to make 1 work!)
Functions Required:
2 x button inputs to move the stepper from pos A-B wait until called and then back pos B-A
I like the AccelStepper.h library for the acceleration and deceleration commands such as
So I would ideally like the stepper to start off slow and then speeding up before gradually slowing down.
I’ve tried to combine different sketches (because I’m no good at writing them) to get what i need but I’ve been going round in circles.
i have attached a the two sketches i've been trying to combine
Can someone please point me in the right direction?
I'm not at all clear what you want help with. Is it the case that the first program works properly and you just want to convert if to use the AccelStepper library?
markcra:
I wish to combine both sketches to have slow movement via button control if that makes sense?
I'm not convinced that that is the correct solution.
I know that the first program does not use acceleration, but does it otherwise do what you want? If not please describe in detail what it actually does and what you want it to do that is different (apart from the acceleration).
When we know what needs to happen adding the acceleration should be straightforward.
Good evening, what i want is a Stepper motor to power a gate on my model railway, so i want to be able to open and close the gate (hence 2 buttons) the stepper motor has to turn aprox 8 times (32770 steps) to go from the open position to closed, i would like the motor to run variable speed, i.e. slow to start then faster then a gradual decrease in speed.
Yes that makes sense, but it does not answer my question about whether the first program does what you want apart from not having acceleration. What actually happens when you run the first program?
Or is it the case that the first program is completely irrelevant and I should ignore it?
After a lot of experimenting i've cracked the button activation accel stepper motor, it quite simple actually, just a lot of work getting the scripts to run correctly , here is the sketch:
#include <Stepper.h> #include <AccelStepper.h> #include <Pushbutton.h> //include Pushbutton library
// Motor pin definitions for Arduino #define motorPin1 8 // IN1 on the ULN2003 driver #define motorPin2 9 // IN2 on the ULN2003 driver #define motorPin3 10 // IN3 on the ULN2003 driver #define motorPin4 11 // IN4 on the ULN2003 driver
// Define the AccelStepper interface type; 4 wire motor in half step mode: #define MotorInterfaceType 8 #define HALFSTEP 8
// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper library with 28BYJ-48 stepper motor:
AccelStepper stepper(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
void setup()
{
// Set the maximum steps per second:
Serial.begin(9600); //initialise serial port
// Setup motor speed and acceleration
stepper.setMaxSpeed(1400);
stepper.setAcceleration(70.0);
}
void loop() {
if (pbutton1.getSingleDebouncedPress()){ //if button1 is pressed
Serial.println("Button1"); //serial monitor shows button3 pressed
Motoropen();
Serial.println("Open");
// Delay before power off
delay(500);
//Power off stepper board
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
}
if (pbutton2.getSingleDebouncedPress()){ //if button2 is pressed
Serial.println("Button2"); //serial monitor shows button2 pressed
Motorclose();
Serial.println("close");
// Delay before power off
delay(500);
//Power off stepper board
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
}
}
void Motoropen(){
stepper.runToNewPosition(0);
}
void Motorclose(){
//Adjust for endstop position
stepper.runToNewPosition(-32768);
}