Go Down

Topic: Controlling motor with encoder feedback (Read 9894 times) previous topic - next topic

I'm new to the forum and to Arduino as well.  I'm working on a project and have come a long way in the last 2 weeks or so that I've been working on it.  I'll describe what I've done so far and where I'm going with this as well as some questions regarding how to implement software to get started and then after some testing some additional software logic.  So here's what I've got.

I'm building a semaphore signal for my live steam train club, the Los Angeles Live Steam Railroad Museaum LALSRM....(http://www.lals.org/).  I'm using a motor/encoder/gearbox combination I read about here: (http://www.robotroom.com/FaulhaberGearmotor.html).  I've changed the output gear to one I bought which is indexed and connects via a timing belt to another indexed gear on the semaphore rotation axis shaft.  I've got a 1:3 (12-tooth to 36 tooth) gear ratio.  So according to the article above the motor will make ~141 rotations per one rotation of the output shaft.  With this set up if I need to turn the semaphore from green to red I'll be rotating the shaft exactly 90 degrees.  Or from red to amber or amber to green 45 degrees.  With the gearing I've got that means the motor output shaft has to turn either 270 degrees (90 x 3) or 135 degrees (45 x 3).  At ~141 revolutions of the motor per revolution of the output shaft this translates to (270/360) x 141 =  105.75 motor revolutions total maximum. 

This is important because it means that we don't need to consider a large number of interrupts or missing encoder pulses.  I've done some basic test and found a few things out.  First, I using the Arduino Uno board with the motor shield from SparkFun.  I followed the tutorial and got two of the Faulhaber gearmotors running using the code example on the page (http://www.sparkfun.com/tutorials/195).  Next I did a rough test of the motors strength and using a vice grip I held the motor and ran the example code.  I increased the time so the signal would keep running in one direction to be sure it would rotate from horizontal to vertical without stopping.  Using just the USB connection to my computer the motor had just enough strength to lift the semaphore arm !  So I plugged in the 9-v power supply that came with the beginners kit I bought from Adafruit.  With that the motor had no problem turning the signal...  As we will be using the 12 volt power from the track system I'm certain this little motor can do the job.  Also, I'm going to add bearings to the semaphore shaft set up as it has none now, just a bolt going through some metal collar.  The reduced friction will make it much easier for the motor to do its job..

I also read this article:
and duplicated it using the same pins on the motor shield connected to the encoder pins of the Faulhaber motor/encoder.  I increased the bit size for the count (int16_t) and turned the motor shaft by hand 100 rotations.  The serial console showed the count as I turned.  The count was flawless.  No missed steps !  Even rotating as fast as I could and the count was perfect.  At 141 rotations of the motor per one rotation of the output shaft I got 141 x 4 = 564 counts per revolution.  At 100 revolutions I got EXACTLY 56400 pulse counts ...  Perfect.

So I know I can control the motor AND read the encoder.  Now I need to do the following before final 'tweaks' are applied.  I need a program that will move the motor an exact number of rotations in the desired direction.  Anywhere from +105.75 to -105.75 rotations.  I'll start at 100% power (5v) to the motor and see how much I can cut that down using pwm before the motor struggles too much.  The reason for this is that we don't want the semaphore to move real fast as it's supposed to be authentic...

So I'd like to have a simple demo program that moves the signal in some test sequence.  So start at position A rotate +90 degrees, rotate -45 degrees, rotate -45 degrees, stop.  That will be a great starting point for the program and there is little else to do after that.

I'll start with the motor just sitting on my desk.  After the basic program is working I'll hook it up to the semaphore.  I'm still working on how to mount the motor rigidly in the signal base, where the Arduino will also be.  Should be done in a few days with that and hope to have the basic program functioning by then.

Thanks in advance for any help with this.  My father, who is 80 years old got me to take on this project for our club.  He is in between cancer treatment/surgery and I'd love to at least get the demo complete before the next operation (probably in the next 2 weeks or so).  I've been working diligently to keep this project on track and I've learned a lot already.  I'm sure my program isn't all that complicated and with a little help I ca get this thing done quickly.

Anyway, thanks again, and I hope I didn't ramble too much.  I will supply whatever information anyone might want to clarify any points I might have missed.

Michael Soibelman

P.S.  Go easy on me, I'm a newbie here.


Jan 27, 2011, 06:10 am Last Edit: Jan 27, 2011, 06:12 am by Graynomad Reason: 1
Welcome to the forum Michael.

I'm a newbie here.

You've already posted more words that I have  :)

Anyway my question is, why bother with the encoder? It sound like you only need 3 positions and a few hall effect sensors on the signal or somewhere could do that. Plus they would give better feedback as you can easily find the home position.


Rob Gray aka the GRAYnomad www.robgray.com

Yes, I've considered the position sensor idea.  But I'm gonna give my method a try.  All that I need to do is write the software.  If I weren't such a newbie I'd have done it already.  I already have the capability to read the absolute position of the motor and now I just want to use that information to control its movement.  In fact, just sitting here for the last few hours I've already begun to write the program.  I just thought someone could help to set it up.  And this way I don't need any more hardware like sensors.  Just count the pulses until the motor turns the correct amount.  And keep track of the position for the next signal change.

Basically, the motor was cheap, came with an encoder & gearbox and all I need to do is hook it up to the semaphore shaft via a couple of gears and a belt and to the Arduino + MotorShield and I've got a complete system.  Small, compact and pretty rugged.  Plus, in the not too distant future we are looking to upgrade our entire signal system and the Arduino boards should make this a snap.  The fact that this is all off-the-shelf technology and we don't have to be concerned about replacement parts or proprietary designs/knowledge means we can use the system for years without worry....  Except for a couple of semaphore signals all th rest have no moving parts so one Arduino Mega could control quite a few signals and we could replace all the existing hardware for very little money.


Hi, Michael,

Do you still concerned with this problem?
This is a typical example of positioin control in the applications of servo motor with encoder.
Similar techniques are popular in robtoic arm control.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131