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

Out and back on a switch: PLC programming exercise

Send one cylinder out, and bring it back when its switch says so.

Each press of Start sends cylinder A out once. It comes back when reed switch A1 shows it has arrived, not after a time.

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 electro-pneumatics trainer this mission runs onPRO (needs Pro) mission
How the test runs

One press, one full stroke

Test 1 of 4
Set by the testChecked by the testStep 6 of 6 · 4.7 s
Level
Applied
Time
About 15 min
Reward
+250 XP
Rig
3D electro-pneumatics trainer
Siemens editors
Ladder (LAD), SCL
Rockwell editors
Ladder, Structured Text
Beckhoff editors
Structured Text
Stage
33. Pneumatics lab: cylinders, valves and reed switches
Required behaviour

Out and back on a switch: what your code must do

Keep AirOn ON, so the trainer has air. When Start is pressed while the air is up (AirOK) and A is fully back (A0), turn ExtendA ON. Keep it ON until A1 comes ON: the piston has reached the end. Then turn ExtendA OFF and the valve's spring brings A back. One press is one stroke: holding Start in, or pressing it while A is moving, must not start another. RunLamp is ON from the press until A is fully back.

Start
Needs AirOK and A0. One press, one stroke.
Out
ExtendA ON until A1 comes ON.
Back
ExtendA OFF: the spring valve returns A.
How it's checked
The checks press Start and watch the trainer itself: its reed switches and StrokesA, its count of strokes that reached the end.
Tag table

Out and back on a switch: inputs and outputs

Your program reads 4 inputs and sets 3 outputs. One more input drives the simulation or shows a reading, for you to test with. The names are the same in every maker’s editor.

TagData typeYour codeWhat it means on the machine
StartBOOLReadsAn input your code needsGreen Start pushbutton
AirOKBOOLReadsAn input your code needsPressure switch 0B1: ON once the air is above 4.5 bar
A0BOOLReadsAn input your code needsReed switch 1B1: cylinder A fully back
A1BOOLReadsAn input your code needsReed switch 1B2: cylinder A fully out
SlowABOOLNot neededFor testing or watching; your code can leave it outTry it: wind in the flow control on A's out stroke, so A goes out slowly
AirOnBOOLWritesAn output your code setsDump valve 0V2: ON lets the air in, OFF lets it out
ExtendABOOLWritesAn output your code setsValve 1V1, spring return: ON sends A out, OFF brings it back
RunLampBOOLWritesAn output your code setsGreen lamp: a cycle is running

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

Out and back on a switch: what the tests check

  1. AirOn stays ON, and nothing moves until Start is pressed.
  2. ExtendA stays ON until A1, however long the stroke takes.
  3. A comes fully back, and RunLamp goes OFF when it's home.
  4. One press gives one stroke, even if Start is held in.
  5. Start does nothing without air, or while A is moving.
  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 single cylinder going out and back is half of all pneumatics. An ejector kicks a part off a belt, a stop gate lets one carton through.

A cylinder brought back on a timer works until the air pressure drops or someone adjusts a flow control. Then it turns back before it has done its job, and nothing reports a fault.

Where you'd find thisMove things with air, and know where every cylinder is

Most machines that clamp, push, lift or eject do it with air cylinders. A solenoid valve sends air to one side of the piston and lets it out of the other, and a small switch on the barrel tells the controller when the piston has arrived. Colleges teach it on a board like this one, because the same few parts make up almost every pneumatic machine.

  1. Air supplyFiltered, set to 6 bar
  2. ValvesOne 5/2 valve a cylinder
  3. CylindersOut and back on airYou are here
  4. Reed switchesProve each stroke
On a real site: places, parts and safety
  • Assembly machines that clamp a part, then press or drill it
  • Packing lines that push, lift and eject cartons
  • College and apprentice training workshops

Compressed air is stored energy. Shut the isolator and let the air out before touching pipework: a hose that comes off under pressure whips.

Letting the air out isn't always the safe state. A cylinder holding a load upright drops when the air goes, so real machines are assessed one cylinder at a time.

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

Keep going

Next on the road