A
Arduino•3mo ago
Sultan

Stepper Motor Randomly Changing Directions

I am using an ESP32, ULN2003, and a 28BYJ-48 Stepper Motor. I have it set up so if the left button is pressed then it will go reverse, if the right one pressed it will go forward (also if any of the two previous cases, the blue led turns on) and if neither are/aren't pressed it stays still. For some reason it just changes directions whenever it likes. This is my code:
#include <Stepper.h>

const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
pinMode(33,OUTPUT);
pinMode(32,OUTPUT);
pinMode(35,INPUT_PULLUP);
pinMode(34,INPUT_PULLUP);
pinMode(2, OUTPUT);
digitalWrite(33,HIGH);
digitalWrite(32,HIGH);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(35);
int rightState = digitalRead(34);

if(leftState == 0 && rightState == 0){
digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
digitalWrite(2,LOW);
stepper.step(0);
}

}
#include <Stepper.h>

const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
pinMode(33,OUTPUT);
pinMode(32,OUTPUT);
pinMode(35,INPUT_PULLUP);
pinMode(34,INPUT_PULLUP);
pinMode(2, OUTPUT);
digitalWrite(33,HIGH);
digitalWrite(32,HIGH);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(35);
int rightState = digitalRead(34);

if(leftState == 0 && rightState == 0){
digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
digitalWrite(2,LOW);
stepper.step(0);
}

}
Thank you very much for your help.
160 Replies
AnonEngineering
AnonEngineering•3mo ago
Pins 34 & 35 are input only, they don't support INPUT_PULLUP
Sultan
SultanOP•3mo ago
Hi Anon, I just rewrote it with the INPUT instead of INPUT_PULLUP, it kind of fixed it, what I mean by that around 70% of the time when you click the button it goes in the right direction and the other 30% it goes in the wrong direction.
#include <Stepper.h>

const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
pinMode(33,OUTPUT);
pinMode(32,OUTPUT);
pinMode(35,INPUT);
pinMode(34,INPUT);
pinMode(2, OUTPUT);
digitalWrite(33,HIGH);
digitalWrite(32,HIGH);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(35);
int rightState = digitalRead(34);

if(leftState == 0 && rightState == 0){
digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
digitalWrite(2,LOW);
stepper.step(0);
}

}
#include <Stepper.h>

const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
pinMode(33,OUTPUT);
pinMode(32,OUTPUT);
pinMode(35,INPUT);
pinMode(34,INPUT);
pinMode(2, OUTPUT);
digitalWrite(33,HIGH);
digitalWrite(32,HIGH);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(35);
int rightState = digitalRead(34);

if(leftState == 0 && rightState == 0){
digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
digitalWrite(2,LOW);
stepper.step(0);
}

}
AnonEngineering
AnonEngineering•3mo ago
if you use just INPUT you need to wire it with an external resistor the pin must be held HIGH or LOW, if you don't use a resistor the pin will float can you use other pins? 34 - 39 are the special "input only" pins
Sultan
SultanOP•3mo ago
Could I use Pin 25 and 26?
AnonEngineering
AnonEngineering•3mo ago
yes, they support INPUT_PULLUP when you use the pullup a resistor inside the chip is added for you
Sultan
SultanOP•3mo ago
Will the PULLUP make the input be default high? When I ran it with the PULLUP no signal was ever sent to the ULN2003 Board
AnonEngineering
AnonEngineering•3mo ago
yes, the pin idles HIGH until you push the button, then the pin goes LOW
Sultan
SultanOP•3mo ago
Using the PULLUP didn't work, the board didn't receive any signals (indicated by the RED LEDS), I tried PULLDOWN but it would only go in one direction on both buttons
AnonEngineering
AnonEngineering•3mo ago
did you set the pinMode back to INPUT_PULLUP?
Sultan
SultanOP•3mo ago
#include <Stepper.h>

const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
pinMode(33,OUTPUT);
pinMode(32,OUTPUT);
pinMode(26,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
pinMode(2, OUTPUT);
digitalWrite(33,HIGH);
digitalWrite(32,HIGH);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(26);
int rightState = digitalRead(25);

if(leftState == 0 && rightState == 0){
digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
digitalWrite(2,LOW);
stepper.step(0);
}

}
#include <Stepper.h>

const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
pinMode(33,OUTPUT);
pinMode(32,OUTPUT);
pinMode(26,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
pinMode(2, OUTPUT);
digitalWrite(33,HIGH);
digitalWrite(32,HIGH);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(26);
int rightState = digitalRead(25);

if(leftState == 0 && rightState == 0){
digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
digitalWrite(2,LOW);
stepper.step(0);
}

}
I did, did I mess up anything else when doing that?
AnonEngineering
AnonEngineering•3mo ago
looks OK, put print statements in your ifs to see if they are executing and add Serial.begin(9600); in setup you have the other side of the buttons to ground right?
Sultan
SultanOP•3mo ago
I don't actually, nothing is connected to ground for the buttons
AnonEngineering
AnonEngineering•3mo ago
pin > one side of button, other side of button > ground the pullup holds the pin HIGH (1), when you press the pin connects to ground (0)
Sultan
SultanOP•3mo ago
I don't have it setup like that currently, it is outputting high on 33 and 32 which are connected to my button respectively, and then connected 26 and 25 with INPUT_PULLUP to the other side of the button, so when I press it 'bridges' the connection. I will try to do it like you mentioned
AnonEngineering
AnonEngineering•3mo ago
no, just one pin per button
Sultan
SultanOP•3mo ago
It works now! Thank you!
AnonEngineering
AnonEngineering•3mo ago
pin 25 . one side of button, other side of button to ground
Sultan
SultanOP•3mo ago
Regarding this, does this mean pins 33 and 32 are reduandant?
AnonEngineering
AnonEngineering•3mo ago
yes, you only use one pin per button in this case 25 & 26 one for each
Sultan
SultanOP•3mo ago
That is so much more simpler than what I was doing, thank you! One more thing, Would there be any way to stop the motor from getting hot? I assume its because of the voltage still going through it
AnonEngineering
AnonEngineering•3mo ago
because of current flowing through it yes are you using a 5v power supply for it?
Sultan
SultanOP•3mo ago
Yes I am using a DC Power Supply
AnonEngineering
AnonEngineering•3mo ago
at 5v, iirc that is what 28BYJ-48 is rated for
Sultan
SultanOP•3mo ago
I have it set to 5 volt and it is currently drawing 0.235 amps
AnonEngineering
AnonEngineering•3mo ago
so a bit over 1 watt is being dissipated by the motor
Sultan
SultanOP•3mo ago
Would I be able to integrate a MOSFET in this system to control the voltage or ground that is connected to the ULN2003 board?
AnonEngineering
AnonEngineering•3mo ago
you could use a MOSFET as a power switch, another pin could drive the MOSFET to act as "motor on / off" does it get really hot? it shouldn't
Sultan
SultanOP•3mo ago
Not really hot, just warm I was planning on using this control my blinds
AnonEngineering
AnonEngineering•3mo ago
warm is normal
Sultan
SultanOP•3mo ago
Oh okay!
AnonEngineering
AnonEngineering•3mo ago
you can also use a drv8825 driver with a bigger stepper if you need to
Sultan
SultanOP•3mo ago
#include <Stepper.h>
#include <iostream>

const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
Serial.begin(9600);
pinMode(26,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
pinMode(2, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(26);
int rightState = digitalRead(25);

if(leftState == 0 && rightState == 0){
printf("Nothing is supposed to happen");
digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
printf("Turn Left");
digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
printf("Turn Right");
digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
printf("Absolutely nothing is supposed to happen");
digitalWrite(2,LOW);
stepper.step(0);
}

}
#include <Stepper.h>
#include <iostream>

const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
Serial.begin(9600);
pinMode(26,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
pinMode(2, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(26);
int rightState = digitalRead(25);

if(leftState == 0 && rightState == 0){
printf("Nothing is supposed to happen");
digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
printf("Turn Left");
digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
printf("Turn Right");
digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
printf("Absolutely nothing is supposed to happen");
digitalWrite(2,LOW);
stepper.step(0);
}

}
This driver looks similar to the hw-134a drivers that I have
AnonEngineering
AnonEngineering•3mo ago
arduino doesn't support printf, use Serial.print those drivers have a STEP and a DIR pin, A4988, DRV, HW, all work about the same, just the specs are slightly different
Sultan
SultanOP•3mo ago
Could I store this program on the ESP32? So I have it start this program anytime it boots up (not connected to computer)
AnonEngineering
AnonEngineering•3mo ago
once you upload it it stays on the esp until you load new code, even if power is removed
Sultan
SultanOP•3mo ago
Oh, its that simple? Thank you!
AnonEngineering
AnonEngineering•3mo ago
thank Arduino / Espressiff šŸ™‚
Sultan
SultanOP•3mo ago
Thank you Arduino and Espressiff šŸ™‚
AnonEngineering
AnonEngineering•3mo ago
lol
Sultan
SultanOP•3mo ago
#include <Stepper.h>


const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
Serial.begin(9600);
pinMode(26,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
pinMode(2, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(26);
int rightState = digitalRead(25);

if(leftState == 0 && rightState == 0){
Serial.println("Nothing is supposed to happen");
digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
Serial.println("Turn Left");
digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
Serial.println("Turn Right");
digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
Serial.println("Absolutely nothing is supposed to happen");
digitalWrite(2,LOW);
stepper.step(0);
}

}
#include <Stepper.h>


const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
Serial.begin(9600);
pinMode(26,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
pinMode(2, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(26);
int rightState = digitalRead(25);

if(leftState == 0 && rightState == 0){
Serial.println("Nothing is supposed to happen");
digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
Serial.println("Turn Left");
digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
Serial.println("Turn Right");
digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
Serial.println("Absolutely nothing is supposed to happen");
digitalWrite(2,LOW);
stepper.step(0);
}

}
This is the code know, for some reason deleting the two lines that made pin 33 and 32 outputs broke it, so it is doing that 70% 30% thing again Or it will go in the right direction in the begining then shake and go the wrong direction
AnonEngineering
AnonEngineering•3mo ago
shouldn't make any difference if it's all wired right these lines weren't doing anything
c++
digitalWrite(33,HIGH);
digitalWrite(32,HIGH);
c++
digitalWrite(33,HIGH);
digitalWrite(32,HIGH);
brb
Sultan
SultanOP•3mo ago
putting in a new stepper motor didn't fix the issue still got that 70% 30% I deleted the Serial.Println for 1&1 and 0&0 and now it doesn't even spin the motor
#include <Stepper.h>


const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
Serial.begin(9600);
pinMode(26,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
pinMode(2, OUTPUT);
stepper.setSpeed(20);

}

void loop() {

int leftState = digitalRead(26);
int rightState = digitalRead(25);

if(leftState == 0 && rightState == 0){
digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
Serial.println("Turn Left");
digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
Serial.println("Turn Right");
digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
digitalWrite(2,LOW);
stepper.step(0);
}

}
#include <Stepper.h>


const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
Serial.begin(9600);
pinMode(26,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
pinMode(2, OUTPUT);
stepper.setSpeed(20);

}

void loop() {

int leftState = digitalRead(26);
int rightState = digitalRead(25);

if(leftState == 0 && rightState == 0){
digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
Serial.println("Turn Left");
digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
Serial.println("Turn Right");
digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
digitalWrite(2,LOW);
stepper.step(0);
}

}
I can feel the motor trying to rotate but it doesn't
AnonEngineering
AnonEngineering•3mo ago
oh, you had 32 & 33 as OUTPUTs in your original, where are they going?
Sultan
SultanOP•3mo ago
instead of having the pins go to ground I used 32 and 33 as High signals and when a high signal was detected on 35 or 34 it would act accordingly
AnonEngineering
AnonEngineering•3mo ago
oh, then it should make no difference
Sultan
SultanOP•3mo ago
That is also what I think but know it won't even rotate.. , all I did was delete the Serial.print for the 0 & 0 and 1 & 1 cases
AnonEngineering
AnonEngineering•3mo ago
serial has no bearing either i'll simulate, give me a few minutes
Sultan
SultanOP•3mo ago
I think when I used control f it messed up the speed, I made it 10 now it works
#include <Stepper.h>


const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
Serial.begin(9600);
pinMode(26,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
pinMode(2, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(26);
int rightState = digitalRead(25);

if(leftState == 0 && rightState == 0){
digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
Serial.println("Turn Left");
digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
Serial.println("Turn Right");
digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
digitalWrite(2,LOW);
stepper.step(0);
}

}
#include <Stepper.h>


const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
Serial.begin(9600);
pinMode(26,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
pinMode(2, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(26);
int rightState = digitalRead(25);

if(leftState == 0 && rightState == 0){
digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
Serial.println("Turn Left");
digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
Serial.println("Turn Right");
digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
digitalWrite(2,LOW);
stepper.step(0);
}

}
AnonEngineering
AnonEngineering•3mo ago
looks like it should work... https://wokwi.com/projects/435146748848937985 wokwi doesn't have your exact hardware, but the logic is sound...
Sultan
SultanOP•3mo ago
What would you recommend doing?
AnonEngineering
AnonEngineering•3mo ago
i thought you said it's working for you
Sultan
SultanOP•3mo ago
It is doing the 70% working and the 30% not working the 30% is specifcally going in the wrong direction
AnonEngineering
AnonEngineering•3mo ago
different than the sim i linked?
Sultan
SultanOP•3mo ago
yes
AnonEngineering
AnonEngineering•3mo ago
then i'd suspect wiring, that's your code (and BTW, wokwi doesn't simulate current, you can't wire like i did in real life) but it simulates the logic perfectly what's pin 2 - the onboard LED?
Sultan
SultanOP•3mo ago
Pin 2 is the onboard blue led
AnonEngineering
AnonEngineering•3mo ago
ok, not simulated
Sultan
SultanOP•3mo ago
I was using it as a trouble shooting step, I can get rid of it
AnonEngineering
AnonEngineering•3mo ago
shouldn't be causing trouble...
Sultan
SultanOP•3mo ago
I agree, but maybe for some incomprehensible reason still doing it with this barebones code:
#include <Stepper.h>


const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
Serial.begin(9600);
pinMode(26,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
//pinMode(2, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(26);
int rightState = digitalRead(25);

if(leftState == 0 && rightState == 0){
//digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
//Serial.println("Turn Left");
//digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
//Serial.println("Turn Right");
//digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
//digitalWrite(2,LOW);
stepper.step(0);
}

}#include <Stepper.h>


const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
Serial.begin(9600);
pinMode(26,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
//pinMode(2, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(26);
int rightState = digitalRead(25);

if(leftState == 0 && rightState == 0){
//digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
//Serial.println("Turn Left");
//digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
//Serial.println("Turn Right");
//digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
//digitalWrite(2,LOW);
stepper.step(0);
}

}
#include <Stepper.h>


const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
Serial.begin(9600);
pinMode(26,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
//pinMode(2, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(26);
int rightState = digitalRead(25);

if(leftState == 0 && rightState == 0){
//digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
//Serial.println("Turn Left");
//digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
//Serial.println("Turn Right");
//digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
//digitalWrite(2,LOW);
stepper.step(0);
}

}#include <Stepper.h>


const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 13 ,12 ,14 ,27);

void setup() {
Serial.begin(9600);
pinMode(26,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
//pinMode(2, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(26);
int rightState = digitalRead(25);

if(leftState == 0 && rightState == 0){
//digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
//Serial.println("Turn Left");
//digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
//Serial.println("Turn Right");
//digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
//digitalWrite(2,LOW);
stepper.step(0);
}

}
What's funny is I have been trying to do this project for about a year, and the same thing kept happening I didn't know where to go to find some help until I came across this discord like 3 hours ago Maybe its cursed?
AnonEngineering
AnonEngineering•3mo ago
not sure what the problem is, doubt it's a curse, 95% of the time it's wiring or lack of sufficient current from your power supply šŸ˜‰
Sultan
SultanOP•3mo ago
I am using this to supply the motor:
Sultan
SultanOP•3mo ago
Jesverty DC Power Supply Variable, 0-30V 0-10A Adjustable Switching...
Jesverty's SPS series is a high-efficiency, compact, lightweight, high-performance Switching mode DC regulated power supply. It can be used as a constant-voltage(C.V.) power supply and constant-current(C.C.) power supply. Also, convenient functions like a USB type-A charging port, and a high-prec...
AnonEngineering
AnonEngineering•3mo ago
that should be more than enough šŸ™‚ is the power supply ground connected to the esp ground?
Sultan
SultanOP•3mo ago
Yes I have common ground point Should I take a photo of the wiring I have going?
AnonEngineering
AnonEngineering•3mo ago
see the faint grey lines inside the button here?
No description
AnonEngineering
AnonEngineering•3mo ago
that represents how the button is wired, a press connects left to right
Sultan
SultanOP•3mo ago
yes I think I have that wired up correctly because it doesn't start the motor until I press the button
AnonEngineering
AnonEngineering•3mo ago
maybe the ULN2003 isn't happy with 3.3v logic, usually see them on Unos (which use 5v logic)
Sultan
SultanOP•3mo ago
I can plug in an arduino uno one sec
AnonEngineering
AnonEngineering•3mo ago
yeah, just need to change the pin numbers
Sultan
SultanOP•3mo ago
Also, I just want to say thank you for sticking around, I just want to learn this stuff better and it mean's a lot.
AnonEngineering
AnonEngineering•3mo ago
you're welcome
Sultan
SultanOP•3mo ago
No description
No description
Sultan
SultanOP•3mo ago
#include <Stepper.h>


const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 4 ,5 ,6 ,7);

void setup() {
Serial.begin(9600);
pinMode(2,INPUT_PULLUP);
pinMode(3,INPUT_PULLUP);
//pinMode(2, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(2);
int rightState = digitalRead(3);

if(leftState == 0 && rightState == 0){
//digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
//Serial.println("Turn Left");
//digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
//Serial.println("Turn Right");
//digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
//digitalWrite(2,LOW);
stepper.step(0);
}

}
#include <Stepper.h>


const int STEPS = 2048;


Stepper stepper = Stepper(STEPS, 4 ,5 ,6 ,7);

void setup() {
Serial.begin(9600);
pinMode(2,INPUT_PULLUP);
pinMode(3,INPUT_PULLUP);
//pinMode(2, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(2);
int rightState = digitalRead(3);

if(leftState == 0 && rightState == 0){
//digitalWrite(2,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
//Serial.println("Turn Left");
//digitalWrite(2,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
//Serial.println("Turn Right");
//digitalWrite(2,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
//digitalWrite(2,LOW);
stepper.step(0);
}

}
Sultan
SultanOP•3mo ago
No description
Sultan
SultanOP•3mo ago
It has the same issue, it does the 70% working 30% not
AnonEngineering
AnonEngineering•3mo ago
that's good news, bad news good news is the levels don't seem to be the issue bad news is it still doesn't work... here's mine btw https://wokwi.com/projects/435148961261584385 just as a style thing, name the pins up top so if you need to change them you only have one line to change i don't see anything obvious wrong with the wiring...
Sultan
SultanOP•3mo ago
#include <Stepper.h>


const int STEPS = 2048;

const int Left_Butt = 3;
const int Right_Butt = 2;
const int Led_Pin = 13;


Stepper stepper = Stepper(STEPS, 4 ,5 ,6 ,7);

void setup() {
Serial.begin(9600);
pinMode(Left_Butt,INPUT_PULLUP);
pinMode(Right_Butt,INPUT_PULLUP);
pinMode(Led_Pin, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(Left_Butt);
int rightState = digitalRead(Right_Butt);

if(leftState == 0 && rightState == 0){
digitalWrite(Led_Pin,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
Serial.println("Turn Left");
digitalWrite(Led_Pin,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
Serial.println("Turn Right");
digitalWrite(Led_Pin,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
digitalWrite(Led_Pin,LOW);
stepper.step(0);
}

}
#include <Stepper.h>


const int STEPS = 2048;

const int Left_Butt = 3;
const int Right_Butt = 2;
const int Led_Pin = 13;


Stepper stepper = Stepper(STEPS, 4 ,5 ,6 ,7);

void setup() {
Serial.begin(9600);
pinMode(Left_Butt,INPUT_PULLUP);
pinMode(Right_Butt,INPUT_PULLUP);
pinMode(Led_Pin, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(Left_Butt);
int rightState = digitalRead(Right_Butt);

if(leftState == 0 && rightState == 0){
digitalWrite(Led_Pin,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
Serial.println("Turn Left");
digitalWrite(Led_Pin,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
Serial.println("Turn Right");
digitalWrite(Led_Pin,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
digitalWrite(Led_Pin,LOW);
stepper.step(0);
}

}
😁, did it right the first time (LETS GO)
AnonEngineering
AnonEngineering•3mo ago
yes, now if you want an LED on pin 9, only one place to change
Sultan
SultanOP•3mo ago
I should have done it this way the first time
AnonEngineering
AnonEngineering•3mo ago
live an learn šŸ™‚ plus, it's pretty obvious what Led_Pin is, 6 months from now yer like "What is pin 9???" or worse, what does 9 mean here?
Sultan
SultanOP•3mo ago
not even 6 months, tmmr lol
AnonEngineering
AnonEngineering•3mo ago
not related, but here is a different way to deal with buttons https://wokwi.com/projects/430668928277663745 it only looks for change, not is it pressed or not
Sultan
SultanOP•3mo ago
I am going to save this for a controller I want to build, thank you!
AnonEngineering
AnonEngineering•3mo ago
but in your code, it isn't printing the button pressed correctly? in your code it should print continuously while pressed does it work differently if the stepper is unplugged? (not ULN, just stepper)
Sultan
SultanOP•3mo ago
#include <Stepper.h>


const int STEPS = 2048;

const int Left_Butt = 3;
const int Right_Butt = 2;
const int Led_Pin = 13;


Stepper stepper = Stepper(STEPS, 4 ,5 ,6 ,7);

void setup() {
Serial.begin(9600);
pinMode(Left_Butt,INPUT_PULLUP);
pinMode(Right_Butt,INPUT_PULLUP);
pinMode(Led_Pin, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(Left_Butt);
int rightState = digitalRead(Right_Butt);

if(leftState == 0 && rightState == 0){
Serial.println("Neither Pressed");
digitalWrite(Led_Pin,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
Serial.println("Turn Left");
digitalWrite(Led_Pin,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
Serial.println("Turn Right");
digitalWrite(Led_Pin,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
Serial.println("Both Pressed");
digitalWrite(Led_Pin,LOW);
stepper.step(0);
}

}
#include <Stepper.h>


const int STEPS = 2048;

const int Left_Butt = 3;
const int Right_Butt = 2;
const int Led_Pin = 13;


Stepper stepper = Stepper(STEPS, 4 ,5 ,6 ,7);

void setup() {
Serial.begin(9600);
pinMode(Left_Butt,INPUT_PULLUP);
pinMode(Right_Butt,INPUT_PULLUP);
pinMode(Led_Pin, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(Left_Butt);
int rightState = digitalRead(Right_Butt);

if(leftState == 0 && rightState == 0){
Serial.println("Neither Pressed");
digitalWrite(Led_Pin,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
Serial.println("Turn Left");
digitalWrite(Led_Pin,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
Serial.println("Turn Right");
digitalWrite(Led_Pin,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
Serial.println("Both Pressed");
digitalWrite(Led_Pin,LOW);
stepper.step(0);
}

}
the lines are correctly printing
AnonEngineering
AnonEngineering•3mo ago
is this order correct?
c++
Stepper(STEPS, 4 ,5 ,6 ,7)
c++
Stepper(STEPS, 4 ,5 ,6 ,7)
Sultan
SultanOP•3mo ago
IN1 is connected to 4 IN2 is connected to 5 IN3 is connected to 6 IN4 is connected to 7 yes
AnonEngineering
AnonEngineering•3mo ago
so all is well, except the stepper moves erratically?
Sultan
SultanOP•3mo ago
and sometimes incorrectly
AnonEngineering
AnonEngineering•3mo ago
the LEDs on the drivers are also erratic?
Sultan
SultanOP•3mo ago
no but I did notice that the 'C' light doesn't ever turn on It hasn't turned at all this ULN2003 is brand new
AnonEngineering
AnonEngineering•3mo ago
try replacing that wire duponts fail more often than you'd imagine and if all 4 don't light the stepper won't move correctly
Sultan
SultanOP•3mo ago
I turned everything off, I started smelling burning
AnonEngineering
AnonEngineering•3mo ago
never a good sign
Sultan
SultanOP•3mo ago
I have absolutely no idea what is burning
AnonEngineering
AnonEngineering•3mo ago
motor hot or the ULN chip?
Sultan
SultanOP•3mo ago
nothing is hot the motor is almost cool just a little warm but its cooler than usual
AnonEngineering
AnonEngineering•3mo ago
smth should be warm if you smell burning motor power is direct from supply, not Uno right?
Sultan
SultanOP•3mo ago
correct
AnonEngineering
AnonEngineering•3mo ago
did current spike?
Sultan
SultanOP•3mo ago
no normal current I went and got a fire extingusher just in case I turned everything back on I don't smell burning I have no idea
Sultan
SultanOP•3mo ago
The LED is still not on, for the ULN2003
AnonEngineering
AnonEngineering•3mo ago
yeah, that is definately a problem
Sultan
SultanOP•3mo ago
Let me get another one, one sec
AnonEngineering
AnonEngineering•3mo ago
proper operation depends on those four signals driving the coils
Sultan
SultanOP•3mo ago
Okay I went and got a new one, immediately the 'C' light turns on
AnonEngineering
AnonEngineering•3mo ago
does it work any better? the stepper i mean
Sultan
SultanOP•3mo ago
It only goes clockwise
AnonEngineering
AnonEngineering•3mo ago
try the example above you can use your pins, just change the code
Sultan
SultanOP•3mo ago
/*
#include <Stepper.h>


const int STEPS = 2048;

const int Left_Butt = 3;
const int Right_Butt = 2;
const int Led_Pin = 13;


Stepper stepper = Stepper(STEPS, 4 ,5 ,6 ,7);

void setup() {
Serial.begin(9600);
pinMode(Left_Butt,INPUT_PULLUP);
pinMode(Right_Butt,INPUT_PULLUP);
pinMode(Led_Pin, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(Left_Butt);
int rightState = digitalRead(Right_Butt);

if(leftState == 0 && rightState == 0){
Serial.println("Neither Pressed");
digitalWrite(Led_Pin,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
Serial.println("Turn Left");
digitalWrite(Led_Pin,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
Serial.println("Turn Right");
digitalWrite(Led_Pin,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
Serial.println("Both Pressed");
digitalWrite(Led_Pin,LOW);
stepper.step(0);
}

}

*/

//Includes the Arduino Stepper Library
#include <Stepper.h>

// Defines the number of steps per rotation
const int stepsPerRevolution = 2048;

// Creates an instance of stepper class
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper myStepper = Stepper(stepsPerRevolution, 4, 5, 6, 7);

void setup() {
// Nothing to do (Stepper Library sets pins as outputs)
}

void loop() {
// Rotate CW slowly at 5 RPM
myStepper.setSpeed(5);
myStepper.step(stepsPerRevolution);
delay(1000);

// Rotate CCW quickly at 10 RPM
myStepper.setSpeed(10);
myStepper.step(-stepsPerRevolution);
delay(1000);
}
/*
#include <Stepper.h>


const int STEPS = 2048;

const int Left_Butt = 3;
const int Right_Butt = 2;
const int Led_Pin = 13;


Stepper stepper = Stepper(STEPS, 4 ,5 ,6 ,7);

void setup() {
Serial.begin(9600);
pinMode(Left_Butt,INPUT_PULLUP);
pinMode(Right_Butt,INPUT_PULLUP);
pinMode(Led_Pin, OUTPUT);
stepper.setSpeed(10);

}

void loop() {

int leftState = digitalRead(Left_Butt);
int rightState = digitalRead(Right_Butt);

if(leftState == 0 && rightState == 0){
Serial.println("Neither Pressed");
digitalWrite(Led_Pin,LOW);
stepper.step(0);
}

else if(leftState == 1 && rightState == 0){
Serial.println("Turn Left");
digitalWrite(Led_Pin,HIGH);
stepper.step(-512);
}

else if(leftState == 0 && rightState == 1){
Serial.println("Turn Right");
digitalWrite(Led_Pin,HIGH);
stepper.step(512);
}

else if(leftState == 1 && rightState == 1){
Serial.println("Both Pressed");
digitalWrite(Led_Pin,LOW);
stepper.step(0);
}

}

*/

//Includes the Arduino Stepper Library
#include <Stepper.h>

// Defines the number of steps per rotation
const int stepsPerRevolution = 2048;

// Creates an instance of stepper class
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper myStepper = Stepper(stepsPerRevolution, 4, 5, 6, 7);

void setup() {
// Nothing to do (Stepper Library sets pins as outputs)
}

void loop() {
// Rotate CW slowly at 5 RPM
myStepper.setSpeed(5);
myStepper.step(stepsPerRevolution);
delay(1000);

// Rotate CCW quickly at 10 RPM
myStepper.setSpeed(10);
myStepper.step(-stepsPerRevolution);
delay(1000);
}
AnonEngineering
AnonEngineering•3mo ago
btw, this is formatted as a codeblock
c++
//Includes the Arduino Stepper Library
#include <Stepper.h>

// Defines the number of steps per rotation
const int stepsPerRevolution = 2048;

// Creates an instance of stepper class
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);

void setup() {
// Nothing to do (Stepper Library sets pins as outputs)
}

void loop() {
// Rotate CW slowly at 5 RPM
myStepper.setSpeed(5);
myStepper.step(stepsPerRevolution);
delay(1000);

// Rotate CCW quickly at 10 RPM
myStepper.setSpeed(10);
myStepper.step(-stepsPerRevolution);
delay(1000);
}
c++
//Includes the Arduino Stepper Library
#include <Stepper.h>

// Defines the number of steps per rotation
const int stepsPerRevolution = 2048;

// Creates an instance of stepper class
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);

void setup() {
// Nothing to do (Stepper Library sets pins as outputs)
}

void loop() {
// Rotate CW slowly at 5 RPM
myStepper.setSpeed(5);
myStepper.step(stepsPerRevolution);
delay(1000);

// Rotate CCW quickly at 10 RPM
myStepper.setSpeed(10);
myStepper.step(-stepsPerRevolution);
delay(1000);
}
Sultan
SultanOP•3mo ago
yeah their code also doesn't work for me it keeps going clockwise
AnonEngineering
AnonEngineering•3mo ago
just the code above?
Sultan
SultanOP•3mo ago
Yes
AnonEngineering
AnonEngineering•3mo ago
that is the standard "known good" code, points to an issue with the ULNs or steppers
Sultan
SultanOP•3mo ago
I just in a new ULN2003 and Stepper, samething damn, so I have defective hardware 😭
AnonEngineering
AnonEngineering•3mo ago
hardware or wiring, the codes we've been playing with all checkout
Sultan
SultanOP•3mo ago
touching the stepper motor, as the motor is starting it trys to turn anti clockwise but it changes direction to clockwise
AnonEngineering
AnonEngineering•3mo ago
Sultan_Servo_Uno - Wokwi ESP32, STM32, Arduino Simulator
Run IoT and embedded projects in your browser: ESP32, STM32, Arduino, Pi Pico, and more. No installation required!
AnonEngineering
AnonEngineering•3mo ago
that's the example, just the pins changed
Sultan
SultanOP•3mo ago
they have this code on the amazon page:
#define IN1 8
#define IN2 9
#define IN3 10
#define IN4 11
int Steps = 0;
boolean Direction = true;
void setup() {
Serial.begin(9600);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop() {
for(int i=0; i<4096; i++){
stepper(1);
delayMicroseconds(800);
}
Direction = !Direction;
}

void stepper(int xw) {
for (int x = 0; x < xw; x++) {
switch (Steps) {
case 0:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
break;
case 1:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, HIGH);
break;
case 2:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
break;
case 3:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
break;
case 4:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 5:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 6:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 7:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
break;
default:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
}
SetDirection();
}
}
void SetDirection() {
if (Direction == 1) {
Steps++;
}
if (Direction == 0) {
Steps--;
}
if (Steps > 7) {
Steps = 0;
}
if (Steps < 0) {
Steps = 7;
}
}
#define IN1 8
#define IN2 9
#define IN3 10
#define IN4 11
int Steps = 0;
boolean Direction = true;
void setup() {
Serial.begin(9600);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop() {
for(int i=0; i<4096; i++){
stepper(1);
delayMicroseconds(800);
}
Direction = !Direction;
}

void stepper(int xw) {
for (int x = 0; x < xw; x++) {
switch (Steps) {
case 0:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
break;
case 1:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, HIGH);
break;
case 2:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
break;
case 3:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
break;
case 4:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 5:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 6:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 7:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
break;
default:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
}
SetDirection();
}
}
void SetDirection() {
if (Direction == 1) {
Steps++;
}
if (Direction == 0) {
Steps--;
}
if (Steps > 7) {
Steps = 0;
}
if (Steps < 0) {
Steps = 7;
}
}
Sultan
SultanOP•3mo ago
wait, why does that code work???
AnonEngineering
AnonEngineering•3mo ago
Amazon code - i have a bridge in Brooklyn to sell ya šŸ™‚
Sultan
SultanOP•3mo ago
it turns anti clockwise and clockwise now? lol But that code actually works for some insane reason
AnonEngineering
AnonEngineering•3mo ago
but that works?!?!
Sultan
SultanOP•3mo ago
It does!?!?!
Sultan
SultanOP•3mo ago
It is also really efficent the motor is cool to the touch I don't understand it
AnonEngineering
AnonEngineering•3mo ago
beats me, that code doesn't work in the sim šŸ™‚
Sultan
SultanOP•3mo ago
why does it WORKKKKKK??!?!?!?
AnonEngineering
AnonEngineering•3mo ago
just back to earlier, they used define to name the pins
c++
#define IN1 8
#define IN2 9
#define IN3 10
#define IN4 11
c++
#define IN1 8
#define IN2 9
#define IN3 10
#define IN4 11
Sultan
SultanOP•3mo ago
is #define or const int better?
AnonEngineering
AnonEngineering•3mo ago
that starts an argument every time šŸ™‚ I prefer the constant but...
Sultan
SultanOP•3mo ago
okay then I will stick with the const int
AnonEngineering
AnonEngineering•3mo ago
so it would seem that driver wants a different pin order
Sultan
SultanOP•3mo ago
🫠
AnonEngineering
AnonEngineering•3mo ago
so try that order with your code
Sultan
SultanOP•3mo ago
Sorry, I am not understanding it Would you mind explaning what you mean?
AnonEngineering
AnonEngineering•3mo ago
brrb your code had
c++
Stepper stepper = Stepper(STEPS, 13, 12, 14, 27);
c++
Stepper stepper = Stepper(STEPS, 13, 12, 14, 27);
that is the order of IN1 - IN4, it looks like they want the reverse
Sultan
SultanOP•3mo ago
//Includes the Arduino Stepper Library
#include <Stepper.h>

// Defines the number of steps per rotation
const int stepsPerRevolution = 2048;

// Creates an instance of stepper class
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper myStepper = Stepper(stepsPerRevolution, 11, 10, 9, 8);

void setup() {
// Nothing to do (Stepper Library sets pins as outputs)
}

void loop() {
// Rotate CW slowly at 5 RPM
myStepper.setSpeed(5);
myStepper.step(stepsPerRevolution);
delay(1000);

// Rotate CCW quickly at 10 RPM
myStepper.setSpeed(10);
myStepper.step(-stepsPerRevolution);
delay(1000);
}
//Includes the Arduino Stepper Library
#include <Stepper.h>

// Defines the number of steps per rotation
const int stepsPerRevolution = 2048;

// Creates an instance of stepper class
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper myStepper = Stepper(stepsPerRevolution, 11, 10, 9, 8);

void setup() {
// Nothing to do (Stepper Library sets pins as outputs)
}

void loop() {
// Rotate CW slowly at 5 RPM
myStepper.setSpeed(5);
myStepper.step(stepsPerRevolution);
delay(1000);

// Rotate CCW quickly at 10 RPM
myStepper.setSpeed(10);
myStepper.step(-stepsPerRevolution);
delay(1000);
}
AnonEngineering
AnonEngineering•3mo ago
what does that do?
Sultan
SultanOP•3mo ago
I think it works correctly
AnonEngineering
AnonEngineering•3mo ago
i've never seen a driver that wants reverse - but the "right" order is imperative (also never seen code on Amazon that works šŸ™‚ )
Sultan
SultanOP•3mo ago
It works know! Thank you so very much, I never would have figured this out by myself, you truly are a great person, staying with me for 4 hours, thank you very much!
AnonEngineering
AnonEngineering•3mo ago
at least we got somewhere šŸ˜‰ glad it works, now that you know the right setup for your hardware you can experiment with code
Sultan
SultanOP•3mo ago
Yes, I want to hook it up to the internet and then have alexa control it, without using esphome on home assistant
AnonEngineering
AnonEngineering•3mo ago
so next step is get it working back on your esp
Sultan
SultanOP•3mo ago
Definitely, but that is probably a tmmr problem, I have been trying to figure this out sense 10AM, its almost 8:30PM over here
AnonEngineering
AnonEngineering•3mo ago
not gonna tell the wife about this project - she'll want me to build it for her šŸ™‚
Sultan
SultanOP•3mo ago
lmao, my dad would make me do this for the whole house
AnonEngineering
AnonEngineering•3mo ago
yeah 11:30 here in the east, and work tomorrow
Sultan
SultanOP•3mo ago
Wow man, up until 11:30 for a random stranger, I don't know what to say, thank you so much
AnonEngineering
AnonEngineering•3mo ago
oh it's better than binge watching TV, no worries
Sultan
SultanOP•3mo ago
I was thinking of going to binge right now, after getting some food of course. Alright man, thank you very much again, and I hope you have a great rest of your night!
AnonEngineering
AnonEngineering•3mo ago
you too!

Did you find this page helpful?