Controlling stepper motor with a single switch

Hello,

I have a Nema23 stepper motor running with a tb6600. IT runs very good. I want to use the stepper motor like a tv lift. There s a leadscrew mounted. When I hit a switch the 'tv' goes up and stops at the top. The motor also stops. When I hit the switch in the other direction it goes down and stops at the bottom. My idea was that When it reaches the top or bottom a pull down takes place on a pin and the motor stops. When I hit the switch again, reverses the direction and stops at the other end, again with a pull down resistor. Does anyone has an idea on how to do this? Are the pull downs a bad idea?

It looks easy...but nog for me

what does this mean?

When I hit the switch in the other direction

what type of switch is this ?

What do you mean with

again with a pull down resistor

?
In which circuit would the pull down resistor be installed?

An easy way to move something between two points is to have "limit switches" at the end of the way. when your TV touches the switch, your arduino detects that and stops the motor.

When you say "pull down" are you referring to a limit switch. If so that would be a normal way to stop at the desired position.

If you have written some code please post it and tell us what it actually does.

The switch has to be a 3 way switch. In my example I nowmuse 2 push buttons.

My idea was also to use the tv or tvmount as limit. When it reaches the top it makes a circuit that pulls down a pin on the arduino uno.

BrutusBert:

sorry no... don't get what you have in mind

have a look at the links from Robin, they will give you some ideas

It IS simple to use one switch to make the motor run either direction. The key is that you have to keep track of which direction to step when the switch becomes pressed. A global boolean variable is all that is needed. true means step one way. false means step the other way. Set the variable to true or false when the motor makes the device trigger the limit switches.

A two way (SPDT), or two separate SPST switches are effectively the same.
They will be read with two pull-up input pins when the switch contacts close to 0V.
With either switch configuration, you need to consider what should happen when both switches are closed for any reason.

Why do expect a 3-way switch will help?
PaulS suggested the easiest, foolproof way of implementing the control switch. A single SPST push button.

You will add limit switches to stop overrun of the mechanism, and some simple code that translates the control button input into
Run up
Run down
Stop (if you ever want to interrupt an up/down. (cat’s tail caught in mech)

BrutusBert:
Hello,

I have a Nema23 stepper motor running with a tb6600. IT runs very good. I want to use the stepper motor like a tv lift. There s a leadscrew mounted. When I hit a switch the 'tv' goes up and stops at the top. The motor also stops. When I hit the switch in the other direction it goes down and stops at the bottom. My idea was that When it reaches the top or bottom a pull down takes place on a pin and the motor stops. When I hit the switch again, reverses the direction and stops at the other end, again with a pull down resistor. Does anyone has an idea on how to do this? Are the pull downs a bad idea?

It looks easy...but nog for me

This is a pretty common situation, and we deal with it with a state machine. At any time, your sketch can be in one of four states:

enum State { TOP, BOTTOM, MOVING_UP, MOVING_DOWN } state;

Inside your loop, you have a switch statement whose job it is to deal with what needs to be done when the sketch is in that state:

void loop() {
switch(state) {
case TOP:
if the 'down' switch has been pressed, {
start the moving down motor
state = MOVING_DOWN;
}
break;

case BOTTOM:
if the 'up' switch has been pressed, {
start the moving up motor
state = MOVING_UP;
}
break;

case MOVING_UP:
if the top bumper has been hit {
stop the moving up motor
state = TOP;
}
else {
continue moving up
}
break;

case MOVING_DOWN:
if the bottom bumper has been hit {
stop the moving down motor
state = BOTTOM;
}
else {
continue moving down
}
break;
}
}

As an aside, it helps if you use english language modal words (should, would, will, can, might). When you say:

When I hit a switch the 'tv' goes up and stops at the top.

This means that this is the situation that currently happens now - that something is stopping your tv already. What you probably mean is

When I hit a switch, the 'tv' should go up and stop at the top.

And what might even be better is to distinguish who is doing what - the agent. I can see here that it's you who hits the switch, but who or what is making the TV go up or down?

When I hit a switch, the sketch should make the 'tv' go up and should stop it at the top.