Busca en nuestro Blog. Encontrarás múltiples aplicaciones, soluciones, ejemplos de código. Navega utilizando la nube de etiquetas o busca utilizando criterios específicos

TCP Client on Arduino based PLC


On this post is showed how to connect to a server TCP from Arduino based PLC. The requirements of this post is just an M-Duino PLC 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, M-Duino can connect to the server. On this example it is used an 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 = Serial.read();
      client.write(s); // Send what is reed on serial monitor
      char c = client.read();
      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:

¿Quieres más información?

Con la tecnología Open Source, puedes ejecutar tus propias instalaciones.

Rellena el formulario y contactaremos contigo lo más pronto posible.

Enviar  Por favor, completa el formulario correctamente.