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

Using the SoftwareSerial library in Arduino PLC industrial controller


There are situations in which, we want to use the serial ports of the equipment but these are already occupied, or, as is the case of the PLC controller of the Ardbox family, that the default serial port of the Arduino Leonardo incorporated inside is occupied by the RS-232  or RS-485 protocols.

It is then, when using Hardware we can not use the physical serial ports of the equipment and there are two possible solutions:

The first and most economically costly is to use an RS-232 to TTL converter (We lose the use of the RS-232 protocol).

The second is the one that we explain in this post and consists in taking advantage of the SoftwareSerial library to simulate a serial port through Software. 


Ethernet or 20 I/Os PLC:    Ethernet PLC          20 I/Os PLC

SoftwareSerial Library:       SoftwareSerial Library


For the Arduino Ardbox Family (20 IOs PLCs) controllers:

    For the Ardbox family (Arduino Leonardo incorporated) all pins can be used for Tx while for Rx the following can be used:

    pin 14 of Leonardo (SO), pin 15 of Leonardo (SCK) or pin 16 of Leonardo(SI). 

    We recommend using one of the Rx-enabled pins for Tx.

For the M-Duino Family controllers:

  For the M-Duino family (Arduino Leonardo incorporated) all pins can be used for Tx, while for the Rx the following can be used: 

  pin 50 of the Arduino Mega 2560 (SO), pin 51 of the Arduino Mega (SI), Pin 52 of the Arduino Mega (SCK).

 We recommend using one of the Rx-enabled pins for Tx.


This sketch is very simple and shows how the library works. First, the Tx and Rx pins of the equipment for the Serial Software must be defined (we are trying it on an Ardbox Family model) :
SoftwareSerial mySerial(14, 15); // RX, TX

Rx is digital pin 14 (SO), connected to TX of the other device.
Tx is digital pin 15 (SI), connected to RX of the other device.

Receives from the serial hardware, sends to software serial, receives from software serial, sends to hardware serial

#include <SoftwareSerial.h>

SoftwareSerial mySerial(14, 15); // RX (MISO), TX (SCK)

void setup()  
  // Open serial communications and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
mySerial.begin(9600); mySerial.println("Hello, world?"); } void loop() // run over and over
{ if (mySerial.available())
if (Serial.available())
mySerial.write(; }

This other sketch sends instructions through the software serial: 

#include <SoftwareSerial.h>

SoftwareSerial mySerial(14, 15);  // Rx (MISO, Tx (MOSI)

void setup() {

  // put your setup code here, to run once:




void loop() {

  // put your main code here, to run repeatedly:


mySerial.println("Instruction 1"); 

Serial.println("1st instruction sended");


mySerial.println("Instruction 2"); 

Serial.println("2nd instruction sended");


Do you want more information?

Open Source technology allows you to develop your installations.

Just fill the form and we will contact you as soon as we can.