PLC in Industrial Automation Systems
PLC (Programmable Logic Controller) is the brain controlling every industrial automation system. From food packaging lines, conveyor systems in warehouses, to HVAC control for buildings — PLCs are everywhere.
Siemens S7-1200 is the most popular PLC series in Vietnam due to reasonable pricing, sufficient performance, and broad ecosystem support. This article will take you from zero to writing your first PLC program.
S7-1200 Hardware Configuration
Popular CPUs
| CPU | DI/DO/AI | Memory | Use Case | Reference Price |
|---|---|---|---|---|
| 1211C | 6/4/2 | 50KB | Small machines, simple control | ~3.5M VND |
| 1212C | 8/6/2 | 75KB | Packaging machines, small conveyors | ~4.5M VND |
| 1214C | 14/10/2 | 100KB | Most popular, versatile | ~5.5M VND |
| 1215C | 14/10/2+2AO | 125KB | Complex systems, 2 Ethernet ports | ~7M VND |
Expansion Modules
Each CPU supports expansion:
- Signal Board (SB): Attach directly to CPU, add compact I/O
- Signal Module (SM): Separate expansion module, add DI/DO/AI/AO
- Communication Module (CM): RS232/RS485, PROFIBUS, AS-i
Example configuration for product sorting conveyor system:
- CPU 1214C DC/DC/DC (14 DI, 10 DO)
- SM 1231 AI (8 analog inputs for weight sensors)
- CM 1241 RS485 (Mitsubishi frequency drive connection)
- SB 1232 AQ (1 analog output for speed control)
Programming with TIA Portal
TIA Portal (Totally Integrated Automation) is Siemens' integrated development environment. Version V17 and above are recommended for full OPC UA support and improvements.
Program Structure
A TIA Portal project is organized as:
Project
├── PLC_1 [CPU 1214C]
│ ├── Program blocks
│ │ ├── OB1 (Main) — Main program, runs each cycle
│ │ ├── FB1 (Motor_Control) — Function Block for motor control
│ │ ├── FC1 (Calculate_Speed) — Function for calculation
│ │ └── DB1 (Motor_Data) — Data Block storing parameters
│ ├── Technology objects
│ │ └── PID_Compact — PID controller
│ └── PLC tags
│ └── Tag table — Physical I/O mapping
Ladder Diagram (LAD)
Most intuitive language, suitable for on/off logic control. Easy for electricians to read and maintain:
// Motor self-holding circuit
|---[ I0.0 ]---[/I0.1 ]---( Q0.0 )---| I0.0: START button
| | I0.1: STOP button (NC)
|---[ Q0.0 ]--------------------------| Q0.0: Motor contactor
// Sequential control of 3 conveyor belts
|---[ I0.0 ]---[TON T1, 2s]---( Q0.0 )---| Belt 1: start immediately
|---[ Q0.0 ]---[TON T2, 3s]---( Q0.1 )---| Belt 2: delay 2s
|---[ Q0.1 ]---[TON T3, 3s]---( Q0.2 )---| Belt 3: delay additional 3s
Function Block Diagram (FBD)
Suitable for analog processing and PID algorithms. Example: oven temperature control:
┌─────────────┐
│ PID_Compact │
│ │
│ Setpoint ──┤── 180.0 (°C)
│ Input ─────┤── IW64 (Thermocouple)
│ Output ────┤── QW80 (Heater SSR)
│ Kp ────────┤── 2.5
│ Ti ────────┤── 10.0s
│ Td ────────┤── 1.0s
└─────────────┘
Structured Text (SCL)
High-level language similar to Pascal, for complex algorithms. Recommended for complex logic:
// Temperature control with hysteresis and alarm
FUNCTION_BLOCK "FB_TempControl"
VAR_INPUT
Temperature : REAL; // Measured temperature
SetPoint : REAL; // Target temperature
Hysteresis : REAL; // Deadband (typically 2-5°C)
AlarmHigh : REAL; // High alarm threshold
AlarmLow : REAL; // Low alarm threshold
END_VAR
VAR_OUTPUT
HeaterOutput : BOOL;
CoolerOutput : BOOL;
AlarmActive : BOOL;
END_VAR
// Control logic
IF Temperature > SetPoint + Hysteresis THEN
HeaterOutput := FALSE;
CoolerOutput := TRUE;
ELSIF Temperature < SetPoint - Hysteresis THEN
HeaterOutput := TRUE;
CoolerOutput := FALSE;
END_IF;
// Check alarm
AlarmActive := (Temperature > AlarmHigh) OR (Temperature < AlarmLow);
SCADA Connection and Monitoring
S7-1200 supports multiple connection protocols from firmware V4.4:
OPC UA (Recommended)
OPC UA is the industrial standard for M2M communication. S7-1200 V4.4+ has integrated OPC UA Server:
# Python client reading data from PLC via OPC UA
from opcua import Client
client = Client("opc.tcp://192.168.0.1:4840")
client.connect()
# Read temperature from PLC
temp_node = client.get_node("ns=3;s=\"DB_Process\".\"Temperature\"")
temperature = temp_node.get_value()
print(f"Current temperature: {temperature}°C")
# Write setpoint
sp_node = client.get_node("ns=3;s=\"DB_Process\".\"SetPoint\"")
sp_node.set_value(180.0)
client.disconnect()
S7 Protocol + Node-RED
For quick and flexible solutions:
{
"nodes": [
{
"type": "s7 in",
"address": "DB1,REAL0",
"name": "Read Temperature",
"interval": 1000
}
]
}
Integrated Web Server
S7-1200 has an integrated web server allowing simple HTML dashboards. Suitable for basic monitoring without separate SCADA.
Integrating PLC with Robot (ROS 2)
The most interesting part — connecting PLC with modern robot systems. Hybrid PLC + ROS 2 architecture leverages:
- PLC: Stable, deterministic, handles safety I/O per robot safety standards
- ROS 2: Flexible, AI/ML, path planning, computer vision
┌─────────────────────────────────────────┐
│ ROS 2 System │
│ ┌──────────┐ ┌──────────┐ ┌───────┐ │
│ │ Nav2 │ │ MoveIt2 │ │ Vision│ │
│ │ (AMR) │ │ (Arm) │ │ (CV) │ │
│ └────┬─────┘ └────┬─────┘ └───┬───┘ │
│ └──────────────┼────────────┘ │
│ ┌───────┴───────┐ │
│ │ OPC UA Bridge │ │
│ └───────┬───────┘ │
└──────────────────────┼──────────────────┘
│ OPC UA
┌──────────────────────┼──────────────────┐
│ ┌───────┴───────┐ │
│ │ S7-1200 PLC │ │
│ └───────┬───────┘ │
│ ┌──────────────┼────────────┐ │
│ ┌────┴─────┐ ┌─────┴────┐ ┌───┴───┐ │
│ │ Sensors │ │ Actuators│ │ Safety│ │
│ │ (I/O) │ │ (Motor) │ │ (E-Stop)│ │
│ └──────────┘ └──────────┘ └───────┘ │
│ PLC Layer │
└─────────────────────────────────────────┘
Debugging and Best Practices
Diagnostic Buffer
S7-1200 logs the last 50 events. Always check diagnostic buffer when errors occur:
- TIA Portal → Online & Diagnostics → Diagnostic buffer
Tips from Real Experience
- Always use Symbolic names — Set meaningful tag names (
Motor_Conveyor_1_Runinstead ofQ0.0) - Backup project to Git — TIA Portal projects are directories, version-controllable
- Comment every network — You'll forget logic after 6 months without comments
- Use FB instead of FC when state needed — FB has instance DB, FC doesn't
- Test on PLCSIM first — TIA Portal has simulator, test logic before downloading to real PLC
- Monitor cycle time — Keep cycle time < 10ms for motion, < 100ms for HVAC
Common Errors
| Error | Cause | Solution |
|---|---|---|
| Red SF LED | Hardware fault | Check diagnostic buffer |
| Connection failure | IP conflict or firewall | Ping PLC, check subnet mask |
| Program download fail | CPU in STOP mode | Switch to RUN, re-download |
| Incorrect analog reading | Scaling not correct | Check input range (0-27648 = 0-10V) |
Advice for Beginners
- Hardware: Start with CPU 1214C DC/DC/DC — reasonable price (~5.5M VND), sufficient features for learning and real projects
- Software: Use TIA Portal V17+ for full OPC UA and simulator support
- Learning path: LAD → SCL → FB/DB → OPC UA → Robot integration
- Community: Join Siemens Vietnam Facebook group, Siemens Support forums
- Certification: Siemens SITRAIN program — international certification valuable for career