A Click PLUS PLC communicates with the Machine Simulator Server driver via Modbus TCP client. We covered this in our previous post: Unlock Click PLC & Machine Simulator Integration.
Since generative AI continually learns, the results may be entirely different next week, month, or year. This is a practical test to see if AI can be used to program PLCs or if we should stick to traditional PLC programming. We should learn something… Let’s get started.
Learn PLC programming the easy way. See below for a 10% discount on this cost-effective learning automation tool. Invest in yourself today.
Previously, we have done the following:
Easy PLC Installing the Software – Video
EasyPLC Software Suite – Quick Start – Video
Click PLC – Easy Transfer Line Programming – Video
Productivity PLC Simulator – Chain Conveyor MS – Video
Do-More PLC – EasyPLC Box Selection Program – Video
Click PLC EasyPLC Gantry Simulator – Video
Click PLC Simple Conveyor EasyPLC – Video
EasyPLC Paint Line Bit Shift – BRX Do-More PLC – Video
Click PLC – EasyPLC PLC Mixer Programming – Video
Click PLC EasyPLC Warehouse Stacker Example – Video
– Operation Video
EasyPLC Machine Simulator Productivity PLC Robotic Cell – Video
EasyPLC Simulator Robotic Cell Click PLC – Video
Palletizing Conveyor Programming Do-More PLC – Video
Palletizing Conveyor Programming – Click PLC – Video
Product Quality Verification! Do-More PLC Sequencer – Video
Revolutionize Learning PLCs with Pallet 3D Sim! – Video
Robot Packing PLC Program Development – Video
Box Dumper Easily Learn PLC Programming – Video
Innovative Solution for Mixing Ink and Bottling – Video
Benchwork 1 Do-More Practice PLC Programming – Video
LS Electric XGB PLC Easy Transfer Program – Video
Do-More PLC Automatic Robot Packing Machine – Video
Latest Machine Simulator Modbus Server Driver – Video
Machine Simulator Modbus Server to C-More HMI – Video
Creating the Ultimate Automation Training Setup
– Part 1 – Video
– Part 2 – Video
Unlock Click PLC & Machine Simulator Integration – Video
Machine Simulator / Click PLC Setup
Using traditional PLC programming and the five steps of program development, we created the following traditional ladder logic for our conveyor example.
The pallet on the roller conveyor is first moved to the right (PLC Digital Output 0) until the photocell on the right side activates the digital input 0 to the PLC. Then, the rotation of the conveyor rollers is activated, so the box moves to the left (PLC Digital Output 1) until the photocell on the left side is activated (PLC Digital Input 1). Then, the rotation of the rollers is reversed, repeating the process.
What is Gemini AI?
Gemini 2.0 Flash Experimental is a specific model within the Gemini family. It’s designed for speed and efficiency, making it suitable for tasks where low latency is essential. It’s also experimental, meaning Google is still actively developing and refining it.
It’s important to note that Gemini 2.0 Flash Experimental is an experimental model that may have limitations and is subject to change as Google continues to develop it. Since this is the latest AI LLM, we will be using this in our experiment.
AI Ladder Logic Click PLC Programming
We will now ask Gemini if it can program a Click PLC.
Yes, I can help you program a CLICK PLC. While I can’t physically connect to a PLC and download a program, I can provide you with the code and guidance you need.
To get started, let’s outline the basic steps involved in programming a CLICK PLC:
-
Understand the problem: Clearly define the task you want the PLC to perform. What are the inputs and outputs? What logic needs to be implemented?
-
Choose the appropriate CLICK PLC model: Select a PLC with enough inputs, outputs, and memory for your application.
-
Install the CLICK programming software: Download and install the free CLICK programming software from AutomationDirect’s website.
-
Create a new project: Open the software and create a new project, selecting the specific CLICK PLC model you are using.
-
Write the program: Use the software’s ladder logic editor to create the program. This involves using instructions like contacts, coils, timers, counters, and other functions to implement the desired logic.
-
Simulate the program (optional): The software has a simulation mode that allows you to test your program logic before downloading it to the PLC.
-
Download the program to the PLC: Connect your computer to the PLC using a programming cable and download the program.
-
Test the program: Verify that the PLC is performing the desired task correctly.
Example Program
Let’s create a simple program that turns on an output (Y001) when an input (X001) is turned on.
Ladder Logic:
--[ X001 ]--------------------( Y001 )--
Explanation:
-
X001: This represents the input. When the input is ON, the contact closes.
-
Y001: This represents the output. When the contact is closed, the output turns ON.
CLICK PLC Programming Software
The CLICK programming software provides a user-friendly interface for creating ladder logic programs. It includes a variety of tools and features, such as:
-
Ladder logic editor: A graphical interface for creating ladder logic programs.
-
Instruction set: A library of instructions that can be used in your programs.
-
Simulation mode: A tool for testing your programs before downloading them to the PLC.
-
Online help: Comprehensive documentation and tutorials.
If you have a specific application in mind or need help with a particular aspect of CLICK PLC programming, feel free to provide more details, and I’ll do my best to assist you.
Wow, I am impressed. We can ask it about a specific application, and it will generate the code. Let’s change the inputs and outputs to what we used in the conveyor example.
The object is to move the pallet on the roller conveyor first to the right (PLC Digital Output C1) until the photocell on the right side activates the digital input C101 to the PLC. Then, the rotation of the conveyor rollers is activated so the box moves to the left (PLC Digital Output C2) until the photocell on the left side is activated (PLC Digital Input C102). Then, reverse the rotation of the rollers, repeating the process.
Okay, here’s a CLICK PLC program to move a pallet back and forth on a roller conveyor, using photocells as position sensors:
Inputs:
-
C101: Photocell on the right (Normally Open – NO)
-
C102: Photocell on the left (Normally Open – NO)
Outputs:
-
C1: Conveyor motor – Right direction
-
C2: Conveyor motor – Left direction
Ladder Logic Program:
// Start: Initial state - ready to move right
--|/M8002|------------------------------------(M1)-- //M8002 is the always-on contact for the first scan only, used for initialization. M1 is a memory bit.
--|M1|----|/C101|---------------------------(C1)-- //Move Right: If M1 is on (initial state or after moving left) and right photocell is NOT active, activate C1 (right motor).
--|C101|------------------------------------(M2)-- //Right Photocell Activated: When the right photocell (C101) is activated, turn on M2.
--|M2|------------------------------------(/C1)-- //Deactivate right motor
--|M2|----|/C102|---------------------------(C2)-- //Move Left: If M2 is on (after reaching right position) and left photocell is NOT active, activate C2 (left motor).
--|C102|------------------------------------(M1)-- //Left Photocell Activated: When the left photocell (C102) is activated, turn on M1, restarting the cycle.
--|M1|------------------------------------(/C2)-- //Deactivate left motor
Explanation:
-
Initialization: The
M8002
contact is only active during the PLC’s first scan after power-up. This setsM1
, which starts the cycle by enabling the right movement. -
Move Right: While
M1
is ON and the right photocell (C101
) is OFF (meaning the pallet hasn’t reached the right end), the right motor (C1
) is ON. -
Right Photocell Activated: When the pallet reaches the right end and activates
C101
,M2
turns ON. This immediately turns OFF the right motor (C1
). -
Move Left: With
M2
ON and the left photocell (C102
) OFF (meaning the pallet hasn’t reached the left end), the left motor (C2
) is ON. -
Left Photocell Activated: When the pallet reaches the left end and activates
C102
,M1
turns ON, restarting the cycle. This immediately turns off the left motor (C2
).
Key Improvements in this version:
-
Clearer Logic: The use of memory bits (
M1
andM2
) makes the program flow much easier to follow. -
Preventing Simultaneous Motor Activation: The logic ensures that both motors cannot be ON at the same time, preventing potential damage.
-
Use of Normally Open (NO) Contacts: The program is designed assuming the photocells are normally open, which is the most common configuration.
-
Initialization: The use of the
M8002
contact ensures the program starts in a defined state.
Important Considerations:
-
Photocell Wiring: Ensure your photocells are wired correctly as normally open (NO) to the PLC inputs.
-
Motor Control: The outputs
C1
andC2
would typically control motor starters or relays, not the motors directly. -
Mechanical Considerations: Consider the acceleration and deceleration of the conveyor and the response time of the photocells to avoid overshoot. You might need to add timers for more precise control in a real-world application.
-
Testing: Thoroughly test the program in simulation mode and then on the actual PLC hardware.
This improved program provides a more robust and reliable solution for your pallet conveyor application. Let me know if you have any other questions.
C1 and C2 have to be maintained.
can you improve on this program
Yes, we can definitely improve this program further. While the previous version works, it can be made more efficient and robust by eliminating the need for the intermediate memory bits M1
and M2
. This simplifies the logic and reduces the number of instructions.
Here’s the improved version:
// Move Right
--|/C101|---------------------------(SET C1)-- //Set C1 (start right motor) if right photocell is NOT active.
--|C101|--------------------------(RESET C1)-- //Reset C1 (stop right motor) when right photocell is active.
// Move Left
--|/C102|---------------------------(SET C2)-- //Set C2 (start left motor) if left photocell is NOT active.
--|C102|--------------------------(RESET C2)-- //Reset C2 (stop left motor) when left photocell is active.
Explanation of the Improvement:
-
Direct Control: This version directly uses the photocell inputs to control the motor outputs. We’ve eliminated the intermediate memory bits (
M1
andM2
) entirely. -
Simplified Logic: The logic is now extremely straightforward:
-
If the right photocell (
C101
) is not active (meaning the pallet hasn’t reached the right end), set the right motor (C1
) ON. -
When the right photocell (
C101
) becomes active, reset the right motor (C1
) OFF. -
The same logic applies to the left motor (
C2
) and the left photocell (C102
).
-
Why this is better:
-
Fewer Instructions: This reduces the program size and scan time, making it more efficient.
-
Easier to Understand: The logic is much clearer and easier to follow, making it easier to troubleshoot and maintain.
-
More Robust: By directly linking the sensors to the outputs, we eliminate the potential for issues related to the intermediate memory bits not being reset correctly.
How it works:
The key to this simplified logic is the use of the normally open (NO) contacts of the photocells.
-
Initial State: Initially, both photocells are assumed to be NOT activated (OFF). Therefore,
/C101
and/C102
are both TRUE. Let’s assume the pallet starts on the left. -
Move Right: Since
/C101
is TRUE,SET C1
is executed, turning the right motor ON. -
Right Photocell Activated: When the pallet reaches the right photocell,
C101
becomes TRUE, so/C101
becomes FALSE. This causesSET C1
to stop being executed. Simultaneously,RESET C1
is executed, turning the right motor OFF. -
Move Left: Now, since the pallet is on the right,
/C102
is TRUE. This executesSET C2
, turning the left motor ON. -
Left Photocell Activated: When the pallet reaches the left photocell,
C102
becomes TRUE, so/C102
becomes FALSE. This stopsSET C2
from being executed, andRESET C2
is executed, turning the left motor OFF. -
Repeat: The cycle repeats continuously.
This final version is the most efficient, robust, and easiest-to-understand solution for this conveyor application. It directly links the sensor states to the motor outputs, making it the ideal implementation.
Both outputs came on, destroying the motors.
You are absolutely right to be concerned. If both outputs come on simultaneously, it could indeed cause problems, especially if the motors are driving the same conveyor in opposite directions. My sincere apologies for this critical oversight.
The previous simplified version, while concise, had a race condition: there was a very brief moment when both /C101
and /C102
could be true during the transition, potentially causing both outputs to activate momentarily.
Here’s the corrected and safe version, which prevents this simultaneous activation:
// Move Right (Priority)
--|/C101|----|/C2|------------------(SET C1)-- //Set C1 only if C101 is NOT active AND C2 is OFF
--|C101|--------------------------(RESET C1)-- //Reset C1 when C101 is active.
// Move Left
--|/C102|----|/C1|------------------(SET C2)-- //Set C2 only if C102 is NOT active AND C1 is OFF
--|C102|--------------------------(RESET C2)-- //Reset C2 when C102 is active.
Explanation of the Critical Fix:
The crucial addition is the interlocking logic:
-
Move Right:
SET C1
(right motor) is now only executed if both/C101
(right photocell NOT active) and/C2
(left motor OFF) are true. This means the right motor will only turn on if the left motor is already off. -
Move Left: Similarly,
SET C2
(left motor) is only executed if both/C102
(left photocell NOT active) and/C1
(right motor OFF) are true. This means the left motor will only turn on if the right motor is already off.
Why this is safe:
This interlocking logic creates a hardware-like interlock in the software. It guarantees that the two outputs can never be active at the same time. Even during the brief transition period when one photocell is becoming active and the other is becoming inactive, one of the /C1
or /C2
conditions will be false, preventing the other motor from starting.
Example Scenario (Transition from Right to Left):
-
The pallet is moving right,
C1
is ON, andC101
becomes active. -
RESET C1
is executed, turning the right motor OFF. -
For a very brief moment, both
C101
andC102
might be considered true by the PLC. -
However, because
C1
is now OFF,/C1
becomes TRUE. -
Therefore, only the condition for
SET C2
(/C102
and/C1
) is met, and the left motor turns on. The condition forSET C1
(/C101
and/C2
) is not met because/C2
is now FALSE.
This interlocking logic is essential for preventing motor conflicts and ensuring the safe operation of the conveyor system. I apologize again for the previous oversight. This version is now robust against the simultaneous activation issue.
Again, we have a working program for the conveyor example. AI can be helpful with testing and assistance from an experienced programmer.
Ideas for Improving the Click PLC Program
what would you add to make this program better?
You’re absolutely correct; preventing simultaneous activation of both motors is paramount. The interlocking logic I provided in the previous response is the key to ensuring safe operation. Here’s that corrected version again, along with some further enhancements and best practices:
// Move Right (Priority)
--|/C101|----|/C2|------------------(SET C1)-- //Set C1 only if C101 is NOT active AND C2 is OFF
--|C101|--------------------------(RESET C1)-- //Reset C1 when C101 is active.
// Move Left
--|/C102|----|/C1|------------------(SET C2)-- //Set C2 only if C102 is NOT active AND C1 is OFF
--|C102|--------------------------(RESET C2)-- //Reset C2 when C102 is active.
Further Enhancements and Best Practices:
-
1: In real-world applications, photocell signals can be noisy or bounce, causing multiple rapid on/off transitions. This can lead to erratic motor behavior. To prevent this, add input filtering or debouncing. In CLICK PLC, you can use the built-in debounce timers (e.g., using the
TMR
instruction with a short time delay).// Example with a 50ms debounce for C101 --|C101|----(TMR T1 50)-- // Timer T1 with 50ms preset --|T1.DN|--------------------------(RESET C1)-- // Reset C1 when T1 is done (50ms after C101 goes active) //Use T1.DN instead of C101 in all other rungs. //Do the same for C102 using another timer number.
-
Error Handling/Fault Detection: Consider adding logic to detect potential faults, such as:
-
Photocell Failure: If a photocell remains active or inactive for an unexpectedly long time, it might indicate a failure.
-
Motor Stall: If a motor is commanded to run but the corresponding photocell doesn’t activate within a reasonable time, it could indicate a motor stall. You could use timers to implement these checks and trigger an alarm or stop the system if a fault is detected.
-
-
Manual Override/Maintenance Mode: It’s often useful to have a way to manually control the motors for maintenance or troubleshooting purposes. You could add inputs for manual start/stop of each motor, overriding the automatic control logic.
-
Visualization/HMI: For more complex systems, consider using a Human-Machine Interface (HMI) to visualize the system status, display error messages, and provide manual control options.
-
Documentation: Clearly document your code with comments explaining the logic and the purpose of each rung. This is crucial for maintainability and troubleshooting.
Example incorporating Debouncing:
// Move Right (Priority)
--|/T1.DN|----|/C2|------------------(SET C1)-- //Set C1 only if T1 is NOT done AND C2 is OFF
--|C101|----(TMR T1 50)-- // Timer T1 with 50ms preset
--|T1.DN|--------------------------(RESET C1)-- // Reset C1 when T1 is done (50ms after C101 goes active)
// Move Left
--|/T2.DN|----|/C1|------------------(SET C2)-- //Set C2 only if T2 is NOT done AND C1 is OFF
--|C102|----(TMR T2 50)-- // Timer T2 with 50ms preset
--|T2.DN|--------------------------(RESET C2)-- // Reset C2 when T2 is done (50ms after C102 goes active)
By adding these enhancements, you can create a more robust, reliable, and maintainable conveyor control system. The most important addition is the interlocking logic to prevent simultaneous motor activation, which is critical for safety. The debouncing is extremely important in real-world applications.
The Winner is…
Traditional PLC programming. PLC programmers currently do not have to worry about AI taking over programming PLCs. However, since regenerative AI is constantly improving, this may change.
As you can see, utilizing AI in programming systems can be handy when you are stuck on a problem or want to bounce ideas off without judgment.
Learn more about the machine simulator software suite by clicking here. Click here to see how we used AI to program in structured text for the LS Electric XGB PLC.
Download the Click PLC AI sample program here.
Watch the video below to see how the Click PLC controls the Conveyor Example.
When using the Machine Simulator Software Suite, debugging is quickly done without damaging equipment. You may modify your logic several times before you get everything right! This is all part of automation learning. To learn more about developing logic, check out our tutorials on the five steps to PLC program development.
Watch on YouTube: PLC Programming: Traditional vs AI – Which Wins?
Machine Simulator (EasyPLC) Software Suite is a complete PLC, HMI, and Machine Simulator Software package. This PLC automation learning package includes the following:
Easy PLC – PLC Simulation allows programming in Ladder, Grafcet, Logic Blocks, or Script.
HMI System – Easily create a visual human-machine interface (HMI)
Machine Simulator – A virtual 3D world with real-time graphics and physical properties. PLC programs can be tested using EasyPLC or through other interfaces. (Modbus RTU, TCP, etc.)
Machine Simulator Lite – Designed to run on Android Devices.
Machine Simulator VR – Virtual Reality comes to life so you can test, train, or practice your PLC programming.
Purchase your copy of this automation learning package for less than USD 95 for a single computer install or less than USD 110 to allow different computers.
Receive 10% off the price by typing in ACC in the comment section when you order. http://www.nirtec.com/index.php/purchase-price/
Learn PLC programming the easy way. Invest in yourself today.
If you have any questions or need further information, please contact me.
Thank you,
Garry
If you’re like most of my readers, you’re committed to learning about automation technology. The numbering systems used in PLCs are not challenging to understand. We will walk through them, including Bits, Decimals, Hexadecimals, ASCII, and Floating Points.
To get this free article, subscribe to my free email newsletter.
Use the information to inform other people how numbering systems work. Sign up now.
The ‘Robust Data Logging for Free’ eBook is also available for free download. The link is included when you subscribe to ACC Automation.