In the old days, We used to have electronic controller modules or PLCs which give warning or alarms on the panel by turning several light indicators on or off. To understand these signals we have to refer their operation manual/books to interpret these messages. For example there are three indicators on the panel which has light A(lA), light B(lB) and light C(lC) so there will be 2^3 =8 combinations of warning/alarms. To make it easy to understand , They provide us a troubleshooting table to tell operators or technicians to trace the problem.
lA=0, lB=0, lC=0 -> ” Machine OK” ,
lA=1,lB=0, lC=0 -> ” Motor Overload” ,
lA=1, lB=1 ,lC=0 -> “Motor Overtemperature”,
(0 =OFF, 1 =ON) .
I am sure such devices or control panels still exists and still be built today. Sometimes it is not easy to troubleshoot the problem because of missing manual/prints or other reasons. For this purpose we will build Alarm messaging system using Arduino to retrofit old panel and convert light bulb/LED indicators into a LCD display. Here we go. Let says that we have an old PLC that control the following system (pic1). The ladder example here just to show how to manipulate 3 coil or relay outputs. Of course we can build more than 3 outputs when we need.
The ladder diagram looks like this :
Basically, this program tell us to open the valve 5 seconds before turning the centrifugal pump on. When we press “Xstart” button, it will open the valve. The Ylight1 will turn on after valve open limit switch (XLSopen) become true. Ylight2 shows the pump is running meanwhile Ylight3 indicate that there is low pressure(XLowPressure) on discharge line.The normal operation should give us Ylight1=1, Ylight2=1 and Ylight3=0. This means valve is fully opened, motor is running and we got normal pressure. Since we can make 8 combinations from these lights, We can convert these states into meaningful messages with Arduino. There is two option to use Arduino for this purpose. The first one is just for converting the state of indicators into messages. Secondly it can be utilized as both PLC and warning/alarm messages. We will use later for this example.
The Things We Need to build this Project:
- Arduino Board.
- Arduino IDE.
- LCD display (serial or I2C) with Arduino Library.
- PHP script to build Arduino Library header (optional).
Any Arduino board can be used for this project. All I/O will be configured using Arduino header. Download LDmicro from this site : http://cq.cx/ladder.pl
The beauty of this LDmicro is that we can compile the ladder diagram into ANSI- C code and from this cpp format we can build its library in Arduino environment.
For PHP script to generate a header we can get it from here : https://github.com/ah01/LDmicro2arduino
Please remember to run php script, we need to install PHP program in our computer. For PHP for windows download the program here : http://windows.php.net/download
Now Lets modify the ladder diagram from pic1.
When we look at new ladder, there are some changes and adding some rungs which have accumulator instruction (Acc ) inserted on them. These four extra rungs actually convert binary status into decimal, Binary Coded Decimal (BCD). From three relay/coil status, we can generate 8 messages.
First, save this ladder diagram as ladder.ld ( we can choose any name for this file). Next step is to choose a microprocessor. On “Setting”->”Microcontrollers” , choose ANSI-C code. Then go to “Compile” ->”Compile as… ” and save it as ladder.cpp. Click OK and it will shows :
Don’t worry about this warning. Like it said, this is not complete program so we have to build header by itself. We don’t need to know about C/C++ programming. Just use this cpp together with header we are going to build to create a library to be used in Arduino environment.
Now It is time to build a header(Ladder.h) The header below built using ladder-gen.php ( see previous link above to download it). Follow instruction there how to run and to build a header for Arduino. We can see that all I/O pins fo Arduino can be configured here.
To write an Arduino sketch, the first step is to create a new folder. Name it as “Ladder” and put both ladder.cpp and ladder.h inside this folder. Copy or move it into Dir://Path/to/Arduino/libraries.
It ‘s time to write an interesting sketch in Arduino IDE.
In the example above we use Digole serial LCD to display the messages. The good thing about LDmicro is that it much easier to create ladder program and then modify in the future with no change or few change in Arduino sketch itself. As long we have same numbers of I/O pins we don’t need generate a new header, what we need is just to compile a new ladder ( newladder.ld) and save it as newladder. cpp and copy it to an arduino library folder.