This example will demonstrate how to automate a (simplified) hydraulic press using the Moore machine structure. A Moore machine is suitable for batch processes, while a Mealy machine is suitable for continuous processes or the ones with a lot of manual intervention from an operator.
In part one of this article we touched on a bit of history of Industrial Automation looking at the Universal Touring Machine and the Mealy and Moore machines as two more practical descendants from the theory. If you are arriving late to the party, here’s the link to catch up.
An example
A hydraulic press is used in a production process of the terminals for electrical motors. A two part mould tool is installed in the press and heated. The process begins with the press being fully opened, followed by pouring granule powder into the mould and applying the brass contacts. After that, the operator activates a two-hand control to close the press.
Once the press reaches a pre-set height value, the closing process is switched from fast to slow, closing and entering the pressure build up phase. The pressure is maintained for a set time by increasing the pressure when material melts and gives way or a chemical reaction starts and expands the product. The pressure should then be slightly released to maintain it within the tolerance band.

Fig. 5 – A hydraulic press used in a production of motor terminals for ATEX rated motors.
The press and the process are significantly simplified for the purpose of this example. The example only describes the automation mode and does not include an emergency stop functionality, manual nor service modes of operation. Significantly simplified hydraulic diagrams are used to further explain the example.
A layout diagram
Let’s have a look at the simplified layout diagram of our press first. It is shown in figure 6. To get an idea, a photo of a similar press is shown here as well.
The bottom heating plate is fixed to the frame and does not move. The upper heating plate is attached to three hydraulic cylinders and can travel the length of a cylinder stroke. The C2 is the main cylinder and is able to apply high pressure to the product. A pair of cylinders labelled C1 are working in parallel and provide a force for a quick move of the upper plate. A quick move is possible due to the small diameter of the cylinders. They also provide the force to open the press with their two-way functionality, something the C1 is not able to do, due to its plunger design.
Fig. 6 – A simplified layout configuration of the press and a photo of one.
A hydraulic diagram
Simplified, but sufficient for our example, a corresponding hydraulic scheme is shown in figure 7. For the press in our example and the one shown in the photo, a one size hydraulic pump should probably be sufficient. However, we will use a more luxury approach here. Two pumps driven by two electrical motors will be used to offer a more interesting example and to learn a bit more about automating the device. Besides, the press from our example exists only in a virtual space and we don’t need any extra money from the budget, not even bitcoins, to use an additional pump. The project budget is safe!
Two hydraulic circuits were designed to perform basic functionality of the press. They have been stripped of all safety valves, indicators and other common elements used on hydraulic units to purely focus on basic functionality and automation. Hence the non-return valve shown in the drawings is not even labelled.

Fig. 7 – Two hydraulic circuit diagrams of a simplified press from our example.
The circuit shown on the left side is used to open and fast close the press by activating V2 or V1 and motor M1, of course. While the circuit shown on the right is used to apply the force required by the process to form a product. Force is applied by switching on the motor M2, while the valve V3 is used to release the pressure from the cylinder (and the mould) allowing the press to open.
We are going to use two analogue sensors in our example to detect physical values. One measuring the pressure (p) in the cylinder C2 and the other measuring the distance between plates (h). The distance measuring sensor is clearly seen on the photography on Figure 6 connected between the upper heating plate (black) and the frame plate (beige) in the left far corner. A closer look at the potentiometric distance measuring sensor is shown in figure 8.

Fig. 8 – A potentiometric principle sensor measuring the distance between plates.
Definition of states
Thus far we have looked at the basic functionality of the device that will be used to automate the process of manufacturing the motor terminals. The next step is to link the individual functions into one automatic process. As already mentioned in the preface, we will use the Moore machine for the job.
The Moore machine uses states as a basis for operation and in our example, we will get through using only eight states to describe all possible operations. The states are listed and explained in table 1.

Table 1 – States of the manufacturing process used to design the automation function of the press.
These states will be realised in the PLC’s memory using memory flags or data bits. Inputs, both digital and analogue, and internal calculations of set time, will be used as transition signals. They will be triggers for our Moore machine to change states.
When designing the machine a consistent notification should be used both in the documentation and later in the program comments and symbols. The states are labelled using the capital letter S and a sequential number, shown in red on the diagram. State names are printed inside the state symbol, which in our case is a green rectangular box.
An initial state
We should differentiate between two initial states, first is an internal PLC’s initial state that is entered after the PLC’s warm or cold restart and health check of the connected equipment has been carried out and proven successful. The other state is the process’ initial state and it is technology related. The latter should be designed in the machine diagram and coded in the PLC program.
It is often necessary to execute a certain sequence of steps before the initial state can be reached. In our hydraulic press example, a sequence to start the mould heating elements and waiting until they reach the set temperature might be an example of such an auxiliary sequence.
Typically a button will be configured on the HMI or SCADA screen to launch the procedure to put the device into its initial state once the conditions are met.
Tip: Always use the positive edge command to enter the automatic mode, thus preventing the device from being accidentally started.
An essential precondition to enter an Automatic Mode in our example will be a fully opened press. This status will be checked using a mechanical limit switch installed and wired to the PLC’s digital input. This signal will indicate the press is fully open, when TRUE.
Tip: The same switch can be used to reset or calibrate the distance measuring sensor (h) located on the side of the press which measures the distance between the lower and upper heating plate.
Transitions between states
The next chapter on our journey to automate the device is the definition of conditions used to trigger transitions from one state into another.
Transitions are labelled with the capital letter T and a consequential number. The position of the label in the diagram is where the transition arrow leaves the state box or halfway down the arrow (whichever is more appropriate and causes less ambiguity when reading the diagram). Long transition arrows will typically have the transition condition close to the starting point, while short transition arrows will have the condition printed half way along the arrow.
Table 2 gives a short description of transitions used in our example. Each transition has a condition listed in the second column showing when it is TRUE. This is the trigger to execute the state change in the PLC.
The easiest way to understand the transitions shown here is to study them in relation to the machine diagram shown in figure 9.

Table 2 – Transitional conditions used in the Moore machine of our example are explained here.
The conditions T11 and T12 are equal to T4 as the machine can be in any of the states used to maintain the pressure (S4, S5 or S6) when the timer expires. Hence the condition to progress from any of the states to state S7 is the same.
Outputs assigned to states
Following the definition of the Moore machine, where outputs are energised in every state, we will now define which output is energised (TRUE) in which state. There are five outputs in our example, three valves and two motors.
As soon as the machine enters a particular state, the relevant output(s) are switched on, and as soon as the machine leaves that state the output(s) are switched off.
Our press is idle in two states, once when fully opened (S1) and once when closed and pressurised (S4). Table 3 shows an empty row as a result of that, while other boxes are filled as required by the process to achieve the desired functionality.

Table 3 – Outputs of the PLC at every state of the process.
The empty box represents an assigned output being switched off, while TRUE in the box represents the output is switched on. As long as the process stays in that particular state the specified output remains switched on. That being said, it appears logical to use an Assign Coil command in the PLC program when coding outputs, rather than Set and Reset commands.
Graphical representation
The graphical representation of our process and the Moore machine is shown in figure 9. Transitions between states are represented by an arrow and the transition is only executed in the direction of that arrow. If the transition is possible in both directions, a second arrow (with the second condition) should be used, pointing in the reverse direction.
After the press is ready to operate in the automatic mode, and the mode is selected, the state S1 is set in the PLC’s memory using a flag or a data bit. The automatic cycle will begin once the operator issues the close command by pressing the two-hand controls. The transition condition T1 will be TRUE and, consequentially the PLC will then set S2 and reset S1.
Tip: Always use two previous steps as a condition to set the next state to assure proper operation when programming the machine manually. To set S4, check S3 to be TRUE and S2 to be FALSE.
A separate two page document is available containing a more detailed description of the diagram shown here. Please indicate your interest in the comment section below or get in touch. I am happy to send it over to you!

Fig. 9 – The Moore machine diagram for our press.
To design more complex automation functions, two methods of dividing the path and a further two for reuniting the path are a common practice among PLC programmers. None of the four methods will be used in our example – they are mentioned here just to give a complete picture of the Moore machine.
Implementation
Once we have completed the design work up to this stage, only now we should sit in front of the computer and click the “Project / New” command from a menu! Without some structure in the program and proper preparation for coding the PLC, including functionalities omitted in our simplified example, one is heading for a disaster! If not during the office design time then definitely later on during commissioning and the first-run phase. Not to mention potential issues during maintenance or later upgrades of the device or the PLC code, when using a ‘spaghetti’ structure.
The structure in the program allows any PLC literate engineer to read and follow (upgrade) the code as long the documentation (the Moore machine diagram) is available. Thus use of the structure eliminates the need to keep a record of the identity of the author of the code used in the device for that particular project. In addition, it allows a company knowledge base to be built up with every successful project!

Fig. 10 – Time to create the project now!
Let’s now discuss the last bit of the project and talk a little bit about coding, testing and the first-run. The idea is to group different functionalists of a PLC code in separate blocks with an accurate definition of cross-reference signals. Controlling the execution of an individual block (a CALL command) gives us the option to test the device in separate blocks rather than all in one go! Once we’ve performed a standard IO test on site and we are sure from a separate test that the Moore machine is working properly, we can join the parts, and let the device run in real life.
Tip: Use one block for analogue and digital signal conditioning (FC1), a different block for manual operations (FC2) and another one for the Moore machine (FC3). Combine calculations from all blocks into one block dedicated to the output register in the PLC (FC4). Blocking a call of this block in the main program routine will prevent any action from the PLC in the output register and you will have plenty of time to investigate the events in the real work environment that will otherwise very quickly be realised.
OB1:
CALL FC1 //Signal conditioning
CALL FC2 //Manual mode
CALL FC3 //Automatic mode
//CALL FC4 //Outputs
CALL FC5 //HMI
Don’t forget to update the project directory on the server with your local copy of the PLC code once the device is running as expected. 😉
Conclusion
This is an example of an approach to automate the process and code the PLC program in a structured way. Further benefits to those mentioned above are:
- clearly defined functionality of the code;
- building a company’s knowledge base;
- reduced time for first-run and process start-up and;
- author independent code
The additional benefits of such an approach are also an easy way to discuss the code with non-technical people working on the project. This will lead to a better understanding of user requirements through a verification process. A user will have no difficulty understanding the detailed functionality of the device even without being familiar with PLC code.
All this should take place in an early stage of a project to ensure there is no doubt over what the end product should look like. Clear thoughts in the functional design specifications will lead to effective engineering hours without lost time working on functionalities no one needs. Good communication in that stage of the project will improve the relationship between a client and a device manufacturer, which in turn will increase the chances of a successful handover process on the first attempt.
Implementing a structure in the PLC program allows every party involved to fully understand the big picture and automatically encourages them to invest extra effort to make the project a success! We all know that a successful project is a basis for the next order.
—
Please comment on the article, tell us what approach you use, how you approach a new project, or get in touch if you have any questions. If you believe there is something missing, please do let us know!
Also feel free to share the article among your network! A more detailed and bespoke example based on your devices might be prepared for your team.


Fig. 1 – Automatic Machines showed with circles representing states and arrows representing transitions between states. Mealy Machine left and Moore Machine right.

