If I want to control the CW and CCW rotation of a stepper and limit it to certain angles, can I do this with a rotary encoder and 2 limit switches. I'll be using an Arduino Uno and easy driver.
If I want to control the CW and CCW rotation of a stepper and limit it to certain angles, can I do this with a rotary encoder and 2 limit switches. I'll be using an Arduino Uno and easy driver.
You shouldn't need the rotary encoder. Just locate the two limit switches at the desired angular limit positions and stop moving when you reach one.
Anything seems possible when you don't know what you're talking about.
Basically you need neither limit switches nor encoder. The whole point of a stepper motor is it moves in steps so you work out how many steps to move and issue that many steps.
One reason for a limit or home switch is to find where you are at start up. Normally you drive the stepper to the limit switch, then slowly back off untill the switch breaks and you have your datum. Apple ][ disc drives used to drive the stepper until it hit a hard stop to datum it. There wasn't enough power to do any damage.
It is possible for a stepper to "lose steps" if the design is marginal in which case an encoder could save the day.
The critical thing with a stepper driving a load is to ramp up the speed so you don't exceed the torque of the motor, if you do it just stops whining away but not moving. You now have no idea where it is.
Hi Hilldweller, thanks for the feedback. I realize I can figure out the number of steps required to go from one point to the next and back but, I need to control the rotation between the 2 points but not exceed them and also be able to return to the start point when I shut off the power, reindexing the stepper to zero. I'm assuming I need something like an encoder to dial the amount of travel between the start and end points?
I'm trying to design a small vent assembly to allow fresh air into a cab. I need to be able to control the amount of air flow into the cab by controlling the open position of the vent door. There is a maximum amount of rotation I can have before the vent door hits a wall which I assume means I need a limit switch? If the vent door is fully open when I shut off power, the stepper doesn't know where it is. After turning the power back on if I rotate the encoder to close the door, I would need another limit switch at the start point. Does this seem like the best way of doing things or can you think of a simpler solution?
I'm using an Arduino Uno, and Easy Driver.
Thanks
@banjobrad2 There are a couple ways to deal with the 'where was I' problem. Indeed just driving in one direction until you hit the limit is ok, what is known as the 'brute force' solution, another more elegant but slightly complex way is to save the current position after each move to a semi permanent memory like EEPROM which the UNO has.
I am getting a sense that you are unfamiliar with a stepper and don't realize that there is a relationship between each step and the shaft's angular position. Maybe check out a YT video or two and I think you will see that it's a little more precise than you are thinking and easy to position to a known spot. Good luck.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@banjobrad2 BTW, when replying, click the Reply link at the bottom of the post you want to reply to that way an automatic tag is inserted as in @banjobrad2 and that causes the person you are replying to to get an email (if subscribed) that tells them they have a reply to read.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@zander Hi Ron. Maybe I don't get the whole picture yet but, if I drive the stepper in one direction without a limit switch, would I not possibly be driving my vent door into the wall without actually knowing I'm doing this? I could be trying to push the stepper rotation beyond its physical limit. The same is true for the return situation.
I'm trying to design an air vent assembly in which I need to control a vent door that starts at a closed position and can be gradually rotated to any increment between the closed to fully open position, which is against a wall. When power is removed, wherever the vent door is at that point in time is fine. When power is back on, I can resume rotating to either limit. Is there a means of doing this like you proposed without actual limit switches?
Thanks
@banjobrad2 I hope the stepper expert @will will chime in with a better description but my limited understanding is each step is a certain number of degrees so all you need to know is the total number of degrees between your two limits then simply add or subtract depending on the direction.
Have a look at the YT video on DBWS (Bill) that explains this better than me.
YES, you will still need the limit switches since it is technically possible to move the motors manually as in the door can be moved by the air coming in and moving the motor without some strong gear reducers.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@zander Ron, the amount of air coming in is not going to be a problem. What I still need from an encoder would be control of rotational increments between the start position and end position as well. I don't want a stepper that just infinitely goes from start to finish. Is there something else that I'm missing in trying to understand this?
@banjobrad2 I am not sure you understand how a stepper works. Here is a link to the blog article with code that might help you understand. https://dronebotworkshop.com/stepper-motors-with-arduino/
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@banjobrad2 I may not be understanding you so excuse me if I am telling you what you already know. Let's assume the total travel from one limit to the other is 45 degrees. Let's also assume the stepper moves 3 degrees each pulse. Simple math says you need 45/3 or 15 pulses from limit to limit (numbers are fictional, I don't know real numbers) If you know you are starting at one limit, then your code simply maintains the total steps to know where it is. You could even save that total to EEPROM or similar.
Have you connected a stepper on a breadboard and played with it? I doesn't sound like it or you wouldn't have these questions. I strongly advise you build a setup according to the YT video/blog mentioned earlier.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
Hi @banjobrad2,
Probably the most common method of determing the start position of a stepper motor. is indeed to use a microswitch or equivalent sensor to detect when it is at one end of the range ... and then simply gently drive the motor until it triggers the sensor, (with a software protection count limit when it has been sent enough steps to return from any position, to avoid driving a jammed motor continuously.) This method can be seen on many of the 3D printers.
You might want to add some physical end stops so that the vent is not damaged by an overzealous motor.
----------
Many years ago, and maybe still today, 'cheap' disc drives didn't bother with limit switches ... they simply repeatedly 'stepped/hammered' into the end stop at power on for 2-3 seconds, knowing the end stop was stronger than the motor.
That is the truly 'brute force' approach ... I am not recommending it, but it is an option!
Best wishes, Dave
@zander Ron, the amount of air coming in is not going to be a problem. What I still need from an encoder would be control of rotational increments between the start position and end position as well. I don't want a stepper that just infinitely goes from start to finish. Is there something else that I'm missing in trying to understand this?
A stepper motor operates by receiving pulses from the driver which drive it forward (or backward) one step at a time.Hence the term "stepper" motor. Depending on the make and model of your stepper, they each have a distinct angle through which each step moves. Many are 1.8 degrees and take 200 steps for a complete circle (i.e. 1.8 x 200 = 360).
You are correct that you need away of "homing" it after its turned on and rotating it to a limit switch is a good method. When it closes (or opens) the switch, you set that point as zero and work from there. If you measure the angle to the vent when fully closed (or fully open depending on where you want it to start) then you can calculate the step count.
For instance, if you want the vent to open 45 degrees from closed using a 200 count stepper, then 24/1.8 = 25. So you'd need to move the vent 25 steps to get it fully open. To close you can count back 25 steps or close until the limit switch is reached.
Note that you can also open the vent to any step count less than 25 as well.
You can store the last position of the stepper to read again at startup but this method is only safe if you can be sure that the vent can't be moved when the electronics are shut off and that power can't fail while the device is in use (which might prevent the current step cout from being saved).
Anything seems possible when you don't know what you're talking about.
@banjobrad2 I missed an obvious explanation. If all you need is two positions, fully open or closed then all you need is the limit switches, but if you want to stop the motor at some point between those two then you need to do the usual calculations. An encoder isn't really needed, the stepper is very accurate but can be fooled by moving it with your hands BUT the limits are always checked in any case and then you zero the location. Clear?
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
Hi @banjobrad2
"What I still need from an encoder would be control of rotational increments between the start position and end position as well."
The choice of user interface to select intermediate positions between fully opened and fully closed is partly one of your imagination.
One of the simple rotary switches could be used, but remember the 'cheap' ones also suffer from a 'where am I?' problem ... they actually just provide pulses to indicate they have been rotated ... they do not give an absolute position.
The 'old skool' approach, might use a potentiometer, with the track 'powered' from the Arduino board/supply and get the Arduino to measure the voltage at the slider. Cheap, and pretty simple to implement, plus at power up, the Arduino can determine the value the pot was last set at. Then, some simple maths to turn the pot setting into a number of steps to move the vane.
A contemporary solution would probably have two push buttons .. one to step in the open direction, the other to step in the close direction.
The choice between 'old skool' and 'contempory', for a car designer would probably be based on the few pence saved with the push buttons. With the push buttons, you might want to save the position last selected in memory ... this is feasible, but may require you adding an extra memory to the Arduino.
And no doubt there are other choices I haven't considered ...
Best wishes, Dave