Control bipolar stepper motor with potentiometer?

Hi, I have just discovered this world of arduino. So I’m the newest noob!!

I have a bipolar stepper motor than I want to control with a potentiometer. The stepper motor needs to move a pin, (via a rack and pinion setup) to adjust the flow of oil.

There will need to be 3 positions for the pin.

0 - fully open = oil flows, this should be with the pot at 0

1 - half open = partial oil flow, this should be with the pot at halfway position

2 - fully closed = no oil flow, this should be with the pot at full position

The stepper motor doesnt need to move the pin very much, probably 2 or 3 steps to halfway and another 2 or 3 steps to fully closed.

Is this possible to do using arduino and what hardware would I need to get this setup working.

Heres some pictures, sorry about the quality.

stepper motor.JPG

fully open.JPG

half open.JPG

fully closed.JPG

Yes this is an easy thing to do. Have a read of:- http://arduino.cc/it/Tutorial/MotorKnob

Thanks Mike, I have had a look at that motor knob diagram. Is that all the hardware I need or would I need a motor shield?

You will need something to drive the stepping motor. Either a dual H-bridge circuit or better still a regulating stepping motor driver.
This is one I use a lot:-

hmmm that regulating stepping motor driver looks way to complicated for my skills :blush: Think I will go for the H-bridge as its going to be my first attempt at this.

Thanks for your advice Mike

looks way to complicated for my skills

The complication is all in the circuit that is done for you. I think it is much easier to use than a H-Bridge because you can set the current with a pot. Where as with a H-bridge you have no control over the motor current other than adjust the voltage driving the bridge. For a given motor you can get it running faster with the driver than the bridge.

While I am waiting for my arduino to arrive. I have been thinking more about what I am trying to achieve.

I have some more questions, if anyone can help.

The housing that the stepper motor is mounted in as ntc glass thermister to measure the oil temp. 1 - Can I connect this thermister to the same arduino board to give a read out to a lcd screen?

2 - Would I be able to code the arduino to turn the stepper "off" when the oil reaches a certain temp. Stepper would need to open the valve to allow oil to flow again? If not, could it activate a LED to indicate the oil temp is high?

3 - Would I be able to connect a LCD read out screen to the same arduino to show oil temp and stepper motor position with relation to the pot being turned?

4 - Lastly, how would I go about setting the stepper back to the "open" position when the power is turned off. I have realised that this is going to be a problem, because if the stepper is in the "closed" position and the power is turned off, then someone turns the pot to the "open" position while the power is off. The stepper won't know that the pot has been moved and when the power is turned on and the pot is turn to the "closed" position, the stepper is going to try push the pin past the "closed" position and strip the rack and pinion gears as the pin won't be able to move further closed.

Is a stepper motor the correct thing to use for this. I was thinking about using a solenoid to push the pin to "closed" position but then I will only have 2 positions, open or closed. Nothing in between, it's not the end of the world but would like to be able to adjust the positions.

Sorry for the dragged out story, would appreciate the experts input on this.

Cheers

1) Yes 2) Yes 3) Yes 4) No - the problem is that once the power is off you can't move the motor because there is no power. The best you can do is to have an off button that will do the motor movement and then power it down by using something like a latching relay.

You can do it with solenoids, but use more than 1 solenoid. I have seen a similar system for controlling gas flow in a welding machine. There were 3 solenoids, with 3 different orifices. by selecting a combination of the 3 solenoids there were 7 different flow rates and Off. With 2 solenoids you could have 2 or 3 flow rates with one solenoid defaulting to open when power is off.

If you're using a stepper motor you need some way to find out the initial position. Either you can just keep moving it until it hits a mechanical end stop, or you need some sort of position sensor such as a limit switch so that you can come back to a known position at startup.

Is it practical to use a servo instead of a stepper motor?

Thanks for replies guys. 1 - Awesome 2 - Awesome 3 - Awesome

This arduino stuff sounds pretty cool. I am already losing out on sleep by staying awake late and trying to learn about this.

The component already has the bipolar stepper motor with a circuit that only allows it to have 2 positions, open and partially open. I want to change the original circuit to allow the arduino to control the stepper motor and have more options on oil flow.

If I had to use a solenoid or servo I would need to fabricate a new housing for the pin to fit into and work correctly.

Another couple questions :)

1 - Could a use a rotary encoder instead of the pot and install a spring on the pin to allow the pin to return to the original "open" position when the stepper is off?

2 - Would I be correct in assuming when the stepper motor has power connected, the coil stays charged to hold the motor in that position. Therefore the stepper motor won't allow the spring to push the pin back to the "open" position?

3 - If I can use a rotary encoder for this project, would it matter if the knob was turned while the system is off? If the encoder was in the "closed" position when the power was turned off and the spring pushes the pin along with the stepper motor to the "open" position, when the power is connected again would the rotary encoder assume its in the "open" position and allow you to turn it to the "closed" position and move the stepper motor to the "closed" position?

Wow that was pretty confusing to type

2 - Would I be correct in assuming when the stepper motor has power connected, the coil stays charged to hold the motor in that position.

That is true. However most motor drivers have an enable input that allows you to turn the coils off.

1 - Could a use a rotary encoder instead of the pot

There are two types of rotary encoder, absolute and incremental. The absolute type is like a pot, it gives a reading of the angle of the shaft. However these can be very expensive. The incremental type just give a pulse for movement and you have to count the pulses, therefore when first turned on you need some way of getting a reference.

Thanks Mike, not sure why its Grumpy Mike, as I find you very helpful and patient XD

So I got my arduino uno, h-bridge and pot. I have connected it all up and its working. I have also managed to set the amount of steps and speed that the motor turns when the pot is adjusted.

However if I move the pot from left to right a couple times, quite quickly the motor either misses a few steps or does a few extra steps. I havent tried the setup with a rotary encoder yet but I feel it might do the same thing. Would I be able to use a rotary switch to select 3 positions for the stepper motor. 1 = off 2 = 50% ( the stepper motor moves "x" amount of steps) 3 = 100% ( the stepper motor moves another "x" amount of steps)

My goal is to step the motor 4 steps at 50% and then another 4 steps at 100%, so at 100% the stepper will do 8 steps and when needed the switch can be turned back to 50% and the moter will step back 4 steps from the 8 step position.

There is a limit to how quickly a stepper motor can step, and the limit depends on the power supply and how much force the stepper has to generate to move. Is it possible that under some conditions you're simply asking the stepper to move faster than it is capable of?

Are you suggesting that it's the speed that motor is set to or the speed that I turn the pot. I have slowed the motor speed right down and still get the same problem when I turn the pot quickly.

I have also noticed that the stepper motor doesn't respond to well to the pot movement when the pot starts to move from the "0" position. Feels like its responds between "200 - 1023" Could it be that it's loosing signal in the "0 - 199" range?

scullies: Are you suggesting that it's the speed that motor is set to or the speed that I turn the pot. I have slowed the motor speed right down and still get the same problem when I turn the pot quickly.

I was suggesting that you were asking the motor to accelerate faster than it was capable of.

I think you need to post your code. It's quite possible that you have a design fault in your sketch which is causing this behaviour.

ok, I’m with you now.

here is the sketch, its the same sketch from the “motorknob” just changed the speed and steps. I appreciate your help.

#include <Stepper.h>

#define STEPS 200
#define COIL1 8
#define COIL2 9
#define COIL3 10
#define COIL4 11

#define PotIn 0

// create an instance of the stepper class:
Stepper stepper(STEPS, COIL1, COIL2, COIL3, COIL4);

int pos = 0; //initial position of stepper

void setup()
{
stepper.setSpeed(100); // speed of motor 4 rpm

}

void loop()
{
// get sensor value and adjust range
int val = analogRead(PotIn); //get the potentiometer value (range 0-1023)
val= map(val,0,1023,0,50); // map pot range in the stepper range.

if((val - pos)!= 0){
if((val - pos)> 2){
stepper.step(1);
pos++;
}
if((val - pos)< -2){
stepper.step(-1);
pos–;
}
}
else{
digitalWrite(COIL1,LOW);
digitalWrite(COIL2,LOW);
digitalWrite(COIL3,LOW);
digitalWrite(COIL4,LOW);
}
}

I have set the step speed to 4 now, but still dont get any response from the pot untill it reaches about quarter turn :roll_eyes:

scullies: I have also noticed that the stepper motor doesn't respond to well to the pot movement when the pot starts to move from the "0" position. Feels like its responds between "200 - 1023" Could it be that it's loosing signal in the "0 - 199" range?

Do a Serial.println of the analog input (your 'val' variable), open the serial monitor, and find out.