Contact and Coil | Nearly In Control

Patterns of Ladder Logic Programming

If you’re familiar with PC programming in languages like Java or C#, then you’ll probably know about the books Design Patterns: Elements of Reusable Object-Oriented Software and Patterns of Enterprise Application Architecture. These books are about Software Design Patterns.

As a long time ladder logic programmer, I thought one way to share my experience with newer programmers is to organize a list of common patterns used in ladder logic programming. This list of ladder logic programming patterns serves two purposes: first, each pattern is a tool for solving a common problem using ladder logic, and having these patterns in your toolbox will allow you to program faster and spend more time focusing on the higher level structure of your program. Second, since these are common patterns, you’ll start to find it easier to read other people’s ladder logic, and other experienced programmers will find it easier to follow your logic.

  1. The Sealed in Coil pattern
  2. The State Coil/Fault Coil pattern
  3. The Start/Stop Circuit pattern
  4. The Set/Reset pattern
  5. The Flasher pattern
  6. The Debounce pattern
  7. The Input Map pattern
  8. The Step pattern
  9. The Mission pattern
  10. The Five Rung pattern
  11. The Mode pattern


  • eplc · November 13, 2015 at 9:26 am

    I do think this is a great idea. Keep posting!

  • codezs09 · February 6, 2016 at 12:58 pm

    Very useful. Thank you for sharing

  • Cheng · February 15, 2016 at 10:29 am

    Very useful and detailed

  • LKH · March 8, 2016 at 8:29 am

    Very nice idea for people just starting out!
    You should include an Anti-Tie Down pattern 🙂

  • Bob · June 24, 2016 at 3:45 pm

    Very nice. I hope you keep adding new sections to this. Naming conventions, Fault – Acknowledgement pattern, Messages/Warnings/Alarms ect.

    I will be sharing this with my colleagues.

  • narakirin · November 28, 2016 at 1:43 am

    Thank you very much

  • azetou · November 8, 2017 at 2:18 am

    Thank you sir for your efforts. Just one question, when you show the timing diagram shouldn’t we see the clock in it? it means you have to add at what intervals the CPU updates the inputs and outputs. Thanks for clearing this up for me.

  • Author comment by Scott Whitlock · November 8, 2017 at 10:24 am

    @azetou – A clock signal would make sense for combinational logic with internally clocked registers, but a PLC is just simulating combinational logic with a sequential program. In a TTL circuit, the clock causes the registers (flip-flops) to update their outputs, which then changes the downstream logic from those elements. In a PLC, every instruction potentially causes the update of internal state, but the logic that depends on that state change doesn’t actually change until those instructions execute. Example if you have two rungs: A := A + 1, and the second rung is A := A – 1, then during the scan A both increments and decrements. A program with 100 rungs could have potentially hundreds or even thousands of “clock pulses” every scan.

  • Allan · December 13, 2017 at 1:06 pm


  • Allan · December 15, 2017 at 6:40 am

    Scott, can I translate it to Portuguese and share it with due credits?

  • Author comment by Scott Whitlock · December 15, 2017 at 2:46 pm

    @Allan – yes, as long as you provide a prominent link from the translated copy back to the original. Also, please send me the link to your translation so I can post a link to it from here.

  • Designmönster för ladder – Automat Etta Nolla · April 13, 2018 at 10:08 am

    […] Patterns of ladder logic programming […]

  • Aliazzz · July 1, 2018 at 8:05 am

    Dear Scott,

    I took the liberty to translate the patterns into CODESYS v3 ladder logic as FB’s. Offcourse kudo’s got out to you, the original poster. I also linked to this page for future reference.

    Just a remark;
    Some ladder patterns are considered obselete in CODESYS v3 (on which TwinCAT3 is based). I implemented them anyway for educational purposes but I suggest to adhere the IEC 61131-3 standard solution.

    I tried to stick as closely to your examples as possible but took some liberties in naming variables etc.

    With kind regards and thanks for sharing!

    Ps you can find my git at:

  • harinder · March 27, 2019 at 11:21 pm

    PLC ladder for controlling stepper motor

    how to move the pulse value

  • Author comment by Scott Whitlock · April 1, 2019 at 5:58 am

    @harinder – controlling a stepper motor directly from ladder logic is rare. Traditional PLC scan times aren’t fast enough to step the motors at a reasonable speed, and you require special output hardware to drive the stepper motor coils without inducing too much current, and giving you improved control like microsteps.

    If you want to control stepper motors from a PLC, you normally buy a separate stepper motor controller / drive as an add-on unit. For the Allen-Bradley world, I’ve used AMCI products. For Beckhoff TwinCAT, I’ve used the EL7041 card. You can also buy stand-alone stepper motor systems from Automation Direct.

  • Timothy P Hannagan · May 26, 2019 at 10:12 am

    I am trying to learn how to set up and use analog input and scale analog output in Beckhoff twincat 2 , help please

Leave a Reply

Theme Design by