I want to use a button to control my stepper motor.
#include <Stepper.h>
int stepIN1Pin = 8;
int stepIN2Pin = 9;
int stepIN3Pin = 10;
int stepIN4Pin = 11;
int stepsPerRevolution = 768;
const int button1Pin = 3;
Stepper myStepper(stepsPerRevolution, stepIN1Pin, stepIN3Pin, stepIN2Pin, stepIN4Pin);
void setup() {
pinMode(button1Pin, INPUT);
myStepper.setSpeed(40);
}
void loop() {
int button1State,State;
State = LOW;
button1State = digitalRead(button1Pin);
if (((State == LOW) && !(button1State == LOW)))
myStepper.step(stepsPerRevolution/8);
}
I pushes the button and the motor doesn't move.
I used a 28BYJ-48 5V Stepper motor and a ULN2003 driver board.
(I connected GND to GND, VCC to 5V, IN1 to to port 8, IN2 to port 9, IN3 to port 10, IN4 to port 4, button to port 3)
You should get each part of your project working individually before combining them together. Right now there are just too many possible factors. You need to narrow down exactly where the problem is.
Does your stepper work correctly with File > Examples > Stepper > stepper_oneRevolution?
Does your button work correctly with File > Examples > 02.Digital > Button?
pert:
You should get each part of your project working individually before combining them together. Right now there are just too many possible factors. You need to narrow down exactly where the problem is.
Does your stepper work correctly with File > Examples > Stepper > stepper_oneRevolution?
Does your button work correctly with File > Examples > 02.Digital > Button?
I tried another code without the button the motor don't moce either.
Also, I'm a newbie, so, I don't know what is File>Example>Stepper>stepper_oneRevolution
and what is File>Examples>02.Digital>Button
DolphinPig28:
I tried another code without the button the motor don't moce either.
Also, I'm a newbie, so, I don't know what is File>Example>Stepper>stepper_oneRevolution
and what is File>Examples>02.Digital>Button
In the Arduino IDE there is a File menu at the top you can click on (maybe it's some other goofy thing on macOS?). In the File menu is an Examples submenu that contains example sketches included with the Arduino IDE and also ones for the libraries you have installed. These sketches provide demonstrations of how to do various things so they are a good way to test that your components are working correctly. You could write your own programs to do this but with the examples you can be fairly confident the code is written correctly. In the Arduino Web Editor, they are under the "Examples" tab on the left side of the screen.
In the Arduino IDE there is a File menu at the top you can click on (maybe it's some other goofy thing on macOS?). In the File menu is an Examples submenu that contains example sketches included with the Arduino IDE and also ones for the libraries you have installed. These sketches provide demonstrations of how to do various things so they are a good way to test that your components are working correctly. You could write your own programs to do this but with the examples you can be fairly confident the code is written correctly. In the Arduino Web Editor, they are under the "Examples" tab on the left side of the screen.
That code should definitely work. Now we need to know how you have the stepper connected to the Arduino and power. You could provide a hand drawn schematic and/or a clear picture.
pert:
That code should definitely work. Now we need to know how you have the stepper connected to the Arduino and power. You could provide a hand drawn schematic and/or a clear picture.
It's really hard to tell what's going on from that blurry picture with the markings on the ULN2003 module obscured by the wires, but I suspect the problem is that the line from the breadboard to the ULN2003 should be connected to the 5 V instead of ground.
It's really hard to tell what's going on from that blurry picture with the markings on the ULN2003 module obscured by the wires, but I suspect the problem is that the line from the breadboard to the ULN2003 should be connected to the 5 V instead of ground.
I reconnected the wire from the ULN2003 to the breadboard to ground. It rotate for a while, and it stops (through it's vibrating). Is my stepper and ULN2003 broken??? Help!!!
What are you using for power? Usually a stepper motor needs external power - the arduino can't provide enough current. Your diagram looks as though you're trying to power it directly from your Uno which will likely damage it.
wildbill:
What are you using for power? Usually a stepper motor needs external power - the arduino can't provide enough current. Your diagram looks as though you're trying to power it directly from your Uno which will likely damage it.
I don't understand why I need a external power. My stepper is 5V. Thank you!
Your stepper may well be 5V, but that doesn't mean that the Arduino can supply enough power to drive it. There are tutorials that suggest that it can, but it looks to me as though it's pulling 200mA which is the maximum that the Arduino can manage and running at the limits isn't going to do your hardware any favours if you want it to have a long life.
The usual cause for issues with servos and steppers is inadequate power. I strongly suspect that that's the problem here.
wildbill:
Your stepper may well be 5V, but that doesn't mean that the Arduino can supply enough power to drive it. There are tutorials that suggest that it can, but it looks to me as though it's pulling 200mA which is the maximum that the Arduino can manage and running at the limits isn't going to do your hardware any favours if you want it to have a long life.
The usual cause for issues with servos and steppers is inadequate power. I strongly suspect that that's the problem here.
So, I need a additional 5V battery? And how can you connect it to the stepper?
DolphinPig28:
(I connected GND to GND, VCC to 5V, IN1 to to port 8, IN2 to port 9, IN3 to port 10, IN4 to port 4, button to port 3)
You mean pin 8, pin 9, pin 10, etc? Pin 4 is not PWM BTW.
Ports are 8 bit memory mapped groups of pins on ATmega processors, and are denoted by letters like
D, B, C, and accessed via registers PINx, PORTx, DDRx where x is replaced by one of the port letters, search term "direct port manipulation"