controlling motor speed with a LVDT and POT

Hi there,

I would eventually like to control the speed of a motor by an LVDT. But first I would like to master it with a POT.

I have a few questions:

1) DC Motor or Servo Motor? I've purchased a servo motor and I think it should work fine. But I've read here on the boards that it's difficult to speed control. Therefore, is a DC motor the better option?

  1. I want to use the following code (the knob code from the arduibo library) to control my servo. I have also been using an Adafruit Motor Shield and connected a 10 Kohm Pot into Analog input 5. Orginally my pot was getting “smokey”
// Controlling a servo position using a potentiometer (variable resistor) 
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> 

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 

int potpin = 5;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin 

void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 

void loop() 
{ 
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 
}

What is wrong with the code?

The code won’t make your pot “smokey”. Incorrect wiring will.

Correct that, and then let us know if you still have a problem.

The +5V goes to one side of the potentiometer. The other side goes to ground. The center tap (connected to the wiper) goes to the analog pin.

Nothing is wrong with the code per-se, but I am wondering about you potentiometer - can you give us a schematic or drawing of how you wired it? It shouldn't smoke (baaad)...

As far as speed control is concerned:

Standard R/C servos operate a one speed only; it is possible to send them incremental positioning commands with a delay in-between, but this results (sometimes) in jittery control, and probably not what is expected.

Your sketch you posted is meant to control the position of a servo with a potentiometer, not its speed.

You don't say what you intend to do with the motor once you have its speed control (and you might want to define what an LVDT is - remember, if you ever use acronyms in writing, after the first introduction you should define the acronym, then use the acronym alone thereafter - you get a pass if english isn't your primary language, but isn't this something covered in high school english class?); if you need a gear motor for more torque, a servo can be used, but if you need to control its speed, then you will have to customise it (basically bypassing the window comparator circuit in the servo, and driving the h-bridge directly, and reading the potentiometer that is in the servo with the Arduino, and implementing your own comparator or PID control with speed control; something you won't find built into a servo, unless it is a programmable digital one).

You can hook up a regular DC motor, and use PWM to control a driving transistor or h-bridge (depending on whether you need directional control or not); with PWM, you can vary how fast the motor is turned on-off, effectively changing its speed. There is a PWM example included with the Arduino IDE for varying the brightness of an LED with a potentiometer, I believe - if you ran that output instead to a driver circuit (ie, transistor/darlington or h-bridge input), then that to a DC motor, you would vary the speed with the potentiometer.

It probably wouldn't take that much to then convert over to the LVDT (whatever that is) - Ok, just googled: Linear variable differential transformer? Hmm - you might have your work cut out making that work, but still, it should be possible...

Good luck!

:)

remember, if you ever use acronyms in writing

...

You mean like PID, PWM, IDE, LED, DC? ;)

Doh! :'(

Thanks everyone for the help. It's not smoking anymore. I still don't know why it was smoking. Apparently the POT could handle being plugged in either way.

The code does work to manipulate the speed to a certain extent. For example 90 makes it stop, and 180 goes one way, and 0 goes the other.

I'm assuming that the PWM is configured into the servo library since it takes in integer values and powers the motor.

My new problem is, precision motor speed control. At values around 100 to 80, the motor runs slowly in each other direction. However, at higher values (150 plus) or (less than 40) the speed does not change.

I have a theory. 1) Is the arduino current limited? Therefore say when my pot turns and gives me a value of 150, i have already reached the max current?

if you need a gear motor for more torque, a servo can be used, but if you need to control its speed, then you will have to customise it (basically bypassing the window comparator circuit in the servo, and driving the h-bridge directly, and reading the potentiometer that is in the servo with the Arduino, and implementing your own comparator or PID control with speed control; something you won't find built into a servo, unless it is a programmable digital one).

You can hook up a regular DC motor, and use PWM to control a driving transistor or h-bridge (depending on whether you need directional control or not); with PWM, you can vary how fast the motor is turned on-off, effectively changing its speed. There is a PWM example included with the Arduino IDE for varying the brightness of an LED with a potentiometer, I believe - if you ran that output instead to a driver circuit (ie, transistor/darlington or h-bridge input), then that to a DC motor, you would vary the speed with the potentiometer.

Thanks Crosh. Do you have links or any reference that you know of that will help me implement that? I'd really appreciate it.