Look for in our Blog. You will find multiple applications, solutions, code examples. Navigate using the tag cloud or search using specific criteria

How to connect Arduino based PLC with Siemens PLC equipped with Ethernet Port


On this post it is showed how to connect Industrial Shields Arduino based PLC (M-Duino‘s) with a Siemens PLC equipped with Ethernet port or communication processor. Any PLC is supported except for old S5 family. To do that we have to use SettiminoSettimino is an open source Ethernet library for interfacing Arduino with Siemens S7 PLC’s. CPU’s 1200/1500 LOGO 0BA7 and S7200 are also supported. Download Settimino


Ethernet PLC:          MDuino Family Products

Ethernet2 Library:             Arduino Ethernet2.h library

Siemens PLC with Ethernet connection


Once we have all the requirements, we can proceed to explain how it works. The main class is S7Client object that is able to connect and transfer data between Arduino based PLC and Siements PLC. Ethernet W5100 chip support 4 clients and uses a one data buffer for the entire client because just one can be connected at the same time. This data buffer can contain just one PDU (see the Siemens communication to know what that means).

The PDU variable is global, this means that is visible from the sketch. See an example (consult the syntax of the S7Client to get a better understanding).

This is the PDU defined on Settimino.h:

typedef struct {
   byte H [ Size_WR ];                      Header PDU //
   byte Data [ Shift + MaxPduSize-Size_WR ];  // Data PDU
TPDU PDU; // Declaration

The H matrix contains the protocol header and Data matrix contains the payload.

Transferring big data:

byte mybuffer [1024]; // 1K matrix
Cliente.ReadArea(S7AreaDB , 24, 0, 1024, y mybuffer);

We are saying that the client can access to database 24, to read from 0 to 1024 bytes y handle into mybuffer.

Transferring small data:

Cliente.ReadArea(S7AreaDB, 24, 0, 64, NULL);
Serial.println (PDU.DATA [0]); // Printing the first byte
Serial.println (PDU.DATA [1]); // Printing the second byte and so on ...

We are saying that the client can access to the database 24, read 64 bytes from 0 to 64 and handle into the internal buffer.

To write we have to do it on the same way putting data to PDU.DATA[] and then call WriteArea().


The Siemens data is Big-enidan and the Arduino data is Little-endian. S7Helper is an object that allows to extract values right to left with an intermediate format memory bytes. The name of the request is S7.

Supposing that we want to load this database:

AddressNameTypeInitial valueComment
0.0 Struct  
=10.0 END_STRUCT  


flotar pressure;
unsigned long Encoder;
int16_t components;
// getting 10 bytes from 0
Client.ReadArea(S7AreaDB , 100, 0, 10, y mybuffer);

My buffer will contain a serial disorder of bytes.

To access to this fills we can write:

Pressure = S7.FloatAt (y mybuffer , 0);
Encoder = S7.DWordAt (y mybuffer , 4);
Componeny = S7.IntegerAt (y mybuffer , 8);

Models Memory

To optimize even more the print, tree memory models are available: small, normal and extended.

Even though extended model works perfectly on Arduino Leonardo and Arduino Mega, it is possible that you wish reduce even more the using memory. For example, Settimino Client can control the Stop mode or Run mode of the PL, but if you just need read/write data you don’t need this feature. 

To establish memory model that you need simply to modify the directive on the beginning of the Settimino.h writing:

#define _SMALL
#define _NORMAL
#define _EXTENDED

The small model has the minimum group of functions to connect to a PLC and reading/writing data.

The normal mode has the S7Helper.

Finally the extended model has also the remaining extended functions.

By default Settimino is released as Extended.

Configuration S7 1200:

  • On DB properties you must select "Access optimized to the block" on attribute tab.
  • On protection area of the PLC properties you just must select "Complete access (without protection)" and "Allow access PUT/GET communication from PLC, HMI, OPC…"