0:03
Can AI program a PLC?
0:06
I gave an AI one task. Write a complete
0:09
conveyor control program in structured
0:11
text for the ACC PLC simulator.
0:15
Start the motor, detect the box with
0:16
proximity sensors, reverse direction,
0:18
stop automatically, and handle a
0:20
restart. Then I pasted the AI generated
0:23
PLC code into the simulator, connected
0:25
the 3D conveyor scene, and pressed run.
0:27
Here is what happened.
0:30
Detailed information in this video is
0:32
available at accccclautomation.ca.
0:34
A link is in the description below. The
0:37
website offers extensive links,
0:39
references, and coding samples, making
0:41
it a one-stop shop for all your
0:42
automation queries. Once again, that is
0:52
the conveyor scene has six IO points. X1
0:54
is start, normally open. X2 is stop,
0:58
normally closed, true at rest. X3 is the
1:00
left proximity sensor. X4 is the right
1:02
proximity sensor. Y1 is motor run. Y2 is
1:05
direction, where off is forward and on
1:07
is reverse. I typed the full
1:09
specification into Claude and asked it
1:11
to write the program.
1:16
What the AI produced?
1:18
I was not expecting this. Claude did not
1:21
write two lines of boolean logic. It
1:24
produced a full state machine with
1:26
variable declarations, a one-shot on the
1:28
start button, stop priority logic, and a
1:30
case statement for state transitions,
1:36
idle, forward, and reverse. The outputs
1:38
are derived from the state variable at
1:40
the bottom of the program. It even came
1:43
fully commented with an IO table and
1:45
sequence description.
1:49
The one shot. The AI added a one-shot on
1:53
the start button using two variables.
1:56
Start pulse fires for exactly one scan
1:58
when X1 transitions from false to true.
2:01
Without this, holding start would
2:03
immediately restart the cycle the
2:04
instant the box reaches the left sensor.
2:08
The AI anticipated this edge case before
2:10
I even asked about it. That surprised
2:17
Claude wrote, "If not X2, then state
2:20
equals zero." Since X2 is normally
2:22
closed and true at rest, not X2 is false
2:25
at rest. When stop is pressed, X2 goes
2:27
false, not X2 becomes true and the state
2:29
drops to idle immediately. This runs
2:32
before everything else in the program.
2:33
If stop is pressed or the wire breaks,
2:35
the machine stops. Correct failsafe
2:38
behavior on the first attempt.
2:45
The case statement handles the
2:48
State one is forward. When X4 goes true,
2:52
the box has reached the right sensor and
2:53
the state moves to two reverse.
2:57
State two is reverse. When X3 goes true,
3:00
the box has reached the left sensor and
3:02
the state moves to zero idle.
3:05
Clean and readable. [music]
3:06
One transition per state.
3:13
I pasted the code and connected the
3:32
Cycle one. Pressed start. Box traveled
3:34
forward. Hit the right sensor. Direction
3:36
reversed. Box traveled back. Hit the
3:38
left sensor. Motor stopped. Correct.
3:44
Cycle two. Press start again. Motor
3:46
started. Full cycle repeated.
3:51
The oneshot handled the restart
3:53
perfectly. I tested stop during forward
3:55
travel. Motor stopped. Stop during
3:57
reverse. Motor [music] stopped. Rapid
4:00
start presses. No issues. Power up
4:01
state. All correct. Every test passed.
4:04
If you are enjoying this video, please
4:06
hit the like button below. Keeping up
4:08
with the latest automation innovations
4:10
can be difficult. So, hit subscribe.
4:12
Remember to hit the bell beside your
4:13
subscription to receive notifications.
4:18
Where the human is still needed.
4:21
The code worked. Every test passed.
4:24
But that does not mean you should
4:25
blindly trust it. I spent 20 minutes
4:28
tracing the scan order in step mode to
4:30
confirm the oneshot runs before the stop
4:32
check, which runs before the case
4:33
transitions, which run before the
4:37
I verified the not x2 logic. A
4:39
programmer who does not understand why
4:41
not x2 means stop is pressed could
4:43
easily misread this code. I checked
4:45
variable initialization and I found one
4:47
edge case worth discussing.
4:50
If start and stop are pressed
4:51
simultaneously, the behavior depends on
4:53
scan order. In most applications, you
4:56
want stop to win unconditionally.
5:03
The AI produced better code than I
5:07
A state machine with a oneshot stop
5:09
priority, failsafe behavior, and clean
5:12
comments. It worked on every test.
5:15
But I still had to trace every line to
5:17
understand it. The AI does not know your
5:19
machine. It does not know your company
5:22
If you cannot explain what every line of
5:24
code does, do not put it on a real PLC.
5:27
AI can help you write it, understand it,
5:29
and check it, but you have to stand
5:36
Open the ACC PLC simulator at
5:39
accccclautomation.ca/simulator.
5:44
Switch to ST mode. Ask your favorite AI
5:46
to write a conveyor program. Paste the
5:48
code in. Connect the conveyor scene.
5:52
Then trace every line in step mode until
5:54
you can explain it. You will learn more
5:57
from verifying the code than from