Gator/Arduino Compatible PLC (Part I) (Programmabl

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:

PLC software programming and hardware tips. (Part III)

"Design for reliability and program check for the worst"

Programmable logic controllers use "relay ladder logic" (RLL) as a preferred PLC programming control language. The Arduino "C" functions, made for programming the Arduino and compatible boards, is extremely easy to use. The Home Automation "Gator" PLC uses the same "C" functions.

The PLC scan sequence includes "input scan", "user program scan" and "output scan", which works in the microcontroller's main Loop(). Reading the inputs (analog or digital), CPU processing the inputs by "if, then, else statements" and other comparison logic and then outputing the results to PLC outputs is all that takes place during each complete "PLC Scan" pass in the main loop(). All PLC scan sequence routines are polled and interrupts are not allowed, which could halt the CPU.

We tried to closely mimic a modern PLC by timing each task in the control sketch software. If a input or control action takes too long, in execution, the PLC will halt and an error is generated. The extremely useful Arduino function millis() command which is used throughout our control software to detect any delays in the overall PLC scan sequence performance.

On reset, reboot or power on reset, the system startup routines <setup()> thoroughly checks for any device or peripheral failure. The system watchdog will not be reset and no control output action will take place until all system devices and peripherals are 100% operational. Simple diagnostic checks like I/O board logic power (checked by polling a spare input photo isolator), I2C addressing checking and a 2 second RTC update checking is all that is needed to verify that all devices are functional and 100% working. Even in the main PLC scan sequence, we run a system diagnostic check on every scan.

I2C bus is the weakest link, on this PLC and on any Arduino. Our design spec. requires a I2C real time clock and we had to make sure the I2C bus was reliable. When a I2C device like a RTC loses its 5 Volt power source, has a loose wire, or fails, or has a low battery or just hangs, the microcontroller I2C master hangs or waits for a response (forever) from the slave I2C device. We checked for this I2C device failure by installing an external WatchDog to prevent any control output(s) from functioning until the I2C failure is fixed.
Note: The I2C/TWI wire library should be rewritten to include a instruction "skip" on any I2C bus timeout failure - if possible ????

Most PLCs have LED lights to easily indicate visually what control I/O actions are being executed. LED lights for the inputs and outputs on the digital I/O board makes troubleshooting a snap. Software generated (Pin 13) red LED for uploading, PLC running, and PLC scanning also helps. The "relay power LED" and the "logic power LED" along with the +5 VDC power supply LED also help in troubleshooting PLC problems. The Watchdog has a red flashing LED to indicate watchdog "time out" and also has a yellow LED for watchdog reset (software controlled LED). By observing all LED status indications, this PLC can be easily troubleshot without meters and diagnostic tools.

During power on reset, the BlinkM cycles thru the rainbow of colors and also flashes green on the I2C bus check completion. The BlinkM is used as the PLC system annunciator. Green is system running and Red is system stopped or failure. You probably need sun glasses on to read this LED PLC system status annunciator - this RGB LED is bright!

Software delays should not be used except during the setup or startup bootup. The PLC scan time should not be slowed down by unnecessary software delays. In our applications, we need every bit of real time for both the PLC scan and the IOBridge scan loops, so the use of any software delays are prohibited. Also, by having extra 4 MHz on the Gator/Gator+ (@ 20 MHZ) provides for a faster PLC scan sequencing.

Most serial LCDs are slow but having one helps in system diagnostics. The LCD we are using takes over 100 ms. to display our LCD data, which slows down the PLC scan. We only display diagnostic data on the LCD when there is a error, failure or fault but never use it as a "running data" information display due to its slow speed.
Note: The Arduino has a receive buffer but does not have a transmit buffer, which slows down all transmited bytes to the LCD! <--- The Arduino design team, one day, should add this variable Tx buffer!

Ambient temperature and light changes affects the readability of all LCD displays. Since the LCD display, we are using, has software controlled brightness and contrast control, then we used a LM34/35 temperature and ambient light sensor (TEMT6000) to adjust the LCD brightness and contrast to different ambient conditions.

There are four ways we show PLC faults, errors and failures to the end user. Each way is dependent on where, how and when a failure has occured in the PLC.
The first way is by the 1st USB serial comm. port via laptop serial terminal program.
The second way, if the I2C bus passes diagnostics, the numerous software colors generated by the RGB BlinkM I2C LED system annunciator. Green = System OK & Red = System Failure
The third way is by the 4x20 LCD serial terminal information display.
The fourth way is to observe on board LEDs on all of the electronic sub modules.

The PLC RTC, (Macetech.com) "ChronoDot" DS3231 is an extremely accurate real time clock. In fact, Maxim-IC claims its DS3231 to be "the industry's most accurate real time clock?"
On daylight savings time changeovers in March and November of each year (In the USA), we decided to preprogrammed in all of the projected DST dates for ten years, which would keep us from resetting the RTC time every year (twice). The lithium battery would run low (8 years) before we would change the time again.
Note: This precision "ChronoDot" RTC is good for +- 1 minute per year!

Power distribution on the PLC requires "clean" and "dirty" power supplies. The internal +5 VDC switching power supply provides "clean power" to the A/D devices, I2C bus devices, the LCD and the "logic power" for the Parallax I/O board. This +5 VDC should NOT be used for any external device to the PLC. Doing so could induce noise and halt the Gator microcontroller. The "clean" +12 VDC supply input power that feeds the Watchdog, the I/O board relay power, the input of the +5 VDC power and the Gator supply voltage input should NOT also be used to externally power other devices. By obtaining very inexpensive switching +5 VDC and 12 VDC power supplies(Sparkfun) with LED indicators, should be done to power the external PLC devices and the photo isolator inputs. Do not power the photo inputs with the "clean" 12 VDC supply voltage!

Note: The external "dirty" power supplies are very noisey due to inductive switching of solenoids, relays and other loads that are connected to the PLC.

Note: The Parallax Digital I/O Board darlington driver (UN2803) has internal noise supression diodes to reduce the inductive switching noise generated by the on board mechanical relays.

Note: The Gator/Gator+ also has extra built-in ESD, overvoltage and overcurrent I/O pin protection, which greatly increases the runtime reliability of the Home Automation Gator PLC.

Note: Notice the huge capacitors on the Parallax Digital I/O Board (1000 uf), the Watchdog board (1000 uf) and the I2C bus board (330 uf) ... they are installed to filter out any noise spikes generated by the PLC sub modules.

Wiring a PLC requires special thought. Keep the AC loads as far as possible away from the DC loads. On the PLC panel (picture above) the farthest right hand corner of the Digital I/O board should be wired for only AC loads.

Summary: Any microcontroller can be used as a "programmable logic controller" to control external devices, but not having the proper designed photo isolation on the digital inputs, isolation on the digital outputs, watchdog safety protection, clean and dirty power distribution, noise suppression, board filter protection, control software that checks for task timing and also does system diagnostics then having a microcontroller to control external devices would be a waste of money due to system unreliabilty and poor runtime performance. Better have several spare Arduinos laying around for replacement!

:sunglasses: :sunglasses: :sunglasses:

PLC Analog / Digital Interface Bus Board (Part IV)

The 3 pin modular connector(s) A/D Bus Board was designed to accommodate Phidgets and Seeed Depot (China) compatible boards. There are many sensors and widgets, which can be easily connected to the Home Automation Gator PLC by the standard pinout format of (1)GND, (2)VCC, and (3)signal (analog or digital) on their three pin modular connectors.

Note: The PLC +5 VDC switching 1 amp. power supply supplies power from the I2C/+5 VDC bus board to all 3 pin modular connectors.

Links: FlexiForce Adapter - 1120_0 at Phidgets
http://www.seeedstudio.com/depot/electronic-brick-family-sensors-c-48_52.html (2 weeks shipping)

The following is just a sample that can be quickly connected to the 3 pin modular 5 VDC. input/output A/D PLC interface:

Sensors: ($USD)
<Distance/Range>
#1102 - IR Reflective Sensor $7.00 Phidgets
#1103 - IR Reflective Sensor $11.00 Phidgets
#1128 - Sonar Sensor $35.00 Phidgets
#2008 - IR Distance Sensor $25.00 Phidgets
Electronic Brick - Diffuse Ref. IR Switch $10.50 Seeed Depot
<Force/Pressure>
#1106 - Force Sensor $11.00 Phidgets
#1115 - Pressure Sensor $50.00 Phidgets
#1120 - FlexiForce Adapter (for below) $11.00 Phidgets
#3100 FlexiForce 0-1# Sensor $22.00 Phidgets
#3101 FlexiForce 0-25# Sensor $22.50 Phidgets
#3102 FlexiForce 0-100# Sensor $22.50 Phidgets
#1126 - Differential Gas Pressure Sensor $40.00 Phidgets

#1129 - Touch Sensor $11.00 Phidgets
Electronic Brick - Touch Sensor Module(Dig) $5.50 Seeed Depot

#1104 - Vibration Sensor $11.00 Phidgets
#1111 - Motion Sensor - PIR $45.00 Phidgets
Electronic Brick - PIR Motion Sensor $11.50 Seeed Depot

#1108 - Magnetic Sensor $11.00 Phidgets
#1124 - Precision Temp. Sensor $15.00 Phidgets
Electronic Brick - Temperature Sensor $3.50 Seeed Depot
#1125 - Humidity/Temp. Sensor (2 inputs) $50.00 Phidgets
#1127 - Precision Light Sensor $11.00 Phidgets
Electronic Brick - Light Sensor Cad. Sulf. $3.50 Seeed Depot
Electronic Brick - Carbon Monoxide Sensor $9.00 Seeed Depot <--- Note 1
Electronic Brick - Gas Sensor LPG/Nat.Gas. $6.90 Seeed Depot <--- Note 1
Electronic Brick - Gas Sensor LPG/Propane $9.90 Seeed Depot <--- Note 1
Electronic Brick - Smoke Sensor $6.90 Seeed Depot <--- Note 1

#1109 - Rotation Sensor $7.00 Phidgets
#1112 - Slider 60 Sensor $11.00 Phidgets
#1113 - Mini Joy Stick Sensor $15.00 Phidgets
#1116 - Multi-Turn Rotation Sensor $29.00 Phidgets
Electronic Brick - Multi Rotary Sensor (Pot) $8.50 Seeed Depot
Electronic Brick - Multi Angle Sensor (Pot) $3.50 Seeed Depot
Electronic Brick - Magnetism Switch (Dig.) $3.90 Seeed Depot
Electronic Brick - Mercury Tilt Switch (Dig) $1.50 Seeed Depot <--- Illegal in USA?
Electronic Brick - Joystick (D/A 3 inputs) $7.90 Seeed Depot
Electronic Brick - 5 VDC Relay (Digital) $7.90 Seeed Depot
Electronic Brick - Buzzer (Digital) $5.50 Seeed Depot
Electronic Brick - Microphone $9.50 Seeed Depot
Electronic Brick - LED (Digital) $3.50 Seeed Depot
Electronic Brick - Microphone $9.50 Seeed Depot
Electronic Brick - A/D Key Module $5.50 Seeed Depot
Electronic Brick - Big Button Switch (Dig.) $3.50 Seeed Depot
Electronic Brick - Dual Big Button Switch(D) $3.80 Seeed Depot
Electronic Brick - Tac Switch (Digital) $3.50 Seeed Depot
Electronic Brick - Rolling Ball Tilt SW(Dig) $3.50 Seeed Depot
<Voltage/Current>
#1122 - 30A Current Sensor AC/DC(2 inputs) $31.00 Phidgets
#1135 - Precision Voltage Sensor $19.00 Phidgets
#3500 - i-Snail-VC-10 Current Sensor 10A $40.00 Phidgets
#3501 - i-Snail-VC-25 Current Sensor 25A $40.00 Phidgets
#3500 - i-Snail-VC-50 Current Sensor 50A $40.00 Phidgets
#3501 - i-Snail-VC-100 Current Sensor 100A $40.00 Phidgets
Electronic Brick - Electricity Meter $11.50 Seeed Depot

Note 1: Calibration gas samples / equipment required for sensor calibration ---> $$$$$$
Sensor should not be used for the primary alert sensor for human (life) and protection!

Note 2. Some Phidget's sensors must be made of gold. By careful sensor inspection and reverse engineering, the cost of most of the sensors can be greatly reduced by installing the individual components on a perf board!

Note 3. We carefully choose sensors, which are connected to the PLC, which does not slow our polling scan time down significantly. Sensors which take complex math calculations, pulse and frequency reading and interrupts are never connected. There are always other sensors, to choose from, that will do the same function.

Note 4. Other sensors from sparkfun.com, parallax.com and futurlec.com could be easily adapted for the 3 pin 5 VDC analog and digital interface connector.

Note 5. All Arduino analog inputs should work with the above sensors. If you subtract 2 analogs for I2C Bus then you only have four left. The Gator/Gator+ has 8 usable analog inputs and maps the I2C Bus to other I/O pins to be compatible with the Arduino.

Note 6. One user said "that our Home Automation PLC could be used for a great Arduino instructional, training and development system" - great idea!

Note 7. Due to the Gator's I/O pin zener protection scheme, analog voltages above 4 VDC are slightly non-linear. Check their website for further details. Not a major problem, due to the usable input range of most sensors but you need to be aware.

:sunglasses: :sunglasses: :sunglasses:

Approximate cost estimation of Home Automation Gator PLC in $USD
(We used parts we had laying around for other projects for the Gator PLC)

It is extremely hard to compare the Home Automation Gator PLC with commercial units.
Our PLC has many design enhancements not found on commercial PLCs like the BLinkM RGB annunciator, a very accurate RTC (ChronoDot), external Watchdog, user adjustable photo inputs, and selectable digital outputs (AC or AC/DC loads using solid state and/or mechanical relays), an I2C bus for further analog expansion.

To do a fair comparison then all the PLC specs., hardware, software would have to be exactly the same.
Since, using a PLC, requires using I/O in an application for the end user, then a very crude comparison would be the cost per I/O point.

The Automation Direct probably has the lowest cost PLC in the industry, so a very crude cost comparison was made with our Home Automation Gator PLC. It will be quite obvious that making your own Arduino PLC is inexpensive. Being able to use the flexible Arduino programming language functions provides faster program development. The ability able to repair your own PLC yourself provides a great advantage to other commercial PLCs which cannot be fixed on site.

Automation Direct Click Series PLCs (needs 24 VDC power)
Part# CO-02DR-D 4 DC IN/ 4 Relay out, 2 channel analog In 2 channel analog out
Note: Software is Free
Note: Needs programming cable(s) to function - $14 (R3232 cable) & $29 (USB to RS232)

$139.00
$43.00

$182.00 Click PLC Total Cost

Total Click PLC $182 / 12 I/O points = Cost per usable I/O point ~$15 <-------<<<<<<

The approximate cost of the Home Automation Gator PLC Sub Modules:
(Excludes no tax, shipping cost, mounting hardware, misc. wiring, labor/ construction)

Gator Sub-Modules Cost USD:

Gator CPU + cable inc. $40.00 <--- 24 usable I/O points > Click PLC
5 VDC Power Supply $7.00 <--- Extra part not found on Click PLC
LCD 4x20 Display $24.00 <--- Extra part not found on Click PLC
Watchdog Bus Module $13.00 <--- Extra part not found on Click PLC (Also, reduces wiring)
BlinkM Annunciator $13.00 <--- Extra part not found on Click PLC
RTC ChronoDot $15.00 <--- More accurate part than Click PLC
Digital I/O (isolated) $50.00 <--- Flexible user defined (Digital Inputs / Outputs)
I2C Bus Module $12.00 <--- I2C (127 max.) slave expansion - Click has fixed analog I/O (Also,
reduces wiring)
A/D Bus Module $12.00 <--- Extra part not found on Click PLC (Also, reduces wiring)

$186.00 Total plus relays (see below)

Total Gator PLC $186 + $16 (8 @ $2 each - mechanical relays)
$202.00 / 24 I/O = Cost per I/O point ~$8.41 <-------<<<<

Note: Relays are extra! - Solid State relays are $4.00 each and Mechanical relays are $2.00 each - user definable per application.

Note: The Gator has 28 I/O points and 24 usable I/O points. Using the cost per I/O from the Click PLC and applying it to the Gator PLC comes out to be 24 x $15 = $360.

Note: 12 VDC input clean supply required plus dirty supplies for external devices.

:sunglasses: :sunglasses: :sunglasses:

Picture below is the close up of the A/D bus module of the PLC.
The LM34DZ (temp. sensor ) the TEMT6000 (ambient light sensor) and the PLC Piezo Buzzer are to the left.


:sunglasses: :sunglasses: :sunglasses:

The Home Automation Gator PLC Complete Panel - picture below.
PLC simulation, testing, debugging & software development is on-going ...
:sunglasses: :sunglasses: :sunglasses:

I think you really have something there. The power of a PLC with the potential to do things much faster than PLC's typically pathetic scan time.