Hay baler control panel

I am new to the programming world and am trying to program a control panel for a hay baler. The original panel that is 20-25 years old quit working and I figured I would play with creating a panel instead of paying a huge amount of money to hunt one down. The system is relatively simple with a series of mag proximity switches and hydraulic solenoid valves. I have figured out how to trigger alarms with the mag switches but I am struggling with how to create a multi step program to run the baler automatically. I am currently able to run the baler in manual using a series of switches.
The control scheme of the baler needs to follow basically the following steps:

No alarms, push momentary switch (Start Button) to start baler(energize clutch solenoid), push again to stop (denergize clutch solenoid.) If certain alarms are tripped the baler stops (deenergize clutch solenoid.)

To complete the bale wrapping and ejection (Auto Cycle) process the following steps need to be taken:

  1. Push second momentary (Auto Cycle) switch to trigger the process of wrapping bale - energize twine arm solenoid
  2. Twine arm position switch closes - deenergize twine arm solenoid
  3. Twine arm home switch closes - deenergize clutch solenoid, energize gate open solenoid
  4. Gate open switch closes - deenergize gate open solenoid, energize ejector solenoid
  5. Ejector out switch closes - energize gate down solenoid
  6. Gate down switch closes - deenergize gate down solenoid, deenergize ejector solenoid

Push Start button to continue baling.

If there is some code out there for something similar (I'm sure there is) that I could repurpose it would be awesome. Hopefully I havent bitten off more than I can chew!

You need to expand on what you have written to declare the exact amount if time for each step to use in the total operational cycle. I am sure you done want all your steps to take place in a fraction of a second.
Paul

they are not timed steps, they are triggered by the switches.

So it would be continuous until the switch is triggered.

Others can help you with the code. I will suggest you pay attention to the physical installation.

Protect EVERY input and output with capacitors and for high voltage (ie above 5V or 3.3V depending on your board) you will need resistor dividers and zener diodes.

I'm assuming a hay bayer (at least the last one I was) had an electrical system as electrically noisy as an automobile.
Physical wiring is important. All wires should come to the board hosing as a single group, be filtered then connect to the board.

Oh and enable the WDT for your board.

Good luck

I have a relay board for the 12 v outputs. Most of the proximity switches are either open or closed so they either complete the circuit or not. There are two inductive proximity swithes that are used as tachometers to compare the input and output speed of the clutch drive. I would like to set that up as a safety at somepoint but for now I just want to focus on the auto cycle.

I'm not clear about what you're asking. It seems to me that the hard part would be
getting the hardware together. Once you have it wired with an input pin from each of the switches and an output pin to each syllanoid, you just follow the pseudocode you gave in the question. To give a little more detail, each step would be something like this

 int  time_limit = <maximum time this might take>;
while ( <switch not in target position>) {
   time_limit = time_limit - 1;
  if (time_limit <= 0) {
     <Something went wrong: abort and signal an error>;
    }
}
<engage or disengage the sylanoid>

Any detail beyond this would depend on the hardware and how you have it wired.

The baler would gather hay until there is enough.

Some sensor would trip saying the bale is ready to get wrapped.

I assume you have the tying process?

The bale is ejected
Sensor detects bale has been ejected.

Hay is gathered for new bale.

Go to start

Is that about the gist of the process?

More or less, yes. there are multiple steps in the process as outlined above, with each step having a trigger (proximity switch.)

It is usually harder to try and code a complete system in one go. Experienced programmers tend to write a new system in small pieces, testing as they go.

Obviously that's tricky or indeed not feasible with your baler, but I suggest that you make a baling simulator with switches for your sensors and LEDs to represent solenoids.