In compliance with high industry standards

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

How to create a TCP Client on an Arduino based PLC


On this post is showed how to connect to a server TCP from an industrial Arduino based PLC controller. The requirements of this post is just an M-Duino PLC for industrial automation with Ethernet connection and available TCP server. 


Ethernet PLC:      Ethernet PLC     

Industrial Shields boards:   Industrial Shields Boards


Before starting with this post, take a look at this example. It consists on implementing a TCP SERVER ON TOUCHBERRY PI 3 WITH NODE.JS

Once the server is running, the M-Duino industrial PLC can connect to the server. On this example it is used an industrial controller M-Duino to connect with the Node.js server called server.js, the same as used on previous example link.

To configure the M-Duino, this post just follows the TCP example from Arduino web site with a few changes. To be able to connect to the server we must know the TCP server IP and the port where this server is listening. 


Next it is showed the Arduino code:

#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0xBE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 100 };
byte server[] = { 192, 168, 1, 105 }; // Touchberry Pi Server
int tcp_port = 5566;

EthernetClient client;

void setup()
  Ethernet.begin(mac, ip);



  if (client.connect(server, tcp_port)) { // Connection to server.js
    Serial.println("Connected to server.js");
  } else {
    Serial.println("connection failed");

void loop()
  if (client.available()) {
      char s =;
      client.write(s); // Send what is reed on serial monitor
      char c =;
      Serial.print(c); // Print on serial monitor the data from server 

  if (!client.connected()) {


For more information see on Arduino web site the TCP functions Ethernet / Ethernet 2 library

Once the sketch is running on the M-Duino, through the serial monitor it’s possible to send data to the server and this data is replied and printed also on serial monitor. On this example is typed “Hello server.js” to the serial monitor. Next is showed two screenshot with the response of this operation, one of the server.js on the Raspberry and second of the M-Duino serial monitor:

 Check our blog to solve your technical doubts or learn more about our products.

Looking for your ideal PLC?

Take a look at this product comparison with other industrial controllers Arduino.

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.

Industrial PLC controller comparison >>

Do you want more information?

Just fill the form!

Tell me more!