Two Steppers controled for two buttons each

Hello, For a few days i've been tryin to write a program which will be controlled my two steppers. My idea are very simple i need for each stepper two buttons, for left move and right move. When i press and hold it stepper goes to given direction.

My problem is when i hold one button, the other stepper have some noises or something like this (i am not sure cuz i am total newbie)

My skecht looks like this: |397x500

my device: |500x333

and this is simple example what for i need this: |500x319

I realize that knowledge as well as the time spent for each is a mega valuable, but for their help in editing the code, or improve it'll always be thankful!

Hi,

Can you please post a copy of your sketch, using code tags?

Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

The fritzy diagram is not a circuit diagram.

It looks like you are using the 5v from the arduino to power the stepper motor. That is a no no, the arduino cannot provide enough current for one stepper let alone two. You need a separate supply to power them.

Tom..... :) (15 minutes in foetal position, sighhh)

sory for not full information:

#include   <Stepper.h>
 
int button_1 = 2;
int button_2 = 3;
int button_3 = 12;
int button_4 = 13;
 
Stepper myStepper(2048,8,10,9,11);
Stepper myStepper2(2048,4,6,5,7);
 
int bval1 = 0;
int bval2 = 0;
int bval3 = 0;
int bval4 = 0;
 
  void setup() {
  pinMode(button_1, INPUT);
  pinMode(button_2, INPUT);
  myStepper.setSpeed(4);
  pinMode(button_3, INPUT);
  pinMode(button_4, INPUT);
  myStepper2.setSpeed(4);
}
 
void loop() {
 
  bval1 = digitalRead(button_1);
  if (bval1 == HIGH)
  {
 myStepper.step(8);
  delay(0);    
    }
  {
 myStepper.step(0);
  delay(0);    
    }
   bval2 = digitalRead(button_2);
   if (bval2 == HIGH)
 
  {
     if (bval2 == HIGH)
  myStepper.step(-8);
  delay(0);
  }
 
 
    bval3 = digitalRead(button_3);
  if (bval3 == HIGH)
  {
 myStepper2.step(8);
  delay(0);    
    }
  {
 myStepper2.step(0);
  delay(0);    
    }
   bval4 = digitalRead(button_4);
   if (bval4 == HIGH)
 
  {
     if (bval4 == HIGH)
  myStepper2.step(-8);
  delay(0);
  }
}

i use external 12V, that was mistake.

At this moment i don’t have photo of my circuit cause i am at work, but is excatly the same as on fritzing (only all buttons i have connected signal and GND is one leg and secound leg is VCC)

i only have photo from backstage ^.^

You need to read through your code very carefully and remove the junk - such as duplicate lines with if (bval4 == HIGH) and useless stuff such as {} not connected to any IF or function , delay(0) and myStepper.step(0)

Also, indent it properly so that the logic is visually obvious.

When you have tidied it up (and if it still does not work) post the revised version.

You have not provided links to the datasheets for the motors or the stepper drivers so I am assuming you have already got other code that makes you motor run properly and all you are asking about here is the control system? If not let us know.

You may find some useful stuff in stepper motor basics

...R

thanks for your reply, yes i use stepper.h library if u ask for that ( i am total newbie and noob in coding, so junk in code is normal, cause i try do write my code, using samples founded on the internet )

for me coding is tottaly magic,that's why it is written chaotically.

in future i wish to hold button and stepper will incrase speed (but this is only dreaming on ;) )

but i will try do my best

Hi,
Make sure you have the gnd of the stepper 12V supply connected to the arduino gnd.

Tom… :slight_smile:

yes, it’s connected :stuck_out_tongue:

#include   <Stepper.h>
 
int button_1 = 2;
int button_2 = 3;
int button_3 = 12;
int button_4 = 13;
 
Stepper myStepper(2048,8,10,9,11);
Stepper myStepper2(2048,4,6,5,7);
 
int bval1 = 0;
int bval2 = 0;
int bval3 = 0;
int bval4 = 0;
 
  void setup() {
  pinMode(button_1, INPUT);
  pinMode(button_2, INPUT);
  myStepper.setSpeed(4);
  pinMode(button_3, INPUT);
  pinMode(button_4, INPUT);
  myStepper2.setSpeed(4);
}
 
void loop() {
   bval1 = digitalRead(button_1);
  if (bval1 == HIGH)
 myStepper.step(8);
  delay(0); 
{
 bval2 = digitalRead(button_2);
 if (bval2 == HIGH)
 myStepper.step(-8);
 delay(0); 
{
  
 bval3 = digitalRead(button_3);
 if (bval3 == HIGH)
 myStepper2.step(8);
  delay(0);    
{ 
 bval4 = digitalRead(button_4);
 if (bval4 == HIGH)
 myStepper2.step(-8);
  delay(0);  
  }
}
}
}

now it’s better ?

patison:
now it’s better ?

Probably worse

Look at the comments I have added to this piece - the same problems appear elsewhere

	bval1 = digitalRead(button_1);
	if (bval1 == HIGH)     // <<<< missing {
		myStepper.step(8);
		delay(0); //  <<<<<<<< does nothing
	{ //  <<<<      wrong {

If you are a complete newcomer to coding study the examples that come with the Arduino IDE and use the Auto Format option in the IDE editor.

…R

i totally don’t understand this code :frowning:

can u please reedit it for me ?

i already fix missing “{” but result are the same :<

patison: can u please reedit it for me ?

That won't help you understand it. The code you have posted is not very complicated.

At the moment your problem is that you don't know the basic requirments for creating code - how to organize {} and such. That's why I suggested you study the examples that come with the Arduino IDE.

When you understand the basics it will be time to come back to your own project.

If you just want someone to write code for you ask in the Gigs and Collaborations section of the Forum.

...R

i try now something like this:

#include   <Stepper.h>

int button_1 = 2;
int button_2 = 3;
int button_3 = 12;
int button_4 = 13;

Stepper myStepper(2048,8,10,9,11);
Stepper myStepper2(200,4,6,5,7);

int bval1 = 0;
int bval2 = 0;
int bval3 = 0;
int bval4 = 0;

  void setup() {
  pinMode(button_1, INPUT);
  pinMode(button_2, INPUT);
  myStepper.setSpeed(8);
  pinMode(button_3, INPUT);
  pinMode(button_4, INPUT);
  myStepper2.setSpeed(8);
}

void loop() {
 bval1 = digitalRead(button_1);
 if (bval1 == HIGH) {
 myStepper.step(1);    
    } 
    bval2 = digitalRead(button_2);
  if (bval2 == HIGH){
  myStepper.step(-1);
  }
  bval3 = digitalRead(button_3);
  if (bval3 == HIGH){
 myStepper2.step(8);
    } 
   bval4 = digitalRead(button_4);
   if (bval4 == HIGH){
  myStepper2.step(-8);
  delay(0);
  }
}

sometimes works one stepper sometimes it vibrate only, sometimes two are working… :((

Hi, You may need to fit bypass capacitors to the protoboard. Connect a 0.1uF accross the 5V and gnd pins of the controller IC, as close as possible to the IC, what it will do is bypass any noise that the steeper places on the power supply, try a 10uF as well, in parallel with the 0.1uF to see if this helps.

Please the spec or model number of your stepper. Also a circuit diagram, your picture shows some stepper driver boards as well as the protoboard mounted IC's. Have you started by programming just one stepper only, then added the next stepper once you get it working, then added the next stepper, etc ?

With so much wiring using those jumper wires, can you organize your gnd wires so they all meet at a point, and not daisy chained from one section to the next, if that is the case?

Hope it helps..Tom...... :)

now it’s look’s like this:

Driver is ULN2003

photo:

at this moment i have this code:

#include   <Stepper.h>

int button_1 = 2;
int button_2 = 3;
int button_3 = 12;
int button_4 = 13;

Stepper myStepper(2048,8,10,9,11);
Stepper myStepper2(200,4,6,5,7);

int bval1 = 0;
int bval2 = 0;
int bval3 = 0;
int bval4 = 0;

  void setup() {
  pinMode(button_1, INPUT);
  pinMode(button_2, INPUT);
  myStepper.setSpeed(8);
  pinMode(button_3, INPUT);
  pinMode(button_4, INPUT);
  myStepper2.setSpeed(8);
}

void loop() {
 bval1 = digitalRead(button_1);
 if (bval1 == HIGH) {
 myStepper.step(1);    
    } 
   
    bval2 = digitalRead(button_2);
  if (bval2 == HIGH){
  myStepper.step(-1);
  }
  
  bval3 = digitalRead(button_3);
  if (bval3 == HIGH){
 myStepper2.step(8);
    } 
    
   bval4 = digitalRead(button_4);
   if (bval4 == HIGH){
  myStepper2.step(-8);
  delay(10);
  }
}

now stepper from pins 4,5,6,7 works correct, but secound one, have 2 led’s (phases) always on, and if i press the controll button 4 led’s are blink.

edit:
maybe i do something wrong with connection on buttons :

i have

5v separetly to one leg and secound one is GND, Signal and resist

even if i use this shield:

use capacitor ?

EDIT:

i stuck on this:
for now one stepper work’s perfect without any problem, other one works only when i move him before i move the (secound, working one) after if i use this secound one, the first stepper stuck.

and the only info i have is 2 led’s on HI
that how it looks like

any idea what is wrong now ? :(

any idea what is wrong now ?

Yeah - I was in bed.
Have some patience if you expect free advice

i stuck on this:
for now one stepper work’s perfect without any problem, other one works only when i move him before i move the (secound, working one) after if i use this secound one, the first stepper stuck.

Which motor works?

You could tidy up your code a bit more (not tested)

#include   <Stepper.h>

int button_1 = 2;
int button_2 = 3;
int button_3 = 12;
int button_4 = 13;

Stepper myStepper(2048,8,10,9,11);
Stepper myStepper2(200,4,6,5,7);

int bval1 = 0;
int bval2 = 0;
int bval3 = 0;
int bval4 = 0;

void setup() {
	pinMode(button_1, INPUT);
	pinMode(button_2, INPUT);
	pinMode(button_3, INPUT);
	pinMode(button_4, INPUT);
	myStepper.setSpeed(8);
	myStepper2.setSpeed(8);
}

void loop() {
	bval1 = digitalRead(button_1);
	bval2 = digitalRead(button_2);
	bval3 = digitalRead(button_3);
	bval4 = digitalRead(button_4);
	
	if (bval1 == HIGH) {
		myStepper.step(1);    
	}

	if (bval2 == HIGH){
		myStepper.step(-1);
	}

	if (bval3 == HIGH){
		myStepper2.step(8);
	} 

	if (bval4 == HIGH){
		myStepper2.step(-8);
	}
	delay(100);
}

I have increased the delay to 100 millisecs to give more time to get your finger off the buttons. Not sure if that is necessary.

…R

Sory if i upset You, didnt want to. I am just excited and can’t wait to use my device :slight_smile:

at this moment stepper Stepper myStepper2(200,4,6,5,7);

works perfect.

this stepper Stepper myStepper(2048,8,10,9,11);
works only when i turn arduino and start to move this motor and it works fine, but when i move other stepper from pins 4,6,5,7, stepper 8,10,9,11 suck and no reaction.

Funny is when i plug in power supply, two steppers works (myStepper(2048,8,10,9,11)), this stepper only have trouble with smoth move. But after few actions arduino start to overheat and restart.

Regards,

patison: this stepper

Stepper myStepper(2048,8,10,9,11);

works only when i turn arduino and start to move this motor and it works fine, but when i move other stepper from pins 4,6,5,7, stepper 8,10,9,11 suck and no reaction.

Funny is when i plug in power supply, two steppers works (myStepper(2048,8,10,9,11)), this stepper only have trouble with smoth move. But after few actions arduino start to overheat and restart.

I can't make sense of this.

What do you mean the "turn arduino"? - I can't see how moving the Arduino board could have any effect.

What do you mean by "start to move this motor"? - do you mean that you have to start it rotating by moving the motor shaft with your fingers?

Does the difference between 200 and 2048 have anything to do with the problem?

What exactly do you mean by "when i plug in power supply, two steppers works (myStepper(2048,8,10,9,11))," - how could they work without the power supply?

And what does "this stepper only have trouble with smoth move" mean? - which motor, what sort of move does it NOT have trouble with?

This "But after few actions arduino start to overheat and restart." makes me wonder if you are trying to power the motors from the Arduino. Don't.

...R

yeah sory but my english is not so good :frowning:

What do you mean the "turn arduino"? - I can't see how moving the Arduino board could have any effect.

i mean when i plug usb cable and arduino is turned on

What do you mean by "start to move this motor"? - do you mean that you have to start it rotating by moving the motor shaft with your fingers?

no no, i mean when i hold button which is responsible to rotate the stepper

Does the difference between 200 and 2048 have anything to do with the problem?

no i just change te steps per rev cause i was check other stepper.

What exactly do you mean by "when i plug in power supply, two steppers works  (myStepper(2048,8,10,9,11))," - how could they work without the power supply?

i mean extra power supply, usb cable, and DC 12V

And what does "this stepper only have trouble with smoth move"  mean? - which motor, what sort of move does it NOT have trouble with?

motor on pins Stepper myStepper(2048,8,10,9,11);, its not smoth, for example it makes half rotate than two steps back, propably some noises (or problem that always two coils of this stepper are HIGH position)

This "But after few actions arduino start to overheat and restart." makes me wonder if you are trying to power the motors from the Arduino. Don't.

I was thinking for that is plug in on arduino to get power supply and get it from VIN port. But if i am wrong i will change it

patison: Does the difference between 200 and 2048 have anything to do with the problem?

no i just change te steps per rev cause i was check other stepper.

Do you mean that the motor that works smoothly at 200 will also work smoothly if you change the value to 2048 (or vice versa)?

What exactly do you mean by "when i plug in power supply, two steppers works  (myStepper(2048,8,10,9,11))," - how could they work without the power supply?

i mean extra power supply, usb cable, and DC 12V

You have have not explained how it could work without the 12v supply.

And what does "this stepper only have trouble with smoth move"  mean? - which motor, what sort of move does it NOT have trouble with?

motor on pins

Stepper myStepper(2048,8,10,9,11);

, its not smoth, for example it makes half rotate than two steps back, propably some noises (or problem that always two coils of this stepper are HIGH position)

See my earlier question about changing 2048 to 200. Does that make a difference?

I was thinking for that is plug in on arduino to get power supply and get it from VIN port. But if i am wrong i will change it

I don't understand. The best thing would be to make a pencil drawing of all the wiring connections and then post a photo of the drawing.

...R

https://www.youtube.com/watch?v=Yi2EWFC2JO4&feature=youtu.be

here You can see how its behavior.

after restart, when i press button to rotate smaller stepper (which usually stuck, after rotate secound one) and its work fine to the both side.

on 0:40 sek i rotate bigger one (which always works fine) but after this on 0:45 u can see two leds are blinking,

and on 0:53 i try to rotate smaller stepper and nothing happend,

value 2k is for smaller stepper cause it have gearbox, and the bigest one has 200 steps per rev.