Controlling a hydraulic ram with a arduino

Hello,

I am starting a project to control a hydraulic ram on a machine similar to a hydraulic log splitter.

The user shall press a button and the ram will move out to full stroke and then return to its resting spot. Once back at rest it will wait for the button to be pressed again to perform another cycle.

In terms of hardware I have relays to move the hydraulic solenoid and I have attached limit switches on the ram so it knows when it is at full stroke and rest positions.

This will be my first program that uses multiple button/switches to perform actions.

I am new to coding so I am having problems with how to structure the program, normally I would be reading a sensor and displaying a value on a screen so to have a sequence of button presses is a bit different.

What structure would be best for this type of application, custom functions, switch case, for or while loops??

Make sure that you have adequate emergency stops, and safety guards, if the machine is similar to a log splitter.

Also don't rely on the Arduino for the safety functions, have a proper emergency stop switch that will cut power to the system.

The State Machine structure is the best. Most tutorials online are very poor. State Machine is the best I know of.

It sounds like your Arduino experience is very limited. Work through some of the basic examples before attempting the state machine. Blink an LED. Blink without delay. Debounce a button.

Hi!
From my point of vue....
For safety reasons You should not use a simple button pressed to start a cycle.
Professional hydraulics like this use two buttons well apart from each other and both need to be held down for especially the forward motion. If any of the two buttons are released, action stops.
Using a monostable relay being normally off makes all motion stop in case of lost power or logic.

Thanks for the ideas I think I will add a proper interlock switch on the machine, maybe with a lid so the machine can only operate when it's closed.

Does the Arduino have to do anything else - counting etc?
This problem seems like it would be a lot safer and easier to implement with pure hydraulics.

Yes, lastchancename, You probably solved the "colombi egg". Creating smart things using microcontrollers is really fascianating but regarding safety You are right. I would say: Use one button controlling the hydraulic pump and one lever handling the forward/backward movement.
This arrangement I think was used in a 5 ton wood splitter I operated some 13 years ago.

You could even implement the direction change valve as a mechanical function of reaching the two endpoints.- a hydraulic oscillator!

Why not use a bidirectional hydraulic valve? Nop when not operated, forward for splitting and backward for retracting?
The safety button starts the hydraulic pump and the lever decides about forward or backward? That sounds safe to me. Even the retract movement might be hasardeous for a human hand being in the wrong place depending on the mechanical design.