Stepper Motor Control

Hey there,

Im trying to control a stepper motor using an Arduino Uno and Cytron SD02B stepper motor controller. The control is based off of an analog signal from a water pressure sensor that is sent to an analog input on the Arduino.

The stepper motor is coupled to a main valve to open and close it and control water flow as well as pressure. The pressure sensor receives a water pressure depending on the flow of water through the system. Id like the Arduino and stepper motor controller to maintain a constant output from the pressure sensor. Therefore, if water flow and pressure increase, the output of the pressure sensor increases and the stepper motor closes the valve to return the output of the pressure sensor to the desired number. If the water flow and pressure decrease, the output of the pressure sensor decreases and the stepper motor opens the valve to return the output of the pressure sensor to the desired number.

The reason for this system is to simulate a cruise control type of system for an outboard motor. If I can get this program to work, all I have to do is grab a water pressure signal from the lake and connect the stepper motor to the throttle in the outboard motor.

Any help would be greatly appreciated!

Thanks everyone.

before anyone posts links on how to use a stepper,

think about what you are trying to do.

if you are trying to create a cruse control, then you need two loops.

one would be independent, the varying speed if you will
the other is the motor control

lay our a schematic.

simulator pump. manual or automatic valve for you. second automatic valve for the stepper control.

you change conditions as you want. your desired control has to compensate.

I really think you need to think about your test setup (application)

it sounds like you have the stepper bits worked out as they are easy enough.

if you have a pump that you can manually vary water speed past your sensor, you need to control something.

just changing the pump to control water speed will only bring the speed back to what your sensor is set for, not adjust anything for varying water speeds. in other words, you would be designing for one sweet spot.

more thought or more information on your test rig will help.

the project is not hard.
your goal is to make sure your stepper (cruse control) can be manually disengaged at an instant, but be strong enough to be in control. the stepper will need to be totally out of the loop under manual. MECHANICALLY,

thinking more about this. your speed control on the boat will have one set of mechanical characteristics. these will be different than on any test rig you make.

the problem is that you will fine tune control of a pump or valve, but on the actual boat the tuning will be different.

sooner or later, you will need to understand hysteresis.

if you are moving at 6 knots, do not expect to alter the throttle at 6.001 or at 5.9999, you will need some dead band.

since your control appears to be a linear movement of a mechanical device (throttle arm) you could use a simple fuzzy logic control.

if water speed is more than 1 knot from setpoint, move fast
if water speed is less than 1 and more than 1/4 knot, them move slow
if water speed is less than 1/4 knot from setpoint, do nothing. this is your dead-band.

you could add a third, move very slow..... if needed.

Thanks so much for the replies.

Above is a picture of my setup. A standard tap or garden hose will be used to send water through the piping. Main control of water flow through the piping comes from manual opening or closing the tap by hand. Opening the tap increases water flow and pressure read by the sensor. The program will hopefully be able to detect this and tell the stepper motor to close the main valve to keep the output of the pressure sensor at the desired value. The process is the same when the tap is closed only the stepper motor will open the valve.

Youre right about the tuning Dave, thats a good point. Im hoping to demonstrate that the program can work before I install it on a boat and fine tune it for that purpose.

I hope this additional information helps you understand my dilemma.

just to keep posting......

if water_speed - setpoint > 1 knot
integral = integral + 10
if setpoint - water_speed > 1 knot
integral = integral - 10

if water_speed - setpoint < 1 knot && > 0.25 knot
integral = integral + 1
if setpoint - water_speed < 1 knot && > 0.25 knot
integral = integral - 1
// this will be 10 times slower

if integral > 20000
step output 1 step // output to stepper motor driver
integral = 0

since the program loop will run really fast, this will pass 20,000 quickly.
then you output 1 step. this could be very fast.

======================

in chop, this will add and subtract to keep 'integral' from changing fast.

to test, you could add delay() in the program to slow things down.

mdn91:

Thanks so much for the replies.

Above is a picture of my setup. A standard tap or garden hose will be used to send water through the piping. Main control of water flow through the piping comes from manual opening or closing the tap by hand. Opening the tap increases water flow and pressure read by the sensor. The program will hopefully be able to detect this and tell the stepper motor to close the main valve to keep the output of the pressure sensor at the desired value. The process is the same when the tap is closed only the stepper motor will open the valve.

Youre right about the tuning Dave, thats a good point. Im hoping to demonstrate that the program can work before I install it on a boat and fine tune it for that purpose.

I hope this additional information helps you understand my dilemma.

sweet set-up !

I posted a super simple type of fuzzy logic I used to use on PLC's to gain control when PID was not working.

the final device is often a huge problem and this would reveal what was working and what was not.

looking at your setup, I think you got it.

that asks the question of what help you need ?

dave-in-nj:
just to keep posting......

if water_speed - setpoint > 1 knot
integral = integral + 10
if setpoint - water_speed > 1 knot
integral = integral - 10

if water_speed - setpoint < 1 knot && > 0.25 knot
integral = integral + 1
if setpoint - water_speed < 1 knot && > 0.25 knot
integral = integral - 1
// this will be 10 times slower

if integral > 20000
step output 1 step // output to stepper motor driver
integral = 0

since the program loop will run really fast, this will pass 20,000 quickly.
then you output 1 step. this could be very fast.

======================

in chop, this will add and subtract to keep 'integral' from changing fast.

to test, you could add delay() in the program to slow things down.

The problem Im facing is that Im an Electrical Engineering Technology student and Ive had no issues constructing the simulation, but I have little to no experience with programming. All of this code is foreign to me and Im trying to understand it.

The code you replied with makes sense to me, I just insert that into an Arduino document and it will understand? In that case, is the stepper motor controller even necessary?

what I posted was an idea. not actual code.

the stepper DRIVER handles the power. it is needed.

also, I am not familiar with your driver, you need to find some code for it that you can modify.

all sketches for the arduino have 3 sections.

the first is un-named 'declare' section and where you assign names to pins and variables

the second is the voidsetup() where the program assigns what a name does

the voidloop() is where all the magic happens.

for your test, I would add a few switches and LED's.

a pause switch could be useful.
LED to flash with each overflow in iterations.
a switch to allow delay() to be used,
possibly a pot to alter the values in real time.
two buttons, one to move stepper forward, one to move it backwards.

I would suggest you try to move the motor forward 200 steps, then back 200 steps.

once you run some LED's to blink and such, things will make a LOT more sense.

just to be annoying....

putting an elbo before the sensor will cause more turbulent flow than if the pipe was straight

looks like you have 10 straight runs, but without knowing the Reynolds number, the flow past the sensor could be more turbulent than what you find on the boat.

no effect on the project or the test stand, but noting the observation

You may find some useful stuff in stepper motor basics and this simple stepper code

...R

Robin2:
You nay find some useful stuff in stepper motor basics and this simple stepper code

...R

the OP said he has a Cytron SD02B stepper motor controller

does your code work with that ?

mdn91:
Hey there,

Im trying to control a stepper motor using an Arduino Uno and Cytron SD02B stepper motor controller.

I would stay away from robot shop, they have no clue what they are selling.
they label a simple DRIVER as a CONTROLLER
that is like saying your resistor is a 100uF for 5 watts
or your capacitor is DPDT and has a 5v coil......
pure nonsense.
hate to say it, but a 1 amp DRIVER should not cost over $10.00
the fact that it takes a UART input, does put it in a different class.
unfortunately, this is not common, most drivers we use have a step and direction control.
on the other hand, it looks like this board has a pulse and a dir, so, that would be step and direction....
the manufacturer calls it a DRIVER, so the robot shop changed the words. anyone that does not know what they are offering is really wasting other peoples time and effort.
you have it, it should work. I am just not happy with people who don't have a clue.

dave-in-nj:
the OP said he has a Cytron SD02B stepper motor controller
does your code work with that ?

I have not seen a link to the datasheet, so I don't know.

If it takes normal take step and direction signals it should work.

...R

Robin2:
I have not seen a link to the datasheet, so I don't know.

If it takes normal take step and direction signals it should work.

...R

the photo shows he is using it on pins D0 and D1
and the DRIVER board (not a controller) takes a serial command
best I can figure, it also takes step and direction ,but the manual is wanting.
not sure if it is based on pulse for step and then UART for everything else.
https://docs.google.com/document/d/1E5idr2dDcRnOk2wbNgWdmgsSLmUR1YYPfWoOduPjYNA/view

.

Dave, thanks for the link (but, really, the OP should have provided it)

Section 5.2 of the document says it can take ordinary step and direction inputs - that would be compatible with my code examples. And with the AccelStepper library.

Section 5.4 gives details of alternative serial input. I can't immediately think of any reason to use that because it is not compatible with the usual way Arduinos control steppers.

...R

Thanks for the replies Robin and Dave. I should have posted the documentation, my apologies. I'll check out the links you posted. I appreciate it.

I could be wrong here but for a closed loop the stepper motor shouldn't be in the sensor loop. The stepper motor should be the throttle control. It should not be able to directly effect the pressure sensed. It should only control the throttle. As pressure sensed decreases below setpoint the stepper motor should increase throttle and vice versa.
I don't see the stepper controlling the throttle. What am I missing ?