Open source PLC

In industrial applications, controlling relays, servos, solenoids, and the like isn’t just a matter of wiring in an Arduino and plugging in some code. No, for reliable operation you’ll need a PLC – a programmable logic controller – to automate all your hardware. PLCs are usually pretty expensive pieces of hardware, which led [Warwick] to come up with his own. He built two versions, one large and one small that can handle just about any task thrown at them.

Both devices are powered by an ATMEL SAM7S ARM chip running at 48 MHz. The smaller of the two devices has 10 digital inputs, 4 analog inputs, and 8 digital outputs able to sink 200 mA each. The larger PLC has 22 digital ins, 6 analog ins, and 16 digital outputs. Both of these devices have a ton of connectivity with USB, RS-232 and RS-485 ports

Below you can see the large PLC being used as a barcode scanner and as a strange device using compressed air to levitate a ping-pong ball. There’s also a demo of the smaller PLC lighting up some LEDs.

57 thoughts on “Open source PLC

  1. Now make sure you connect that PLC to the internet. Why ?
    Because homeland (what is this mother russia?) security says
    all PLC’s are connected up so evil “hackers” can access them.
    How else are they going to shut down the national power grid ?
    (never mind the fact that every nuke plant i’ve worked at, all that
    $hit was on a CLOSED air-gapped network).

    1. Google Stuxnet. The U.S. government and the Israeli’s hacked into Iran’s SCADA network they were using to process uranium, and commanded the motors to spin at a higher rate than they were designed for, destroying their centrifuges. They were using Siemens PLC’s…..

    2. There is more than the power plants required to distribute energy. I know the electric company in the state I live in uses very old RTUs to manage the entire infrastructure. Sure they run on a closed network using Optic fibre running in the ground wires however I am sure if you could splice in or get into one of the hundred switch yards around the state you could cause some mayhem. Thankfully they do restrict people from downloading new firmware over the network but it does not stop you from remote accessing the tables and forcing bits, who wants cooling fans on a transformer anyway!

    1. in short a PLC (programmable Logic Controller) formally called PC (programmable Controller) allow process control with field I/O using many instruction sets. The PLC is an industry hardened computer I/O package with analog and digital input and outputs, it is running CPU. The PLC CPU has instructions sets program and data memort with default tables tables. The PLC is ready to solve ladder logic, and other types of programming (new specialty controller too). In short a PLC is already designed for an industrial computer in regards to dust shock (vibration), in some cases working voltage and isolation, and while an x86/x64 microprocessor can be programmed the same task, it depends on task and developers. The difference is PLC entry point in market was geared for relay logic in 1970s when programming x86 had not gained as much traction for automation.

    2. Programming in Ladder, which is essentially a 100 year old programming language, derivative of the way logic was done with ice cube relays. Extremely fast, easy to implement. Not too many know how to program in it these days…

    3. The mount and casing system, the screw terminals, and IO isolation.
      If you dig into the guts of most PLCs, they tend to choose relays driven by optoisolators for a double layer of protection. This design just has optos. Relays offer much higher current drive out of the box before needing to use step up relays.
      Most PLCs and associated hardware are 24-48 volt compatible on inputs and outputs.

      But, setting aside the hardware for a moment, the real benefit to a PLC is the firmware design and subsequent software generated for it. Just do a search for RTOS related to using PCs as machine controllers and you will find years worth of reading. IT all comes down to reliability and safety. the firmware running behind your actual application is designed to never run away, never ignore an emergency stop button, and to be as simple as possible to program (originally for the mindset of people used to “programming” with wire, relays, gates and timers, called ladder logic).

      This is a micro controller in a PLC package, which I totally commend, and the work going into it was certainly a lot (and it looks professional as well), but I am not sure about skipping on the relays. RE firmware: I would hope and assume that there is some sort of RTOS working within the C code (there are plenty of options for that these days).

      1. RTOS in a micro? would be surprised if its not just bare matel programming, why would you need an OS to toggle a led if a button is pressed, this may seam rude but it’s all a PLC needs to do, on a input toggle an output. Altough .net is beggining to get a foot on embeded programming with the FEZ and netduinos it just looks like crazy, the ideia it’s to help windows programmers to develop for hardware but, would you trust the develpment of anything hardware related to someone who doesn’t know what it takes to blink a led?

        1. Very few PLCs use relay outputs these days, though many still offer it as an option for legacy applications. When current loops took off for control purposes and became quite reliable the perceived advantages of a reliable relay diminished. Even Safety PLCs these days opt for electronic outputs rather than electromechanical.

          1. Sorry but I don’t understand what you are trying to say here. Current loops are generally reserved for analog status and controls. You can encode a 8,10,12,16, … bit value in them and decode on the other side but it will eventually go to a discrete output whether it is a transistor or relay. That aside, you can not beat the isolation an interposing relay provides and their use is very prolific. Every digital output in a panel we build uses relays. They aren’t integrated into the PLC’s IO modules but driven by the modules output. We also specify that all IO coming into the RTU be provided using dry contacts as well.

  2. It makes me want to plug where I work, because we sell all kinds of PLC and industrial process control stuff new and used.
    In fact if you don’t mind repairing it yourself you can get some pretty good deals on broken PLC stuff like I/O modules that usually just need caps and/or relays replaced.
    There is all kind of really, REALLY OLD PLC stuff in use to this day.

    Open source is interesting, because documentation is sometimes one of those proprietary things you just can’t get.
    (GE Fanuc, I’m looking right at YOU.)

  3. I’m going to put this out there. Whoever puts together a 24v capable, optically isolated, screw terminal, modular, SAMXX based, Arduino compatible PLC system with off the shelf LCD, opto isolated relay, signal conditioning, and analog input/output modules – all in a proper enclosure, preferably with a GUI based programming interface is going to make a lot of money.

    1. As a controls engineer, my career is based on using PLC’s and PC’s for automation. Although the open source PLC seems like a nice design with some benefits, it is still technically not a PLC. For one, what is the mean time between failure (MTBF) for the design? Were mil spec components used, extended temperature range components used or were the cheapest components used? These questions are only the start…

      You can’t get away with patching firmware on a PLC as often as with a PC because clients will not tolerate it and some processes simply cannot be shut down easily just for an update. Many companies have tried to offer a PC with a RTOS as a replacement for a PLC with limited acceptance.

      PLC’s are about reliability, an Arduino or even a Parallax BS2 could replace the functions of many PLC’s. Opto22 is probably the closest to such a thing as it uses flowchart programming as well as a textual language, but the reliability is the primary cost but the features add to the cost.

      1. As much as I hate using crappy PLC programming software (and ladder logic in general), what you’ve said is all true. It’s standard and reliable stuff. For home projects I think I’d prefer to try something like this, but in “industry,” it’s best to go with what’s proven to work.

      2. agreed. Aside from reliability, key aspects of ‘real’ PLC’s are:
        – the ability to monitor program code ‘live’
        – the ability to download new software ‘on the fly’, while a process is live, without interruption

        Without these, this project is just a lookalike.

      3. There is an open source soft PLC licensed under the GPL named Proview
        It’s the best in it’s class and there are parts it beats commercial solutions without problems. One if the biggest companies in Sweden, named SSAB (steel mill), developed this beast and Proview and are running their plants with it. It is still under development.
        Powerful, flexible and almost without limits.
        They gave it free in 2006. If you can’t handly Linux or don’t want to use your brains then it’s better to stay away and continue with your outdated PLC solutions.


  4. PLCs are actually pretty cheap in hardware, especially if you dont mind used. Where you get nailed is the software. I think Allen Bradley’s software is well over $1k, same with the MItsubishi stuff.

    1. actually, $1000 for PLC-programming software is dirt cheap. Siemens wanted $1800 *per seat* for Step7 15 years ago, and IIRC, Fastrack software (GUI for old TISOFT 505 PLCs) costs $4500 per seat.

      give me open source any day; that way, i can fix bugs i can’t work around.

  5. A PLC *is* just a microcontroller with IO, however it is a very well designed controller and very well designed IO and instead of Wiring/C you use ladder logic or Structured text, more familiar to electricians and which limits pointers, register access and other “extreme programming” favoured by hackers and hobbyists using C

    The whole PLC package is very simple but very well tested and almost bullet-proof, however there is no reason an AVR/PIC/ARM based system (Especially those devices that have been around for donkeys years and are really well tested) cannot do the same.

    The good thing about this project is it is open source, so unlike commercial PLCs where you dont even know what processor is in there, means you have freedom to innovate and use a more familiar programming language or even design your own

    As to newer SOC’s, these seem to go obsolete almost before they are launched, many are released with hardware bugs and are not really a good choice for PLC systems until they have reached a certain level of maturity. Remember many PLC’s control critical systems like Nuclear Power Plants so I’m not too sure I’d like a SAMXX Arduino DUE controlling one of those just yet :-)

  6. Levitating a ping pong ball isn’t so strange. It is rather cool that it will center itself in a vertical stream of air, especially if you haven’t seen it before. Can be done easily with a hair dryer on the cool setting. Or your own breath with a bit of practice. Try it if you have the opportunity, and then see if you can figure out why it works.

    1. it’s also a demonstration of the timing / feedback based event processing:

      Start ball Levitation:
      Move the ball into position
      Turn on the air
      Wait for ball to stabilize
      Move container arm out of path

      End ball levitation:
      Move container arm into position
      Ensure that arm is extended
      Turn off air
      Return arm to home.

  7. As someone who deals with plc’s and pac systems on a daily basis I think this is extremely cool. I’m guessing the “strange device” levitating the ping pong ball is actually a form of a PID controller. Haven’t checked the videos so wouldn’t know for sure. If it’s not that would make for an even cooler project :D

  8. As an engineer trained in Automation, what I would really like to see is an open source PLC capable of being programed according to the IEC 61131-3 standard. Using Function Block Diagram, Structured Text, Sequential Function Chart and Ladder logic.

    When trying to explain basic programming structure and logic, the ladder, FBD and SFC methods form a much more understandable visual representation, making things like jumps/gotos, breaks, escapes, etc much easier to explain. Plus it’s a lot easier to get very simple projects in the air.

    Especially the earlier languages (Ladder and FBD are designed to be used by the people used to the old nuts and bolt, relays and wires) even people who might have a problem reading an ST program (let alone C) can understand the,.

    1. There are scratch ports to arduino, but don’t know how they perform as C is preferred around here. Also C can be really easy to understand if you use a begginer level programing style, remember that a programming language is just a messenger, not the message

  9. Mounting an Arduino that you program in C on a DIN rail makes it a PLC?! Not even close- it’s just an Arduino in a nice box. Sort of like putting a NASCAR shell on your Soapbox Derby chassis and telling kids to go ahead and push it on to the highway.

    1. Why does everybody complaint about C? Is it less powerful than your flowchart programming? Is it that you can’t learn a more complex programming language? The advantage of real PLC is not the caveman style programming it’s the resistance that those boxes have to shorts, peaks, dust, EMI and a long life that makes a good PLC.
      The software only has to be written and tested once, the machine has to be able to run it 48h A DAY accounting for tolerances, if it needs a 5A relay use a 10A one, if it needs a 1 inch bolt use 2 inch bolts, that is why modern installations fail quickly, its the darn bean counters wanting us to use less quality equipment to save a few bucks

      1. “The advantage of real PLC is not the caveman style programming ”

        Actually it is, when you have an assembly line that has to run at 98% operational availability….you want FAST and EASY programming

      2. I was a Forth, assembler, C, and then C++ programmer long before I was a PLC programmer. Not that I enjoy it particularly, but the advantage of PLC’s is the caveman-style programming. It is the fact that there’s no accessible OS, no accessible hardware, You don’t want your life depending on some kid’s brilliant idea for a clever way to run a traffic light using one register and the XOR operation.

        You wouldn’t believe the power and expense of the stuff that PLC’s control. I prefer C because it’s easy. But it has no place down at the PLC level.

        1. There are bad programmers everywhere, but people keep blaming the messenger (language) or the horse (PLC, micro) for the bad message (code). If you can’t comprehend the system you shouldn’t be programming critical software for it, even with ladder logic there are always outputs that can’t be on at the same time or some hydraulic cylinder will just trash the machine.
          I don’t mind my “life depending on some kid’s brilliant idea for a clever way to run a traffic light” as long it has been properly tested in regular and faulty conditions and the result is always either regular function or safe fall back

          1. I once worked with a pair of 7 MA DC switches controlled by SIEMATIC PLCs.

            The first unit was programmed by a real wizz-bang software engineer with a deep understanding of Siemens products so he programmed it in STL* for “performance”.

            Then they smart guy got Amoeba dysentery – obviously not drinking quite enough wine and booze while working in Brazil. His older colleague programmed the second unit in ladder, from the manual, because he was never trained in SIEMATIC.

            The unit programmed by the expert, turned out to be the one that every week or so lost communication and restarted. The one with the stone-age program, hacked together by following the instructions precisely — worked!

            This is not the only time that I have seen that the tools quickly becomes smarter than the programmers and overwhelms people. It was just the first time (the second was when we compared hand-crafted tricked-out math code with what the compiler would produce and found that the compiler beat the “optimised” code easily).

            Trying to be clever just confuses the tool chain, waste time and caused problems downstream, IMO. Most people just barely understand the problem they are trying to solve as it is – there is no need to add more fuel to that particular bonfire.

            *) STL is the language that ladder compiles into. Similar to assembler, but interpreted.

  10. These days most of industrial machines work with a central plc and a fieldbus with IO.

    I ‘m write a PLC-soft that runs Raspberry Pi, that is programable with the webbrowser.

    I has also the feature to create touchpanel interfaces for phone ….

    For the fieldbus I use WAGO modules, since it’s opensource you could use any module.

    The code can be found on:

    Contact me if you would like to have screenshots …

  11. How ignorant of so many “gurus” here. Opto 22 has badass programming GUI; all around Ethernet; SNAP brains are web enabled automatically but most of all it will run for 40 years as long as your power doesn’t go out.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s