Create a TCP connection between PLC Siemens S7-1200 and Arduino Uno or Mega

This how-to is meant to teach you how to establish a raw tcp connection between Arduino Uno/Mega and PLC Siemens S7-1200.

  1. Prerequisites:

    • Siemens PLC S7-1200
    • Arduino Uno/Mega
    • Ethernet shield or native Wi-Fi
    • Siemens Switch for LAN connections
    • TIA Portal
    • Arduino IDE
    • Ethernet library for Arduino (based on the shield used)
  2. Hardware Network Setup

    • PLC ethernet port > Switch
    • Ethernet shield > Switch
    • LAN cable from laptop > Switch for TIA portal
    • Set static IPs: 192.168.0.1 (for PLC, Device Configuration > PROFINET Interface) and 192.168.0.xx (for Arduino)
  3. Configuration in TIA Portal
    3.1. Add TCON and TSEND/TRCV instructions in Main_OB1

    • TCON - establish connection
      • Local Device: Active
      • Remote IP: 192.168.0.xx (Arduino’s IP address)
      • Remote Port: match Arduino server port
      • Active connection: TRUE
      • Type: TCP
    • TSEND - send data
    • TRCV - receive data
      3.2. Connections in Main_OB1 for TCON:
    • REQ - bool
    • CONNECT - “DB_TCP”.CONNECT (data block created specifically for TCP connection)
    • DONE - bool
    • BUSY - bool
    • ERROR - bool
    • STATUS - word

    3.3. Connections in Main_OB1 for TSEND/TRCV:

  4. Example of sending over the data in Main_OB1