Stepper motor carousel

Hi guys,
In my project I need to get sample from water source every set amount of time. I printed myself carousel circle with holes for plastic tubes (on pic.). For driving this carousel I have Arduino mega, standart NEMA 17 motor and A4988 driver. The problem is, I can't make it move precisely so it will align with tube from which water is pumped into plastic tubes. It always goes OK and after 3-4 move it will start lossing it's center and eventually tube is in between tubes and everything spills over. Do you have any suggestions how can I fix this? Thanks.

Carousel

Put a small magnet at each tube location and have a hall effect sensor sense the magnet to precisely align the spout with the tube.

Or use an optical reflective sensor to sense a reflective strip at each tube location.

The idea is to add positional feedback so the controller knows the location of each tube.

groundFungus:
Put a small magnet at each tube location and have a hall effect sensor sense the magnet to precisely align the spout with the tube.

Or use an optical reflective sensor to sense a reflective strip at each tube location.

The idea is to add positional feedback so the controller knows the location of each tube.

I have IR sensor available but the thing is I don't know how to programme to make it work. If I use if statement to stop stepper motor and sensor detect's nearby tube it will always stay "true" for stopping motor and never let it move another turn.

It sounds as if the centres of the tubs are not an exact number steps apart. That means the water spout will gradually drift out of alignment, though I am surprised it drifts in 3-4 moves. I am guessing that you are making a fixed number of steps between each tub.

The idea from @groundFungus is a good one. You could use magnets micro-switches, anything to say things are in alignment.

To get to the root of the problem you could make a sketch that lets you drive the stepper manually and counts the steps between centers. Then instead of making a fixed amount of steps between every tub you might vary the stepping so that say every second or third pot you take one more or one less step.

Presumably you already have some kind of signal when the program starts so that it can rotate the table ready to use the first pot?

Mount a break beam photo sensor to detect the containers as they pass - so it can 'see' the gaps. Make the mounting adjustable for back and forth.

A short state machine (switch/case) could do this easily.

  • sensor blocked, nothing happens, state = 'n', waiting for state to change
  • initiate cycle by setting state variable to 'n+1'
  • state 'n+1' runs motor until sensor clears, set next state, 'n+2'
  • 'n+2' runs motor 'til sensor blocked, stop motor, set state to 'n'
    Or, something as simple as: sensor is blocked. Signal sets bool which starts motor. Sensor clears. When sensor becomes blocked, reset bool which runs motor.

If I use if statement to stop stepper motor and sensor detect's nearby tube it will always stay "true" for stopping motor

Move the carousel till it is on a mark (true), fill tube, move the carousel a few steps regardless of the mark or not (to get the sensor away from the mark [false]), then move the carousel while watching for the next mark to be true.

Describe the rest of your mechanical setup. Is the stepper directly attached to the table or is there some other intermediate device?

Paul

something like @dougp - drive away from the stop signal then enable the stop sensor - a timer or drive the stepper a number of steps then enable the stop sensor again - common to have slippage in mechanical systems and with stepper motors - - also best practices to not rely on a fixed number of steps - prudent design says check position

Or you could go wild and put an absolute encoder on the table then after calibration it would also repeat

I think you must have a fault or bug somewhere.
You have not said if your carousel rotates too far or too little. If it is going too far you are probably just taking too many steps. If it is stepping too little then you could be taking too few steps. However your stepper motor might be undersized and could be skipping steps. As @Paul_HD7HB asked how is the motor connected to the carousel, perhaps there is slippage in the mechanism, how far does the carousel rotate per step. Another possibility is that you are trying to start and stop the carousel too quickly. Mechanical parts need to be accelerated and decelerated they cannot start and stop instantly. Try stepping the carousel slowly, does it still get out of alignment.

ardly:
I think you must have a fault or bug somewhere.
You have not said if your carousel rotates too far or too little. If it is going too far you are probably just taking too many steps. If it is stepping too little then you could be taking too few steps. However your stepper motor might be undersized and could be skipping steps. As @Paul_HD7HB asked how is the motor connected to the carousel, perhaps there is slippage in the mechanism, how far does the carousel rotate per step. Another possibility is that you are trying to start and stop the carousel too quickly. Mechanical parts need to be accelerated and decelerated they cannot start and stop instantly. Try stepping the carousel slowly, does it still get out of alignment.

I want to thank everybody for their suggestions. Maybe the problem is really in making too many steps.
I followed: How To Control Stepper Motor with A4988 Driver and Arduino ... And even when I set everything as described it won't make 360° but something like 180° ... I need something like 500-800 stpes, depending on microseconds delay... and I think it'S not faul of stepper motor because manufacture list says angle error +- 0.1 degree

Dragonsired1:
I want to thank everybody for their suggestions. Maybe the problem is really in making too many steps.
I followed: http://howtomechatronics.com/tutorials/arduino/how-to-control-stepper-motor-with-a4988-driver-and-arduino/ … And even when I set everything as described it won’t make 360° but something like 180° … I need something like 500-800 stpes, depending on microseconds delay… and I think it’S not faul of stepper motor because manufacture list says angle error ± 0.1 degree

So change the program! You still have not revealed the mechanical design of the machine.

Paul

Dragonsired1:
… And even when I set everything as described it won’t make 360° but something like 180° …

So how is the motor connected to the carousel?
Post your code as well and don;t forget to use the code tags </>

ardly:
So how is the motor connected to the carousel?
Post your code as well and don;t forget to use the code tags </>

After holidays I had some time try to spin my carousel again and to my surprise it won’t work for good half an hour and than it started to make terrible noise. I have link to video where you can hear what sound it makes. video
I have A4988 Stepper Motor Driver like here driver. I have standart NEMA17 stepper motor with 2A and 2B coils. I have all wire as described in datasheet wiring, except DIR which is set permanently LOW.

Void setup() {

  pinMode(4,OUTPUT); 
}
void loop() {
  digitalWrite(4,HIGH); 
  
for(int x = 0; x < 200; x++) 
{
    digitalWrite(4,HIGH); 
    delayMicroseconds(500); 
    digitalWrite(4,LOW); 
    delayMicroseconds(500); 
  }
  delay(1000);
}

Sounds and looks like it's simply stuck.

wvmarle:
Sounds and looks like it’s simply stuck.

I can spin it freely without any problems. Also if I disconnect wire for stepping it turns ?randomly? so I think that’s not the case.

I would reduce the steps per second. The motor may not be able to go right to 1000 steps per second without acceleration. Increase the microsecond delay to 10000 just to see If it helps. And move it further.

Note that the STEP and DIR pins are not pulled to any particular voltage internally, so you should not leave either of these pins floating in your application. If you just want rotation in a single direction, you can tie DIR directly to VCC or GND.

Have you got anything connected to DIR?

Presumably there is nothing connected to MS1, MS2 & MS3 so that the full stepping is used?

How does the stepper motor physically connect to the carousel e.g. is there a drive belt or gears and if so what is the ratio of motor turns to carousel turns?

I agree with @groundFungus about not stepping too fast.

I would reduce the steps per second.

I did and it rotates but it's very laggy. video

Have you got anything connected to DIR?

GND

Presumably there is nothing connected to MS1, MS2 & MS3 so that the full stepping is used?

Yes. They should be in default LOW state so full step.

e.g. is there a drive belt or gears and if so what is the ratio of motor turns to carousel turns?

There are no gears or anything else. The carousel is directly fit on shaft.

That shaking looks like the motor taking steps, but having problems making it a nice and smooth step due to the disk’s inertia.

wvmarle:
That shaking looks like the motor taking steps, but having problems making it a nice and smooth step due to the disk's inertia.

The funny thing is, it worked like month ago. Without any problems it spun like hell. Unfortunately I don't have a footage of it. For me now is question, what happened? wiring is the same, power source is the same, arduino is the same, code is the same.