How do I control the exact position of a motor with Arduino?
August 7, 2017 11:59 AM   Subscribe

Through code, I am looking to tell the motor what position to go to at a specific time (always one rotation direction, but stopping at different positions along the way) - what kind of motor do I need for that?

I'm designing a split-flap display board but each flap will act like a pixel for an image the whole size of the board. I will have to 'program' each motor to go to a certain position so that one whole image is displayed. For example, if I have 12 positions on each motor, each corresponding to one part of an image, I'd like to write code to say 'at 12:33, send all the motors to position 6; then a 12:37, send all the motors to position 9'. Also, there will be one user input, where when they do something, it'll go to, say, position 1.

The motor is always moving in the same direction, but stopping at different, specific positions along the way.

So what type of motor can do this? I've been reading about rotary encoders, but I want to control the motor position with code/feedback from the motor and not a separate switch. I'm hoping to use an arduino uno and a bunch of 16 channel servo drivers.

Let me know if you need more details and thanks for your help in advance!
posted by AutoPilot83 to Technology (13 answers total) 5 users marked this as a favorite
I'm a total amateur who's been using an Arduino for a couple of months for non-motor-related stuff... but based on what I got in my starter kit, I think you're after a stepper motor? And I think it'll also need a special IC to control it alongside the Arduino itself.
posted by Ted Maul at 12:01 PM on August 7, 2017 [1 favorite]

You'll probably want to check out servos. They'll go to a predetermined position based on your inputs.
posted by TrinsicWS at 12:04 PM on August 7, 2017

A servo coupled with the standard arduino libraries will do this, but be sure to buy a 360 or continuous servo - standard servos have a stopper in the gear system that prevents them from going outside of a certain range (usually 180 degrees). Modified servos that provide full 360 motion are available but you'll have to be sure you're buying one specifically.
posted by Itaxpica at 12:14 PM on August 7, 2017

Note that continuous servos can't do what you're looking for on their own - the act of modifying them to rotate continuously means that you lose the ability to keep track of their absolute position, so you'll need some sort of external encoder. Do you need the motors to always be rotating in the same direction?
posted by btfreek at 12:35 PM on August 7, 2017 [1 favorite]

Most of those little servos expect to travel bi-directionally, so that's not going to work for the typical split-flap module rotation.

If all units are moving together and you don't need to automatically "home" each unit, I'd say a DC stepper board on each unit with a single signal pulse wire connected to all of them to drive them one step forward.

For the final assembly you then home/reset all pixels by hand upon startup, and the controller keeps track of current and desired positions. (e.g. if there are 100 steps in a revolution, you program the controller to assume it starts at position 0 and then you can count steps forward to get to any place you want, wrapping mathematically at position 100)
posted by JoeZydeco at 12:53 PM on August 7, 2017

Do you have the flap board hardware? I'm just thinking that the movement is somewhat discrete and depending on the gearing of the 'flap' device a small solenoid that pushes a cog may be more accurate. One push triggers one flap. Stepper motors and servos are expensive and need control logic, if the mechanism can be triggered by a push movement it's simplify to just keeping count of the pushes.
posted by sammyo at 1:01 PM on August 7, 2017 [1 favorite]

Stepper motors are set up with a set of coils that you energize in a particular sequence to move the motor one direction or the other. So if you currently have the "A" coils energized, and you energize the "B" coils, the motor moves to mid-way between the "A" and "B" coils. If you then de-energize the "B" coils, the motor moves to the "B" coils, and so on for the "C" and "D" coils and back to the "A" coils.

(Sometimes the "A" coils and the "C" coils are the same coils, but energized in reverse. Usually, though, there are 5 or 6 leads from the motor, and you drive 4 of them and the others go to the common point on your power supply.)

So steppers are super handy for when you want to move a precise amount in any direction, and when you want to hold at a particular location. But, they only do this if you're asking for less torque than the motor can generate. They also don't know exactly where they are, just that they're at one of the coil positions, and there can easily be 200 positions in a full rotation in a common stepper motor. Back in "the day", floppy disk drives made a horrendous racket because rather than having a switch that told them where "home" was, they simply banged the read/write head against the stop 40 or 80 times to make sure that it was at zero, and then did relative indexing from there.

Servo motors are the combination of a more standard motor and an encoding mechanism, so they know where they are, and can go to a location (in cheap hobby servos usually an analog location, specified by a how wide a pulse is, sent about 20 times a second). This means that they don't necessarily hold the location super well (if you torque them out of the location, they torque back).

Unless you're very smart in driving them, stepper motors tend to be louder and have more vibration (think a little buzz every time a coil is energized), and take more electricity (they're always drawing current, even if nothing is trying to move them).

For your application, I think you want stepper motors. They're easy to drive, they do the "turn 1/x of a turn" really simply and easily. The only question is how you'll home them. For a clock, sometimes this is moot: You "home" them by setting the clock, so that's a human process. For applications where they only have to turn one direction, maybe you can turn them back against a ratchet a set number of times? Or maybe you just have a "home" switch.

They do take some number of outputs from your microcontroller (2 or 4, depending on your driver circuitry), but the driver circuits can be amazingly simple.

Can you elaborate on "I want to control the motor position with code/feedback from the motor and not a separate switch"? Is some homing procedure and then just telling the motors where to go sufficient?
posted by straw at 1:16 PM on August 7, 2017 [2 favorites]

Straw: I'm worried about the longevity of something with no encoder. I think i want the motor to know where it is in it's 360 degree rotation, if that's possible. Some way of self correcting if things start getting loosey-goosey. I don't mind the noise, though - in fact I think it will add to this piece.
posted by AutoPilot83 at 4:27 PM on August 7, 2017

So it is totally possible to hook up an encoder to everything, but with stepper motors, sometimes you just size them to several times the worst-case torque and trust that they're going to be where you set them (a whole lot of devices do this, from paper cutters like the Cricut, to a system I once worked on that moved mannequins around).

I know of at least one mid-scale art clock installation which just runs, and I believe has done so for years.

If you're building ten thousand of these maybe stepper size is an issue. If you're building one, just order a size up (if you're in the SF Bay Area, I probably have what you need in my junk parts box).

But having a home switch (is this where I think it is? if there's any drift reset it here.) is a cheaper (both $ wise, and in terms of I/O pins) option than having a full-on encoder.

And on encoders: You can get/make an encoder that'll tell you where you are on the circle, or use a home switch and a quadrature encoder to count where you are. If you go with steppers, just use the home switch and dead reckoning from stepper pulses. Seriously, you'll be within like a 400th of where the home switch toggles until someone jams an arm in there and gums up your works, and then you'll be happy that the stepper failure mode is not "draw progressively more power and burn up", but just "beat back and forth a little bit until the jam is removed".

Memail me if you wanna take specific design issues off-line...
posted by straw at 5:03 PM on August 7, 2017 [1 favorite]

stepper motor
posted by patnok at 5:49 PM on August 7, 2017

Straw, I'm with you :) I'll be in touch. Thanks for the input - everyone.
posted by AutoPilot83 at 8:19 PM on August 7, 2017

I'd go with stepper motors over servos for this job for sure. One of the nice features of steppers for this kind of application is that the interaction between the internal magnet and the pole pieces gives you a certain amount of positive location even when no coils are energized.

If I were designing a moderately large split-flap array, I'd be tempted to look into using a single motor for each row, with a common shaft running through all the flap wheels in any given row and some kind of per-column mechanical clutch to bind some subset of wheels to the shaft at any given time. This would allow multiple flap wheels to operate simultaneously without needing ridiculous amounts of motors and wiring.
posted by flabdablet at 6:03 AM on August 8, 2017

YouTube is, as ever, helpful.

It's completely feasible to control a stepper motor using nothing more complex than a current driver like a ULN2003 to buffer one digital output per stepper motor coil, if the sheer number of steppers you're trying to control makes the EasyDriver referred to in the linked video cost-prohibitive. The AccelStepper library makes controlling the motors about as easy either way.
posted by flabdablet at 6:22 AM on August 8, 2017

« Older Favorite cold noodle salads   |   Teach me to defeat my baking nemesis Newer »
This thread is closed to new comments.