Limit switch control for double acting cyclinder

I have a protect in which I need to control the end position of a pneumatic double acting cylinder for a certain number of cycles. At the moment I have a program which uses 2 switches (1 for each direction are pushed the cylinder will either go in or out.

So essentially I need a counting loop which when a switch is pushed turns off a relay. Do a need o use interrupts for this.

Any help would be much appreciated

i doubt it needs to be that fast (within usec).

do each limit switch cause the motion to reverse?

debouncing the switch with a simple delay and counting should be simple

Hello Ruddock984

Welcome to the worldbest Arduino forum ever.

Post your sketch, well formated, with well-tempered comments and in so called
code tags "< code >" and schematic to see how we can help.

Have a nice day and enjoy coding in C++.

Let's give the description another shot so I'm sure I got it.

You want to cycle an air cylinder from retracted to extended a certain number of times.
And you want to start that cycling by activating a switch.

Will you need to adjust the number of cycles, or the time per cycle?
Will you ever need to stop the cylinder in the middle of these cycles?

All of this assumes that you have your pneumatic system, solenoid valves, etc. already working. Right?

yes, i want to cycle cylinder number of times

it will start by activating a switch
cylinder will have a wait time at each point when limit switch is triggered
system all works

The basic behavior will be:
Wait in a loop while the activation switch is inactive (reading its input continuously)

Then activate output to extend the air cylinder
Wait in a loop until extension limit is activated
Delay extension time
Deactivate output to retract the cylinder
Wait in a loop until retracted limit is activated
Delay retraction time

Repeat the above block for the desired number of times.

There are some error checks I may add for cases where something goes wrong, but that logical structure I outlined will be fine for 99.99% of cases.

so just count the # of debounced limit switch events

How do i wait in a loop for an input to go high. Do you have an example

Srsly? Try

    while (digitalRead(somePin) == LOW)
       ;

which will do nothing until the pin goes high.

Of course nothing else will happen whilst you are waiting, so don't do that if you aren't sure you wouldn't end up waiting forever.

HTH

a7

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