Stepper Motors, Limit Switches and buttons

I really tried to avoid having to bother anyone by posting here. I've been reading and watching videos for days...I think I've mostly managed to confuse myself more than anything. Below I'll post what I'm trying to do in hopes of getting some direction.

Project description: I'm building a table that will fold out of the way to be flush with the wall and then lower back down.
This will be handled via two stepper motors connected to ball screws that will guide via linear slides. I want to push a button to make the table lift all the way up until it is parallel with the wall where it will hit a limit switch and stop. I would also like to hit another button (down) to make the steppers reverse and go all the way down until hitting another limit switch. I'd also like to have a button inline where I could just stop the motors in any position (just in case I needed to).

Attached are a couple of pictures of a basic CAD depiction of what I'm wanting to do.

Equipment: I have two Nema 23 steppers. and 2 stepperonline DM556T drivers. I have an Arduino Uno with "accelstepper" library. I was trying to "frankenstein" some code together to get what I wanted, but I thoroughly confused myself (I may be trying too much, too fast). But any suggestions of where I can read or obtain addtional info to get me on the path? Thank you!!

Here is the up picture (I'm new, so I was restricted to only one photo upload).

How the motors and switches are wired to your board?

Have you played with basic examples to make sure that circuits are working?

1 Like

Better terminology is "Nema 23 stepper motors". "Servo motors" are very much different motors and can not be ran by a stepper driver.

Haha. I like Your humour.

One suggestion is to check the IDE for basic stepper motor code.
The other suggestion is that You post Your "monster", using IDE autoformat and "code tags", the </> symbol in this window.
Drawing schematics showing the powering, and the signalling might get interesting.
Just started using Accelstepper and know there are some traps using not suitable functions to let the end switches come in play. Some functions are like "ho ahead and don't return until finished". If the end switch is hit but there are more steps to do the switch will be over ran...
Have faith! We'll sort things out together,

1 Like

Thank you for replying. Every example has a different config, which I adjust. If I just copy a code and upload it. Everything works. It's when I modify that I seem to make a mess.

Initially I downloaded the tutorial that showed a limit switch on each end and it just reversed the motor when it saw the limit switch. That code used accelstepper and ezbutton. I tried to add 3 more buttons (as per my listing above. That didnt' work as I wasn't sure what the code needed to be for the button configuration I wanted.

Geez, I'm quite embarrassed. I know the difference between steppers and servos (even on a professional level, but we won't talk about that). The last video I watched prior to my post was about servos and arduino...so I must have had that in my head. I've fixed the post.

I started with the code here: https://arduinogetstarted.com/tutorials/arduino-stepper-motor-and-limit-switch

And then, I tried adding variations of code from this tutorial: https://arduinogetstarted.com/tutorials/arduino-button

And then I thoroughly confused myself. Here is what I learned:

I need to identify 5 buttons in the code. Two of those are limit switches. The other 3 are traditional buttons. I just can't find code that has a button initiate the movement. I don't care about the code "homing anythign". And I don't care if the code doesn't ever know where the motors are. If the table is down, I want to push a button and it will go up until it sees the switch and vice versa.

I made such a mess of the code, I didn't save it. I will give it another whack and post it here in hopes someone can make some suggestions of how to modify it. Thanks!

Show us a schematic where we can see where each switch and motor is connected to your board.

1 Like

thanks again Fernando! I'm happy to put that together, but really, moving the switches and motor to the arduino is pretty easy. It's the code that I'm hoping to get some help with.

You could have posted the first attempt as per Your reply in #5, and we could have assisted You.
Don't search complete solutions. Search for key parts and keep the nucleous You need. Then add one new piece and make it work. You have taken too large steps it looks like.
Troubeling with button libraries might not always be needed.
Using the pin definition "INPUT_PULLUP" the button is connected between input pin and GND. The reading gives 0, or LOW when button is active.

1 Like

You are 100% correct. I started off too big. I'm going to take your advice and go back to where I started (motor just turning when I add power to arduino). Try to get it to stop when I press a button (limit switch or "stop button), and then do the same for the opposite direction. And then add the start buttons. When I get stuck (again). I'll post code here for help. Thanks again @Railroader

I don't know exactly what you doing but it can be useful.

Thanks for picking up the idea! Continue this post if anything stops You. Adding more items doesn't help, only the opposite.

@FernandoGarcia This is so cool. I didn't know something actually existed. I tried to enter my items as I could. The library at wowki doesn't have my actual driver, so I used one they had (mine is actually a stepperonline dm556t (as seen in the attached picture). I started laying things out (as you can see here: tabletop - Wokwi Arduino and ESP32 Simulator ) . I'm not certain of the commands to tell the servo to "run" via the button and how to stop via the limit switches. I'm going to try @Railroader suggestion and slowly add components to see if I can get it to do what I want little at a time. Any suggestions are getrealy appreciated. I should also mention that this forum is freakin' awesome with all of the help.

New users should really read all this:

1 Like

Impressive, likely good and powerful stuff.
Can You post a datasheet link to that driver? Many, most(?), drivers have a common interface like Direction, Pulse and Enable. nothing more.

I've learned that some members are fascinated by those simulation tools. However they often fail in some aspect and things don't run in reality.
Read datasheets carefully and when You understand them, connect things and run. Simulation and theory might be good sometimes but reality speaks for itself.

1 Like

Thanks again. Honestly, I'm not putting too much stock into the simulation tool. I just thought it was super cool, and visually it helps. The datasheet for my specific driver is found here:

And @Railroader , I seriously appreciate your patience in dealing with such a newcomer. Thank you very much.

I did read that. Did I do something wrong?

@FernandoGarcia hooked five switches up to an Uno in #11. If those were your 5 switches/buttons, what would you want them to do? If A0 and A4 are the limit switches, what would you name the other three switches and what would you want them to do?

The other way to think about your projedt is that it is doing one of a limited set of things: {movingToUp,movingToDown,stayInPlace} and the problem is knowing when and how to switch between the operation states.

If you can describe your inputs, outputs, and what you want to do, there's lots of ways to get it done.

I'd approach it with Demonstration code for several things at the same time - #2 by Robin2 with code monitoring the buttons and limit switches, and a state machine to switch between {movingToUp, movingToDown, stayInPlace} based on the button states. The button/switch based transitions seem pretty straightforward: if you are movingToUp and limitUp or stopButton is detected, switch to stayInPlace, etc...

But there are many, many ways to approach it. It helps if folks know what inputs and outputs you have, and what is connected where.

That stepper works as supposed in earlier reply.

@DaveX , thank you very much. So here is a better explanation of what I'm trying to achieve:

I have a table (or will have) that folds/hinges out from a wall into "normal" position, and then back up out of the way. The table is on linear slides connected to ball screws and "lifted" via a stepper motor (picture in first two posts). I'd like to have a limit switch at the full "up" position, one at the full "down" position (to tell it to stop when going "up" or "down". I would then like to have a button dedicated to telling the motor to spin clockwise (up), another button dedicated to telling the motor to spin counter-clockwise (down).