Automation Project Help

Working on automating a series of actions via an arduino. Not the best at coding and would like to understand what the best way would be to design the sketch to control it.

Inputs

  1. Start Button (MC Switch)
  2. Reverse Button (Toggle Switch
  3. Emergency Stop (MC Switch)
  4. Stepper Speed Control (POT)

Outputs

  1. Relay 1 (Clamp)
  2. Relay 2 (Start applicator)
  3. Stepper Motor

Action

  1. Start button press
  2. Clamp will Actuate
  3. Applicator start a specified time after clamp actuates
  4. Stepper will start a specified time after applicator starts will move a specified a number of steps at a specified speed
  5. Applicator will stop before stepper is finished with its routine.
  6. Clamp will disengage after stepper is finished with a delay.

I'm not worried about having the applicator stop and the clamp unclamp based on the time it takes the stepper to finish its routine (as its time to complete will change with pot speed). I'm assuming that the clamp and applicator could be run based on time from the start button press. Stepper would be a delay and then speed and steps. Start and end positions do not matter.

Would also like to be able to reverse the motor via a switch which could be standard toggle switch. Also an E stop would be nice to stop the process in case something goes wrong.

For me I can understand how to individually control some of the functions in a sketch but the momentary start and E stop are throwing me for a loop. I believe we need to watch the state of the switch during the loop but beyond that I'm not sure what to do. Any help would be appreciated.

Thanks
Ryan

It's a good question, but I would start with something else.

The Arduino has a stepper library : Stepper - Arduino Reference
At Adafruit they have a stepper library for some products.
There is also a library for automatic acceleration: AccelStepper: AccelStepper library for Arduino

You could first try to make the stepper work with a library.
Do you know what the hardware is ?

You could run the loop 50 times or 100 times a second and read the buttons.
You could also use a library with debounce for the buttons.

You already wrote the answer in your question: you need a state machine. That is a variable that identifies the current state. According to the current state the buttons result in certain actions.

To measure time, you could use the millis() function.

If you have not done something like this before, do it step by step, and upload your sketch so we can see how you are doing.

If only everyone else who is new to the Forum could set out their requirements so clearly :slight_smile:

You may find my Reply #6 in this recent thread useful
http://forum.arduino.cc/index.php?topic=207026.msg1523574#msg1523574

...R

I'm using a ebay stepper drive L298H board. I can run the stepper alone without too much difficulty. The state changing based on millis is what I'm having difficulty with. I have started with the standard debounce tutorial and substitute the led setup for the relays. Assuming I can use a "If and"statement to set the relay states based on time since the button push. Really not sure of where to start with the code though to get the millis control.

In contrast to your original post your description is confusing. What was state change got to do with debouncing?

The usual way to use millis() for time control is a bit like this pseudo code

startMillis = millis();

loop() {
  if (millis() - startMills >= theTimeIwant) {
    doSomething;
  }

}

...R