Gator/Arduino Compatible PLC (Part I) (Programmabl

Gator/Arduino Compatible PLC (Part I) (Programmable Logic Controller)

A customer/contractor wanted a "Internet Controlled Water Sprinkler Valve Controller."
By having the Internet to automatically predict "local" weather projections and by using local rain guage sensors,
water consumption and usage could be greatly reduced. ($$$$)

We decided build a "generic" programmable logic controller using an Arduino compatible microcontroller. (See design specs. - below)
The isolated input / output interface board for the PLC (microcontroller - Arduino/Gator/Gator+) uses the Parallax Digital I/O Board Kit.


PLC Generic Design Specs.
Version: 1.0b
Date: 3/1/2010
Author: ArduinoAndy

#1. +12 VDC single supply voltage operation.
#2. 8 opto isolated digital inputs - +12 VDC inputs. <Parallax Digital I/O Board Kit (Parallax.com)>
#3. 8 relay outputs - 4 solid state for AC loads (8 amp) and/or 4 mechanical for AC/DC loads (12 amp). (can be mixed and matched - 8 total) <Parallax Digital I/O Board Kit (Parallax.com)>
#4. Accurate real time clock with battery backup. +- 1 minute per year @ room temperature. <I2C Real Time Clock - ChronoDot (Macetech.com)>
#5. LCD Display with software controlled backlight/contrast for PLC status and data. <New Haven 4 x 20 LCD serial Display (newhavendisplay.com)>
#6. I/O Status LEDs on all digital inputs and outputs. <Parallax Digital I/O Board Kit (Parallax.com)>
#7. All PLC sub modules are standoff mountable for easy repair and maintenance.
#8. RGB LED status annunciator. <BlinkM RGB I2C LED Annunciator (Sparkfun.com)>
#9. Modular analog and digital interface. <Electronic Bricks by Seeed Depot (seeedstudio.com)(compatible modules by Phidigets.com>)
#10. All modules and parts easily purchased via Internet for quick construction. (Except for Watchdog timer / 12 VDC Bus board, 5 VDC Distribution / I2C Bus Protoboard, which has to be constructed)
#11. PLC intended use (inside) for home automation, security, envir. control. <---- Not for use in an industrial or medical (life) applications!!!!
#12. PLC Watchdog Timer for output control safety and protection. <Still under design/construction/testing.> <----<<<< This Watchdog board is a design requirement.
#13. Rugged microcontroller inputs and outputs which are protected from ESD, shorts and overvoltage. <Gator/Gator+ (RuggedCircuits.com) [Also, can use the standard Arduino?]
#14. PLC controlled and polled via serial port by the Internet. <IOBridge with serial output module (IOBridge.com)> (Rugged Circuits Gator has two serial ports for easy external uploading and serial I/O)
Note: The IOBridge needs no PC but needs an Ethernet / Internet connection to function.

(Part I)

Parallax Digital I/O Board Kit


General

The main digital input/output "isolated" interface board is the Digital I/O Board KIT from Parallax. The Parallax Digital I/O Board Kit enables your microcontroller to interface to high voltage circuits allowing you to read up to 8 optically isolated inputs and control up to 8 isolated outputs. Inputs can be a voltage from 5-30VDC (AC compatible) and outputs can be either mechanical (AC/DC loads) or solid state relays (AC load only) that can switch up to 12A loads, such as cooling fans, solenoids, heating elements and more.

The Parallax Digital I/O Board Kit has the following features:
Mechanical and or Solid State Relay output
Configurable Input Voltage range
Serial or parallel interface to inputs/outputs
LED indication of power and input/output status


Hints & Tips

To use the Parallax I/O interface, 8 inputs and 8 outputs pins are needed - 16 I/O pins total. Since we are using the Gator/Gator+ with 28 I/O this was not an issue. We used this interface for easy I/O bit troubleshooting. For users with Arduino boards, the I/O requirement can be greatly reduced to 4 I/O pins by using the serial shifting in and out and using the built-in serial interface.

The cost of the board is fairly expensive but is well engineered ($50 USD) but it does not include the optional (extra) output mechanical or solid state relays. (User application requirement determined) For those, who are good at bread boarding, the cost can be greatly reduced by just buying the components needed and constructing a perf board. The schematic and instruction PDFs can be obtained at the Parallax.com website.

The Parallax I/O board needs two sources of power. The input 12 VDC "relay power" which supplies the control voltage for the mechanical and solid state relays. The "logic power" is a +5 VDC power for the opto isolator logic on the board. Both supplies will be needed and "sized" for the high current to the control to the circuits.

Since, the 8 amp solid state relay (AC loads only) and 12 amp mechanical relays (AC/DC loads only) have high amperage outputs, then only thru soldering can the relays be attached to the board.
There are no easy to use plug-in pin sockets due to the high amperage outputs. So, by chosing what type (Solid state or mechanical) and how many relays are critical due to the fact that
all outputs relays will have to be soldered on the board. Note: The relays can be mixed and/or matched.

The Parallax Digital I/O board has current limiting resistors (resistor pack) to limit excessive output current from the microcontroller. Since the Gator/Gator+ plus has 510 ohm resistors built-in, then we jumpered the resistors out on the digital I/O board. Using a standard Arduino, these resistors will save your board in case of excessive current draws or short circuits.

The I/O connections to the I/O board are done via ribbon headers. We used 22 guage wire in the header holes for a better reliable connection(s) to the microcontroller. There is also an option that uses the input +12 VDC "supply power" for the "relay power" VDD that goes to the microcontroller to supply the 12 VDC to the microcontroller board input regulator and then feeds back +5 VDC from the microcontroller supply to the I/O board for "logic power". Proper power supply "sizing" is required.

We installed 1.0K input resistors for 12 VDC photo isolated inputs instead of the 1.5K inputs resistors (default) for 15 VDC isolator inputs, which came with the kit.
Note: Different voltage photo isolated levels can be designed per user requirements.


Watchdog - Digital I/O Board

Safety and protection is always designed into a PLC and having an external Watchdog is a standard PLC design requirement. (This is NOT optional!)

Fault #1 What happens if the microcontroller fails or becomes "bricked"? (Device failure?)
Fault #2 What happens if you lose the 5 VDC "logic power" on the digital I/O board? (Device failure?)
Fault #3 What happens if the I2C bus hangs or halts the microcontroller instruction execution? (This does happens with the 2 wire.h library!) (Software or device failure?)
Fault #4 What happens if the local 5 VDC power supply is shorted / overheats or fails? (Device failure?)
Fault #5 What happens if the microcontroller has faulty, buggy software (sketch or rev.) that causes the microcontroller execution to hang, to loop forever or to halt? (Software?)
Fault #6 What happens if a microcontroller critical component like the RTC fails? (Device failure?)
Fault #7 What happens if a microcontroller, during a "fixed timed scan sequence", times out or overruns? (Software?)

You guess it !!! --> The control digital outputs could be activated and stay on all the time without the microcontroller! This loss of control is a severe safety and protection failure that can be easily preventable by proper system design. An external Watchdog will, in most cases (above), will disconnect the control output "relay power" when there is a fault, failure or error. This would stop all control outputs from functioning until the fault, failure or error is fixed or repaired.

By using one output from a microcontroller, which pulses a "missing pulse detector" watchdog relay. This watchdog relay is activated (ON) all the time, which supplies power to the digital I/O board. On any failure event, which causes the output pulse to stop, the watchdog relay will drop and the control output voltage is removed from the control output relays. The watchdog has a timed R/C 2.2 second time out delay, a manual reset and an optional "auto reset" on restart input (dry contact NO).

Note 1: By losing the "input supply" +12 VDC to the digital I/O board, all control voltage is removed from the digital I/O board. All control outputs are turned off.
(Warning ...Do not use the NC contacts on the mechanical relays!)

:sunglasses: :sunglasses: :sunglasses:

Picture of just released Parallax Digital I/O Board (Kit)
:sunglasses: :sunglasses: :sunglasses:

Bigger picture of PLC. This development board is used for software/hardware design and testing.
Picture includes Parallax's Digital I/O Board Kit, Rugged Circuit's Gator/Gator+, Macetech's RTC "ChronoDot, New Haven 4 x 20 serial LCD and Futurlec +5 VDC 1 amp switching power supply.
Bottom right - Sharp Solid State Relays and Omron SPDT mechanical relays.
:sunglasses: :sunglasses: :sunglasses:

Very nice work as usual :slight_smile: Allen-Bradley are probably starting to become worried!

You really meant to say "Automation Direct" with their Koyo PLC series product line should be worried.
Besides, those are "Industrial PLCs" with class certifications.
;D ;D ;D

Also, how many Allen Bradley or Koyo PLC types do you know of that can be repaired by the end user at
a very low cost? The answer is 0 - ZERO. Guess what? My Gator PLC, due to its modular construction,
can be easily repaired by the end user!
:sunglasses: :sunglasses: :sunglasses:

The I/O schematic - a better one can be obtained at their website.


:wink:

Part II - PLC Watchdog - design and schematic.

Below is the preliminary PLC WatchDog Schematic we used to build a "missing pulse detector" for our Home Automation PLC using
the Parallax Digital I/O Board. Arduino users can use this "preliminary" schematic as an engineering starting point to prevent equipment and property destruction
by disabling the digital control outputs when the following occurs:

#1. Microcontroller/Gator/Gator+/Arduino device failure.
#2. I2C lockups/hangs due to loss of device +5VDC vdc power or device failure, which hangs/halts the Arduino/CPU.
#3. Loss of device/system +5 VDC power.
#4. Microcontroller uploading which might cause the control digital outputs to turn on.
#5. Microcontroller software bugs or revision changes which could force the digital control outputs on.
#6. Software task timeouts or scan overruns. (Software stops the WatchDOG)

The microcontoller needs two digital outputs to control the PLC Watchdog.
One resets/restarts the WatchDog timer.
The other output pulses or "kicks the dog" to keep the WatchDog enabled via software control.
When the microcontroller fails, device fails or under software control the pulsing stops, all digital control outputs are disabled.

Note: You can use just one digital output but you need to manually reset the timer on all uploading, power blips or brownouts.
You could also prevent brownouts by using a computer UPS, which most modern PLCs already have built-in to their systems.

Note: There are no known problems with the PLC Watchdog ... yet ... further testing in progress.

Note: Watchdog part costs ~ $13 USD.

:sunglasses: :sunglasses: :sunglasses:

PLC WatchDog Schematic Rev. 1.0b

Picture of PLC WatchDog breadboard module.


:sunglasses:

Below is a picture of the Home Automation Gator Programmable Logic Controller System Block Diagram.


:sunglasses:

The picture (below) of the Home Automation "Gator PLC" which is 3/4 complete. Still waiting on parts for the 3 pin A/D interface board, which connects to the upper left corner of the Gator microcontroller.

In the picture, from the top left, is the BlinkM I2C RGB annunciator and the ChronoDot RTC. Below that, is the 5 VDC and I2C bus board. Then comes the LCD terminal display, the 1 amp 5 VDC power supply, the Gator and Watchdog and 12 VDC Bus Board. Last is the Parallax Digital I/O Board.

This development PLC panel is used for software development and PLC I/O simulation.
The final PLC end product will be installed in a Nema enclosure.
BTW ... everything works fine, so far.

:sunglasses: :sunglasses: :sunglasses:

I know what you are all thinking ... "So what that we went through all the engineering effort to design a generic, very reliable, Home Automation Programmable Logic Controller" What are some of the unique home control applications that can be applied using this Gator PLC?

Applications:

  1. "Internet controlled water sprinkler valve controller", uses four relay digital control outputs for 4 zone water valve solenoids. 2 digital photo isolator inputs are used for accumulated water detection. IoBridge via serial port, off loads the projected weather forcast to conserve water usage and to save money on the utility bills. The valve controller uses the built-in ChronoDot RTC for water scheduling. This PLC valve controller acts in tandem with the existing water sprinkler controller to allow transparent backup in case of PLC failure and adds greater uptime reliabilty to the system.

  2. "Garage door automatic/manual, remote/local opener and closer" uses one photo isolator input (feedback) from the garage door magnetic open/close sensor and one relay output to pulse the open/close garage door switch. One A/D output is also connected to a beeper/buzzer to indicate pending door closure. An RTC along with "fast", ambient light sensor (TEMT6000- Sparkfun.com), also on the A/D bus, senses lighting conditions and closes the garage door automatically at night.

Using Wifi and a iPhone/iPod Touch, a home user can remotely or locally open and close the garage door. The IOBridge connected to the Internet and the PLC via serial port, can also open and close the garage door from any user PC.

Note: Using the isolated inputs and outputs from the Parallax Digital I/O Board allows long runs of remote wiring to and from the PLC.

Note: The garage door control electronics are NOT modified and is preserved to allow transparent garage door operation and reliability.

Note: The IOBridge can visually indicate, on their I/O Bridge internet website, garage door entry and exiting using the garage door feedback from the garage door magnetic sensor.

  1. "Garage Parking Assistant", which guides the driver by ultrasonic range finder sensor (EZ0 - MaxBotix - Sparkfun) and a mixed color I2C RGB BlinkM indicates the precise parking distance, in the garage, by changing color patterns. One A/D bus I/O is used along with the built-in IC2 BlinkM PLC system annunciator.

  2. "Automatic garage lighting controller", automatically turns on/off ceiling lighting in the garage using Insteon, PIR Detector and one digital output contact are used in this controller. During the day, human presence allows preproprammed on/off time delays and at night using the RTC the lights are scheduled OFF.

The best part is that ALL of the above home controller applications can easily done using one Home Automation Gator PLC and still have left over digital and analog I/O.

"Let the power of the PLC be with you"
Enjoy
:sunglasses: :sunglasses: :sunglasses:

This is pretty cool, and probably something I should do for my home's watering system (right now, we run in manually, even though it has an electronic timer system - it is just difficult and fussy to program, and it being outside (though under the porch area) means that the switch contacts for the programming buttons and such don't work great, and you have to remember to shut it off in case of rain, etc).

Are you planning on adding a "ladder-logic programming" system to it?

A definite NO.

The Arduino functions are more than sufficient and easy to use than the "Relay Ladder Logic" of yesteryear. Your can do more with the Arduino's function set than any vintage PLC with RLL. The key is to mimic the PLC scan with functions like millis() to make sure all control functions are executed within the proper time frame.
:slight_smile:

Then what justifies calling it a PLC, The external watchdog timer and industrial looking I/O modules? I've always associated PLCs with their most common programming method of ladder logic symbology.

Lefty

Being in the electronics controls industry for over 30 years, I can answer this one.

A Programmable Logic Controller (PLC) has four major units ...

#1. Central processing unit (CPU) -- microprocessor, memory and power supply.
#2. Programmer/Monitor
#3. I/O modules (input and output modules) (in most cases isolated)
#4. Racks and Chassis.

This PLC defination was made before the use of microcontrollers came to the market.

To qualify as a PLC does not require the use of RLL - Relay Ladder Logic.
Modern PLC systems use flowcharts and or a combination of the IEC-1131 programming languages.

:sunglasses: :sunglasses: :sunglasses:

Even so, I think it would be cool to have ladder logic in there somewhere; it would probably have to be as a front-end preprocessor to the C code. While I realize that the Arduino and C can do everything and more that ladder-logic can, the fact that it is old-school, and there are a number of people who understand it still around, might make it useful in something like this; if a front-end pre-processor was available, then they could code and use that to translate over to AVR C...

:slight_smile:

The only decent RLL control language translation, I have seen, were done on a 8051 microcontroller, which has Boolean hardware instructions. The AVR Arduino has none.
:frowning: :frowning: :frowning:

A modern PLC is best used with Strutured Text, one of the IEC1131 languages. And thats very close to the Arduino, I have transalated some of my ST libs to the Arduino and it wasn't hard at all.

In my opinion, ladder is gone. No kids want to learn it any more. Its just nostalgia for us oldies.

My suggestion is to create the PLC shield with 24VDC digital IO:s, 4-20mA analog IO:s and keep the programming as an Arduino.

I will agree with you on keeping the programming on the Arduino.

As for building a PLC shield, with mechanical and solid state relays switching AC and DC would be a definate design flaw. The switching noise will kill the microcontroller. You would never be able to get it to work properly.

If you include just 24 VDC digital I/O then you will be quite limited on the applications you could create with the PLC shield. Besides you still need a watchdog timer for safety and protection.

On your suggestion in using 4-20ma analog I/O (250 dropping resistors), the cost of the external 4-20 ma. transducers would be prohibitive.
:wink: