Loading local progress…
PLC Gym
PLC Gym homeLevel 1, 0 XP · your progress
Mission 48 · PRO (needs Pro)

Write your first state machine: PLC exercise

Use a numbered state to start, finish and reset a mixing job.

Run a mixing job with a CASE statement. State is a whole number (a ) that says which state the job is in: 0 Idle, 10 Running or 50 Complete. Start moves Idle to Running. MixDone moves Running to Complete. Reset moves Complete back to Idle. Change State at most once per , one pass through your code. Every state sets all four .

This mission is part of ProCreate a free account: every account gets a free Pro trial until 5 December.

No card. Nothing to pay. Nothing to cancel.

Official release: 5 December. Top the leaderboard on the day and win 3 months of Pro, plus 2 weeks of Pro to give a friend. 2nd place wins 4 weeks. 3rd place wins 2 weeks. Rules

  • Every Coaching lesson, from zero
  • Every mission and lesson, as you level up
  • A practical test for every title, with a certificate
  • Rewind any test, one scan at a time
  • Worked solutions when you're stuck
  • The code converter, as much as you like
The 3D process tank this mission runs onPRO (needs Pro) mission
How the test runs

Start, complete and reset

Test 1 of 5
Set by the testChecked by the testStep 9 of 9 · 460 ms
Level
Applied
Time
About 12 min
Reward
+250 XP
Rig
3D process tank
Siemens editors
SCL
Rockwell editors
Structured Text
Beckhoff editors
Structured Text
Stage
16. Write phases in text
Required behaviour

Write your first state machine: what your code must do

This is the first of three missions on the same mixing job. MixDone is the mixer’s done signal. It comes on after four seconds of mixing. The operating rules below list each state and what every output must be. The first move is written for you. There is no Stop or Hold yet. The next two missions add them.

0 · Idle
All outputs OFF. Start → 10. Other inputs do nothing.
10 · Running
PumpOn, ValveCmd and MixerOn ON. Done OFF. MixDone → 50. Other inputs do nothing.
50 · Complete
Pump, valve and mixer OFF. Done ON, and it stays ON after MixDone goes OFF. Reset → 0. It must not also start in that same scan. Other inputs do nothing.
Scan rules
State starts at 0. Change State at most once per scan. On the scan where State changes, the outputs may match the old state or the new one, as a full set. From the next scan, they must match the current state.
Tag table

Write your first state machine: inputs and outputs

Your program reads 3 inputs and sets 4 outputs. The names are the same in every maker’s editor.

TagData typeYour codeWhat it means on the machine
StartBOOLReadsAn input your code needsStart pushbutton
ResetBOOLReadsAn input your code needsReset pushbutton
MixDoneBOOLReadsAn input your code needsMixing finished
PumpOnBOOLWritesAn output your code setsPump command
ValveCmdBOOLWritesAn output your code setsInlet valve command
MixerOnBOOLWritesAn output your code setsMixer command
DoneBOOLWritesAn output your code setsJob complete

In Siemens SCL, write a block’s own tags with # in front, as TIA Portal does: #Start. Rockwell and TwinCAT use the name on its own: Start.

Automatic tests

Write your first state machine: what the tests check

  1. Every state sets all four outputs: pump, valve, mixer and Done.
  2. Each state has one way out: Start from Idle, MixDone from Running and Reset from Complete.
  3. State changes at most once per scan, even with Start, MixDone and Reset all on together.
  1. Try it Use the buttons below the model and watch the rig respond.
  2. Test solution Every check runs on your code in one press.
  3. Rewind PRO (needs Pro) If one fails, step back through it one scan at a time to see why.

Stuck on this mission? Ask the members in the Locker Room.

Why it matters

Where you’d see this on site

A factory mixer is waiting, running or finished. The operator starts each batch, and resets the panel when it is done.

Without one clear state, a finished batch can start again by itself. A Done lamp that copies a sensor goes out as soon as the mixer stops.

Where you'd find thisMaking one batch of drink

At a drinks factory, valves let measured amounts of water and syrup into a mixing tank. An electric mixer blends them into one batch. An outlet valve then sends the drink to a holding tank. Filling machines bottle it from there.

  1. Ingredient tanksHold the water and syrup
  2. Mixing tankFill, mix and measure one batchYou are here
  3. Holding tankKeeps the finished drink ready
  4. Bottle fillerPuts the drink into bottles
On a real site: places, parts and safety
  • Drinks factory — blending water and syrup
  • Paint factory — mixing ingredients into a consistent colour
  • Water-treatment works — preparing a measured chemical mixture
  • Brewery — heating water for washing equipment

A full tank does not close its own inlet. Water keeps arriving until the valve closes, so an open inlet can flood the room.

A heater that is not covered by liquid can overheat. Real tanks have separate safety devices as well as the PLC program.

The sizes, timings and cutaways are teaching choices, not a drawing of any one real installation.

Keep going

Next on the road