Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 37 ยท Projects and Practice

PLC Programming Practice Exercises and Review

Practice PLC logic with graded exercises on timers, counters, edges, state machines, scaling and alarms. Each exercise has a runnable C model and hints for your own PLC code.

You learn PLC programming by building things. This lesson gives you graded exercises covering this part of the track: timers, counters, edges, sequences, HMI data, communication and fault handling. For each one, first write the logic in your own PLC tool or simulator (ladder or Structured Text), then compare with the C stand-in model here. No PLC runtime is available on this site, so the C programs are the runnable reference.

How to work: read the requirement, sketch inputs and outputs, decide which blocks you need (timer, counter, edge, state machine), write it, then test with a list of scenarios, including odd ones such as a button held down or both start and stop pressed.

Level 1: single blocks

Exercise 1: Delayed start with warning. When Start is pressed, a horn sounds for 3 s, then the motor starts. Stop turns everything off. (Hint: a TP or a TON for the horn phase, a latch for the motor.)

Exercise 2: Batch counter. Count bottles; when 6 have passed, pulse a gate output for 1 s and restart from 0. (Hint: CTU with the reset driven by its own done bit, one-shot for the gate.)

Exercise 3: Toggle button. One push-button starts and stops a lamp. (Hint: rising edge and a flip.)

Here are models of all three in one program:

C C stand-in: reference models for exercises 1 to 3

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Level 2: combining ideas

Exercise 4: Star-delta start (sequence). Start closes the main and star contactors, waits 5 s, opens star, waits 100 ms, closes delta. Never allow star and delta at once. (Hint: state machine plus interlocks on the outputs.)

Exercise 5: Two-pump alternation. Rework the tank project so the pump with fewer run hours starts first.

Exercise 6: Alarm with acknowledge. An over-temperature alarm at 90 degrees with a 2 s delay, 3 degree deadband and an acknowledge button. (Hint: alarm life cycle.)

C C stand-in: star-delta starter with mutual interlock

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Level 3: data and communication

Exercise 7: Scale and display. Convert a 4-20 mA signal (0-27648 counts for 0-16 mA above 4) into 0-250 degrees Celsius with a fault below 3.6 mA. Exercise 8: Pack a telegram. Send three values (a status byte, a 16-bit speed and a 16-bit temperature in tenths of a degree) in a 5-byte packet with a CRC, and parse it back. Revisit Modbus and I/O mapping.

C C stand-in: reference for exercise 8 (pack, check, parse)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Level 4: faults and design

Exercise 9: Dual-channel guard door. Both channels of a gate switch must be closed to run; a mismatch longer than 200 ms faults. Reset only after both are closed again. (Model it on the safety lesson, and remember this is an exercise, not a certified function.)

Exercise 10: Find the bug. The ladder below has two defects. Find them before reading the answer.

TEXT
Rung 1:  | Start |---|/Stop|---( Motor )
Rung 5:  | Auto  |---|/Fault|--( Motor )

The answer: the output Motor is written in two rungs (a double coil, so Rung 5 overrides Rung 1), and Rung 1 has no seal-in contact so the motor stops as soon as Start is released. See good practice.

Exercise 11: Design review. Take the conveyor project and list ten things that could go wrong (sensor dirty, belt slips, encoder lost, cylinder stuck, air pressure low, jam, E-stop, power loss, wrong recipe, HMI disconnected) and write the program's reaction to each. This habit separates working programs from reliable ones.

Self-check with a quiz

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In exercise 10, why does the motor stop as soon as Start is released?

    A momentary Start needs a seal-in contact from the Motor output in parallel with Start to hold the rung true.
  2. 2. Which block would you choose to count 6 bottles and then act?

    A count-up counter with PV = 6 raises its output when six rising edges have been counted.
  3. 3. What is the purpose of the dead time between star and delta contactors?

    A short gap prevents a short circuit between phases caused by both contactors being closed momentarily.
  4. 4. What is the best way to be sure a new program is robust?

    Reliability comes from testing odd and failing conditions, not only the expected sequence.

Summary

  • Practice in levels: single blocks, combined sequences, data and communication, faults and design review.
  • Always list scenarios, including unusual ones, before declaring logic done.
  • Model your ideas in a simulator or in C to check timing and states.
  • Typical bugs: double coils, missing seal-in, level instead of edge, missing timeout.
  • The C programs are stand-ins; write the real versions in your PLC environment.

Next: back to the PLC Programming track