Open source PLC based on Arduino

I'm an arduino fan for many years. It's really an excellent project that changed the way people look to electronics. But, anyway, I will not waste my words saying something everyone here already know. Arduino rocks! XD

Some years ago, I worked on a facility and had my first contact with these peculiar controller called "PLC". PLCs are robust digital controllers made for the industrial environment. They can be programmed using a graphical language called Ladder (it is very similar to electric diagrams) and is used in most industries all around the world. The big problem is that there is no open source PLC to date (at least none that would be compatible and do the same thing an actual PLC does), and PLCs are extremely expensive! :~
So, in 2012 I started building my own open source PLC. I created a google code page to share my research and made a few friends along the way. It was all based on arduino. Actually, my first version was just an arduino with some shields that I developed myself, to offer some protection to inputs and outputs. The project now has grown into a complex system with 4 boards, but is still based on the Arduino platform. I call it OpenPLC. Every board has an ATMega microcontroller and runs the arduino boot loader. The CPU is an ATMega2560, with USB , ethernet and RS-485 communication. The slave boards runs on 328P's and have 485 communication with the CPU.
If you want to know more about the project, check this website: http://www.openplcproject.com. If you want to collaborate, give suggestions, or say anything related to the project, please reply to this post, PM-me or email me.

I hope you enjoy it!

Thiago Alves

What protocol are you using for communications to SCADA etc?

The OpenPLC uses its own protocol (called OPLC Protocol) over 485 to communicate with expansion cards. To communicate with other systems (SCADA) it uses MODBUS over TCP/IP. I tested it using some free SCADA software that support MODBUS TCP and it worked fine! :smiley:
Not all MODBUS functions were implemented, but the most important ones are (like read coils, write registers, write coils, read inputs).

I'm planning to create a another version of the OpenPLC. It will be called OpenPLC Mini. The idea is to create an arduino shield combining features of the input card and output card in only one board, that would attach to an arduino UNO or Mega. It also needs to be compatible with all software developed for the OpenPLC. It means that it will behave exactly as the original OpenPLC, but without ethernet and expansion capability. I believe that a small board will decrease costs and help the platform to spread better. I believe that a simple single board like this can be sold for about $50,00. It means that with about $50 you can transform your standard arduino into a robust PLC compatible with Ladder diagrams. What do you guys think about it?

In preparation for the OpenPLC Mini, I developed a beta version of the OpenPLC Ladder Editor that can generate code for a standard arduino from a ladder diagram. Its fully compatible with standard OpenPLC and is available for download now!

If you want to try it out on your own arduino, read my blog post about it and download it from the link posted there
http://www.openplcproject.com/#!OpenPLC-is-having-a-new-brother-the-OpenPLC-Mini/c1r22/64E8D308-1B83-41CA-B5F6-68B20E6CF47A

Since I dont't have all types of arduinos, I need people helping me testing the code on their own hardware. It has been reported to work on arduino UNO and Mega, but I want to know if it works on Mega 1280, Duemilanove, and its variants.

I found your website last week, and I've been VERY excited ever since. I debug Siemens PLC/CNC systems for an automation company, and have wanted to venture into arduino programming for a long time, but the textual programming immediately turns me off every time I look at a sketch. If this is an affordable, real PLC, I would be eager to buy the hardware/software package from you.

Will it have any of my favorite Siemens features, such as:
online viewing, where I can see which bits in a rung are high and low in real time?
Online editing?
Function blocks?
Function calls?
Structured data blocks?
Search tools that check all functions for an address?

It will have all functionality you mentioned, plus zero cost! :wink: I'm planning to integrate the OpenPLC hardware with Beremiz, a complete open source IDE for automation. Beremiz is a very interesting project.

But right now, the OpenPLC can only do the basics: digital input and output and ladder diagram (with all standard blocks)

This is an amazing project. Congratz. It would be cool if you can match the industry requirement for this device to survive on the industry enviroment.

I am a software guy, and have some LADDER experience. First thing I did was rush to see if your source is on Github and if I can help in building the IDE.

Saddened to see two things

  1. Source not on github (Why?)
  2. Windows-only targetted audience. (again why? If it's an open source project, you'll get huge support from the Linux crowd)

Instead of the C# based project, we could fork Processing, and create the Ladder Editor from that.

Arduino and Fritzing are exammples of Processing's versatility. From PCB graphic design to Atmega binary compiling and uploading, a lot can be done. I am sure handling Ladder wouldn't be hard.

Also I would love to contribute to this project (mainly from the perspective of developing Arduino <--> OpenPLC interfacing libraries, and on the IDE (Ladder Editor). So where do I start with that ? :slight_smile:

It sounds to me that someone needs to write a better version of the configuration
utility using open tools, then the c# one can be left to die.

@championswimmer
As an electrical engineer, my knowledge about high level Windows / Linux programming is limited. I'm much stronger with low level programming and hardware design. For this reason, the ladder editor for the OpenPLC is based on LDmicro, a simple Ladder editor/compiler. Since LDmicro is windows-only, the OpenPLC Ladder Editor has to be windows-only too. I wanted to support linux, but since I was running out of time for my graduation, and I had LDmicro working perfectly, my option was just to modify it to make it work with the OpenPLC hardware.

Currently, I use LDmicro simply as a Ladder -> ANSI C compiler. Once the ANSI C code is generated from the ladder diagram, I call the AVR GCC to compile the OpenPLC firmware with the LDmicro generated code included as a header file. It means that the ladder instructions are compiled to machine code with the firmware every time you upload a new ladder program. I found this process to be easier to build and faster to run on an 8-bit hardware.

Some people suggested me to change this process to interpreted instructions, for instance, the ladder editor generates a XML file with the ladder instructions, then it is uploaded to OpenPLC's flash and interpreted at runtime, just like any other standard PLC. But this approach requires a complete change in the OpenPLC's hardware. The actual 8-bit architecture can't achieve that at a reasonable speed.

So I'm going for the Ladder -> ANSI C idea until I create a faster version of the OpenPLC. If you are willing to help, I need your knowledge to build a brand new ladder -> ANSI C compiler, like LDmicro, but, as you suggested, based on processing and multiplatform. I'm open to suggestions, but I think that this will be the easiest approach, at least to start with. If you manage to build that, the integration with the OpenPLC hardware will be seamless.

About the source code, actually it is available at github. If you go to my website (www.openplcproject.com), at the downloads section, the OpenPLC Ladder Editor source link points to my github page: GitHub - thiagoralves/OpenPLC-Ladder-Editor: Ladder programming language for the OpenPLC and Arduino

@MarkT
You are right. I believe that if we manage to create a new version of the Ladder Editor, the configuration utility must be rewritten and integrated to the Editor, so that both may become a single software for the OpenPLC hardware.

@thiagoralves

I suggest you dump the forum on your web site (nabble) for a better one like SMF (used in this site) and attract all the discussion to openplcproject.com

Add small news at least a month. Make sure your links work (links at the bottom of pages do not work)

Move wiki info from google code to openplcproject.com

Make it look like it is alive. From where I am it looks death.

Regards.

I have written ​​an article about Build PLC using Arduino , please visit the link Build a Simple PLC using Arduino

Thanks
Cartiman

can someone tell me what's the difference of PLC and arduino uno and what we most add to arduino to be like the plc !!!

samizroud:
can someone tell me what's the difference of PLC and arduino uno and what we most add to arduino to be like the plc !!!

Mainly, it's safety and liability.

An industrial PLC is designed to be as inherently safe as possible - meaning that it's outputs will be in a properly defined state when it is switched on or off, that it won't randomly set output pins due to environmental conditions, that it has means of rejecting noise, and a whole host of other specifications.

If something does go wrong, there is generally a company behind the product which can assume liability, especially in cases of a major industrial accident involving such controls. To that end, an insurance company for such an industrial concern will likely want such assurances about the industrial controls; the Arduino (as-is) has none of this.

You also have the hardware side of things - most industrial controls output and expect 12-24 volts DC - not 5 volt TTL levels (but it runs the gamut); a PLC is designed to talk to such devices, while not being destroyed by noise and transient voltages (back EMF and the like). Furthermore, PLCs in general are designed as "real time" systems, whereas the Arduino isn't such a device (it is probably possible, though, to code the ATMega328 for real-time usage, but not likely using the Arduino libraries). I'm sure there are plenty of other "hardware" differences that I am not mentioning.

Programming for PLCs is generally done in a form of "ladder logic" - though from what I understand, C/C++ and other languages are becoming more common. However, understanding ladder logic, how it works (both as a program/state machine - and as real hardware) - are both paramount to using another language for industrial control - whether its a PLC or an Arduino.

Could an Arduino be used in place of a PLC? Sure - there are ways to do it. But ultimately, you won't likely be able to simply drop-in a cheap Arduino for a PLC, even with the needed modifications and support. This is because of the liability concerns and the business insurance requirements. The only way that it would be possible in that case would be to use an approved and vetted Arduino-based PLC replacement hardware and software system. AFAIK, nothing like that exists, though there have been attempts to create such things (in most cases, I think the hardware and software became available - but the needed validation and approval for insurance concerns is the expensive part, which no one has done).

If you don't need a PLC for an actual business or industrial purpose, then an Arduino would probably work fine for your purposes.

Guys-
I am totally on-board with you. There needs to be a good PLC-like implementation with Arduino. Here's my shot at it: www.plc.us All the hardware and software is fully open source, so please use the ideas in your own design. The world will be a better place when there are rugged PLCs based on Arduino compatible chips.
-Martin

Hi-

I found a guy named Marco who advertised an Arduino compatible PLC on Kickstarter. A couple of guys here at work paid for some, but they haven't arrived yet and it's been well over a year. We understand things happen, but we think a good quality Arduino PLC should be here NOW.

So we decided to just do it ourselves and keep everything, including the hardware, open source. Here's were we are so far: www.plc.us

If anyone wants to join the development or contribute PLC related code to GitHub, please join us.

Thanks for looking.

-Martin

Hi guys,

So I just wanted to give you all an update about my project. The OpenPLC is now a complete package with a new editor and compiler. The editor runs in Windows, Linux and MacOS and supports all the 5 IEC 61131-3 languages: ST, IL, LADDER, FBD and SFC. It also supports functions and function blocks.

The compiler is responsible for getting the program written by the user and compile it to the platform in which the OpenPLC is running. Currently, the OpenPLC runs on Raspberry Pi, Arduino, UniPi and also as a soft-PLC on Windows or Linux. If you have an Arduino board collecting dust somewhere, you might want to give OpenPLC another try.

Go to the website for install instructions: www.openplcproject.com

Thanks,

Thiago Alves

Hi folks,

I've been working on a new board for the OpenPLC. My goal is to have it as simple and cheap as possible, although still offering PLC-level of electrical protections. It is called OpenPLC RN (RN is for Remote Node), and will be based on the ESP8266 chip. This initial version will support Wi-Fi only, but I'm also planning in creating a variation of OpenPLC RN that will work on Ethernet based on the ATMega 328p + ENC28J60.

Attached is the schematic of the current version of the board. It is still in development! Therefore, I would love to hear the opinion of all of you concerning what you want to see in the board and also suggestions for modifications.

I'm looking for partners that will be able to manufacture this board when ready. If any of you know about any PCB manufacturer in US or China, please contact me.

Thanks!

Thiago Alves

OpenPLC RN Schematic

i made a lcd frame and pcb board based on DUE.

Specification:
8 optocoupled input
8 optocoupled output.
8 PWM out optocoupled.
1 Expansion connector for mount extra board
1 RTC
1 eeprom 256K
1 connection for 4.3" and using all functionnality of lcd like SD, Flash touch.