← Back to Blog
otherplcautomation

Siemens S7-1200 PLC Programming: From Basics to Application

Overview of PLC programming with TIA Portal — from hardware configuration, ladder diagram writing to SCADA integration in automation systems.

Nguyen Anh Tuan10 tháng 4, 20256 min read
Siemens S7-1200 PLC Programming: From Basics to Application

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.

Siemens PLC in industrial control cabinet

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:

Example configuration for product sorting conveyor system:

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

SCADA system monitoring factory

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:

┌─────────────────────────────────────────┐
│              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:

Tips from Real Experience

  1. Always use Symbolic names — Set meaningful tag names (Motor_Conveyor_1_Run instead of Q0.0)
  2. Backup project to Git — TIA Portal projects are directories, version-controllable
  3. Comment every network — You'll forget logic after 6 months without comments
  4. Use FB instead of FC when state needed — FB has instance DB, FC doesn't
  5. Test on PLCSIM first — TIA Portal has simulator, test logic before downloading to real PLC
  6. 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

Related Articles

Related Posts

Tự động hóa nhà máy điện tử Bắc Ninh: Bài học thực tế
amrautomationfleet

Tự động hóa nhà máy điện tử Bắc Ninh: Bài học thực tế

Phân tích quá trình tự động hóa tại các nhà máy điện tử FDI ở Bắc Ninh — thách thức, giải pháp và bài học cho doanh nghiệp Việt.

19/2/202610 min read
Top 5 Cobot 2026: UR vs Doosan vs FANUC vs ABB vs Techman
robot-armcobotautomation

Top 5 Cobot 2026: UR vs Doosan vs FANUC vs ABB vs Techman

So sánh 5 hãng cobot phổ biến nhất — payload, tầm với, giá thành và ứng dụng thực tế cho nhà máy Việt Nam.

13/1/202612 min read
AGV vs AMR: Chọn gì cho nhà máy Việt Nam?
amrautomationfleet

AGV vs AMR: Chọn gì cho nhà máy Việt Nam?

So sánh chi tiết AGV và AMR — chi phí, tính linh hoạt, ROI và hướng dẫn chọn loại phù hợp cho nhà máy sản xuất tại Việt Nam.

5/1/202610 min read