Arduino recording of events

Hello,

I am still in the process of creating a logic for my program so I cannot provide any code.
I would like to ask for some expert advice on how can this be done.

Problem:
I am working on a project with mechanism that uses several stepper motors and limit switches.
I wonder how you could program Arduino for it to record a sequence of events.

I have different control modes (e.g. FORWARD, REVERSE, RESET et.al)

Example:
In FORWARD:
The sequence should be, and the mechanism should

  1. Touch Limit Switch 1
  2. Touch Limit Switch 3
  3. Touch Limit Switch 4

In REVERSE:
The sequence should do below

  1. Touch Limit Switch 4
  2. Touch Limit Switch 3
  3. Touch Limit Switch 1

In RESET :
The sequence should be, and the mechanism should

  1. Touch Limit Switch 2

There are other control modes but let us just focus on three above.
I am able to move the mechanism to touch the different switches using AccelStepper library.

Now, I need to do the following:

  1. Record the sequence of events and verify that this happens in the desired sequence
  2. If after 10 seconds (timeout) and the desired touching of the limit switches did not happen then sound the alarm ( buzzer)

Challenges:
Stepper motor movement to touch the limit switches takes some time so there will be some waiting time.

My first thought is to create a list of sequence arrays (my pseudocode)

forwardSequenceArray = [1,3,4]
reverseSequenceArray = [4,3,1]
resetSequenceArray = [2]

And for each activation of the control mode, I would record the sequence of events and compare it against the 3 arrays above. I am not sure if this is optimal or if there is a more Arduino savvy way of doing this.

I am still thinking about how to implement a timeout.

Any ideas? I am all ears.

How do you ensure that when power is applied to your Arduino, the first event is NOT between two of your limit switches? Spend some thought relating to "initial conditions".

Save the value of millis() to an "unsigned long" variable when the action is initiated, and later, check whether the difference between that value and the current value of millis() exceeds the timeout period.

That would normally be covered under G code and cnc.

Dronebot Workshop recorded servo movement to SD and played it back.
https://dronebotworkshop.com/sd-card-arduino/#Servo_Motor_Recorder_Playback

Search for information on "Finite State Machine".
There are myriad ways to implement one. But that's the programming idea that does what you want.

Thanks for this. This solves my problem. It is now working as expected.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.