HO Scale Rotary Dump

I have a project I have been kicking around and collecting pieces for but need help putting it all together (mainly the code). I have attached an outline of what I would like to do. Here are my questions/notes:

Here is one in action for reference: - YouTube

Can someone help me put the pieces together? It’s for our model railroad club so not much in the way of spending budget.

Thanks,
Wayne


Is bump needed with steppers?
At initial power, can any motor-being-off drift (is there any drift?) be corrected with an initial power-on, move to zero starting location so the rotary dump always starts in the correct position?

I have read that the stepper doesn’t know its out of position if something moves when the unit is off. The rotary pretty much never moves once its in place so maybe this is a non-issue??

START DUMP CYCLE BUTTON
Determine if out of alignment
Hall or IR sensor for position?
Figure out how to determine which direction to move to get into position

Start stepper motor, run to x position
I need to look at current gear rotation to determine how many steps to fully dumped

Once dumper reaches dump position
Pause for three-five seconds
Start vibration/offset motor to release car load contents
Run for three-four seconds starting when the rotation hits about 85% rotated, keep vibrating until the end of the three-five second rotation pause
Return to zero position

Flashing led circuit?
Option for a flashing orange led circuit to run while the dumper is rotating
Enough to drive up to four led’s

BUMP COUNTER-CLOCKWISE (and CLOCKWISE)
Micro-steps per button push
Holding momentary push button does nothing, only individual presses of the button will move the motor
Determine how micro of steps to make; five, ten, ?? steps per push?
A rotary encoder would probably be better for fine-tuning into position? Zero/center and rotate left/right to align?

A momentary push-button will be mounted to a panel to start the cycle.
I have an Arduino uno R3 and the basic kit stepper motor 28BYJ-48 and ULN2003 motor controller. I purchased a pack of bullet vibration motors. I think one will work but if two are needed can another one be wired in without altering code?

I was thinking about purchasing a NEMA 17 stepper motor, the rotary dump turns pretty easily so I’m not sure we need much more motor than the basic. Open to suggestion.

I have the following code which has the acceleration that looks good in my test so far. Currently its looping, I only need it to run once with the push button.

/*

*/

// - → GND
// + → 5V
// IN1 → D8
// IN2 → D9
// IN3 → D10
// IN4 → D11

// First DEFINE the components of the library we’re going to use for this sketch
// Define #USE_ALB_Stepper to include the Stepper Motor functions of the ArduinoLearningBoard Library
// (Must do this before including ArduinoLearningBoard.h)
#define USE_ALB_Stepper

// NOW include the main ArduinoLearningBoard library
// Based on the defines above, the appropriate modules will be added to the project
#include “ArduinoLearningBoard.h”

#define HALFSTEP 8

// Motor pin definitions
#define motorPin1 8 // IN1 on the ULN2003 driver 1
#define motorPin2 9 // IN2 on the ULN2003 driver 1
#define motorPin3 10 // IN3 on the ULN2003 driver 1
#define motorPin4 11 // IN4 on the ULN2003 driver 1

// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);

void setup() {
Serial.begin(9600);

stepper1.setMaxSpeed(1000.0);
stepper1.setAcceleration(300.0);
stepper1.setSpeed(1000);
stepper1.moveTo(8000);

Serial.println(“Moving Stepper to Position 8000”);
}

void loop() {

// Serial.println(stepper1.currentPosition());

//Change direction when the stepper reaches the target position
if (stepper1.distanceToGo() == 0) {
Serial.print(“Stepper Arrived at Destination. MoveTo(”);
Serial.print(-stepper1.currentPosition());
Serial.println(")");
delay(4000);
stepper1.moveTo(-stepper1.currentPosition());
}
stepper1.run();
}

Rotary Dump Specs.pdf (36 KB)

You can NEVER assume a stepper will always be in position. What if the power goes out halfway the rotation? Or something else happens (something gets stuck in the contraption) that forces you to interrupt it? That's why at start up you always have to search for home.

Of course if you normally stop right at home, you'll see the home switch activated upon startup, and in that case no homing needs to be done.

After that, assuming your stepper is strong enough and your motion is slow/smooth enough to make the movement without missing a step, you can simply count steps to know where you are.

wvmarle: You can NEVER assume a stepper will always be in position. What if the power goes out halfway the rotation? Or something else happens (something gets stuck in the contraption) that forces you to interrupt it? That's why at start up you always have to search for home.

Of course if you normally stop right at home, you'll see the home switch activated upon startup, and in that case no homing needs to be done.

After that, assuming your stepper is strong enough and your motion is slow/smooth enough to make the movement without missing a step, you can simply count steps to know where you are.

wvmarle,

I knew you can never assume with the stepper. What I don't know is if I use a hall sensor for "home" how do I make it search otherwise? For instance, if its 8000 steps from beginning to end and, for the sake of argument, it stops at 4000. Then what? When power is restored, how would I make it step and how it would it know which way to go to get home? I imagine I can make it start searching by stepping 10? 100? steps one way and then the other until it finds home? But then how accurate is a hall sensor? Would I be correct in assuming the hall may activate somewhere around the >100 step mark. Which will then throw off my end rotation.

I've been doing a TON of reading and it seems like I saw somewhere that you can write to the EEPROM. Can you write the steps in case of power loss so it will know it last wrote step 4096 in a clockwise rotation? Then when powered on refer to the last step written and continue on?

We've been running the rotary dump on the layout for about 15 years with micro-switches and relays. Recently some of the wires were cut and we figured we'd move on to new methods with the arduino. That being said, nothing has EVER gotten stuck or bound up in the device so I'm not concerned with that precaution. Power outage would be my only concern, though, same applies in 15 years we've never lost power (knock on wood, that continues). What about a capacitor to hold the memory?

Thanks!

wayne_sw: When power is restored, how would I make it step and how it would it know which way to go to get home? I imagine I can make it start searching by stepping 10? 100? steps one way and then the other until it finds home?

Of course you don't know the direction in this case, so you would just move forward. Take a step, check home signal. Take a step, check home signal. Repeat until you reach home.

But then how accurate is a hall sensor? Would I be correct in assuming the hall may activate somewhere around the >100 step mark. Which will then throw off my end rotation.

That's a matter of placement. A microswitch may work better here.

Ideally you'd have a home switch that is activated just before reaching the horizontal point, and deactivated a little past.

So when you power on, you see the switch is triggered: move backwards until it's just not triggered any more, then move forward the required number of steps and you know you're in position. Is the switch not yet triggered on power on, rotate forward until it is.

I've been doing a TON of reading and it seems like I saw somewhere that you can write to the EEPROM. Can you write the steps in case of power loss so it will know it last wrote step 4096 in a clockwise rotation? Then when powered on refer to the last step written and continue on?

No, for two reasons. First of all, you can't write to EEPROM when the power is down. You would have to add some backup for that. Secondly, when a stepper is powered down, it does not hold position and can easily be rotated manually. So that number stored in EEPROM would be a mere guideline, and you would still have to search for home. That also happens when you simply switch off your railway, or when you move it to another place or so. Then there's the thing that EEPROM has a limited lifetime so writing the position every time you take a step will wear it out very quickly.

If you use the 28BYJ-48 stepper it comes with a worm drive, which helps it keeping position. It also makes it slow, the thing can not do not much more than about 60 rpm, so whatever you operate with it goes even slower.

The problem is solvable using a feedback mechanism. e.g., a potentiometer on the hopper.

cedarlakeinstruments: The problem is solvable using a feedback mechanism. e.g., a potentiometer on the hopper.

This may very well work and it did cross my mind. I know I can program the end points and then just rotate the knob.

I didn't dig very deep for how to control the motion though.. as in; I don't want the speed with which I turn the knob to be reflected on the rotary dump. If I spin the potentiometer quickly to the dump position it still rotates at a slow, scale speed.

OR

Were you suggesting a potentiometer to use as a sensor for the end and beginning points?

Pot coupled directly to the motor or to the hopper. You're controlling position using the pot, so it makes no difference how fast you move the control potentiometer if you keep the motor speed constant.

cedarlakeinstruments: Pot coupled directly to the motor or to the hopper. You're controlling position using the pot, so it makes no difference how fast you move the control potentiometer if you keep the motor speed constant.

But then I lose all automation of it. The goal was push start, watch it turn and dump and return. Is there a way to program it to when it senses its hit the end to automatically roll back to zero?

As much as I should be concerned about losing power and position I'm really not. The dump has been in service in its current capacity for about 18 years and we only run it on our open house weekend, once a year. I'm willing to take the odds we won't lose power that weekend if that makes the project easier to automate.

I somehow do not get the problem. Why not use 2 switches ans a screw for adjustment?

zwieblum: I somehow do not get the problem. Why not use 2 switches ans a screw for adjustment?

I'm not sure I understand what you are referring to? Are you suggesting something like a micro-switch on each end for start and stop? Not sure what the screw adjustment is?

Well, as said, I do not get what the problem is. You turn a wheel from A to B and back, that's all. So adjust switch one for A, switch 2 for B, and you are fine. But that was also pointed out in post #3

Wayne: I watched the video and re-read your question & responses and clearly I misunderstood something, so I'll start over.

Problem statement: you have a motorized rotary dump hopper that you want to move to a dump position and then back up to vertical. At startup, the dump must re-establish its vertical position.

At startup, if the Home limit switch is not active, the control drives the motor in the direction of Home until the switch is detected.

When the DUMP button is pushed, motor moves in opposite direction and stops when the DOWN limit switch is detected, pauses, then returns to Home limit position. You also have some details like flashing lights and vibrator to push material out.

It sounds from your description like that's what you're trying to do and you appear to have all the hardware needed, so could you explain exactly what it is you need help with?

cedarlakeinstruments:
Wayne:
I watched the video and re-read your question & responses and clearly I misunderstood something, so I’ll start over.

Problem statement: you have a motorized rotary dump hopper that you want to move to a dump position and then back up to vertical. At startup, the dump must re-establish its vertical position.

At startup, if the Home limit switch is not active, the control drives the motor in the direction of Home until the switch is detected.

When the DUMP button is pushed, motor moves in opposite direction and stops when the DOWN limit switch is detected, pauses, then returns to Home limit position. You also have some details like flashing lights and vibrator to push material out.

It sounds from your description like that’s what you’re trying to do and you appear to have all the hardware needed, so could you explain exactly what it is you need help with?

Thanks for the re-read. My problem is the code and the suggestion for initial sensor. I can make most all parts work separately but I’m having trouble combining the code and making it all work.

I’m wondering though if just using a potentiometer wouldn’t be simpler in the long run as zwieblum mentioned. I know I can program the stepper to rotate and automatically retract back and I think this would also give me the bump for fine-adjustment.
I can’t wrap my head around what happens if the potentiometer is at zero and I program the stepper to go 8k steps to the end and automatically return. What happens if I bump it negative 100 steps to get into final position and then turn the potentiometer the opposite direction for another cycle, now the final dump will be at a physical net of 7,900 steps right? Though, in reality 100 steps is probably so minimal its likely a nonissue.
It seems like a “home” sensor is pretty much a must so it always knows where to start counting from? I THINK we’d be safe programming the stepper to go 8k and then return without an additional sensor, do you feel its safe to trust the program or better to trust a sensor?

Thanks!
Wayne

The home sensor is needed to find home.

After that you can just count steps - assuming the stepper doesn't stall or otherwise miss steps, you will always come back at the original position with great accuracy. The home switch can of course still be checked, if you're worried about missing steps.

So you'd just move the 8,000 steps forward, then 1,000 steps back and forth a few times (shake the car), and finally the 8,000 steps back to the home position and you'll always be back there.

Normally homing would be very quick and almost unnoticeable. Note that you should look for the point where the switch just makes or breaks contact. Assuming it closes when your contraption reaches home, in setup: If home switch closed: move forward until it opens, then one step back (it should now be closed again, otherwise continue stepping until it does). Now you're home. If home switch open: move backward step by step until it closes. Now you're home.

Usually you will power down your railway with the bridge in home position, so the home sequence can be done in less than a second upon power up. Sometimes you will have it further out, and then it will simply move back up searching for home.

You can use a RC Servo and a RC servotester to get the job done. No arduino in this equation.

I really like the idea of using a servo tester, that does accomplish a lot of my requests. However, not knowing much about them I have a few questions:

  1. Can you control the speed or is it reflective of how fast you turn the knob? If someone cranks the knob I don’t want to throw the load out, it needs to rotate smooth.

  2. How does the vibration motor come in to play? I’m sure I could use microswitch or reed switch to set off the motors at a certain spot.

  3. Can you program the extents in the tester or are you at the mercy of how far you turn the knob?

  4. As simple a device as it is, it really seems like it introduces it’s own set of issues that need attention.

You can get different servo testers, you'll need to look around. On the other hand, you can use the arduino servo library to do the same. In the end it's just about how much time you want to spend on it. And as always the shortcut will turn out to be the longest road.