Index
Introduction
In this post, we are going to explain how to do the basics when working with digital inputs of Industrial Shields PLC controller. With this post, you will be able to understand how to connect and configure the PLCs to be sure you will be able to read the digital inputs.
Previous reading
We recommend you to read the following blogs in order to understand the program of this blog. We used the following blog posts to do this example:
- Knowing how to program our industrial PLC with Arduino IDE:Â Installing the Industrial Shields's boards in the Arduino ID
Requirements
In order to work with digital inputs you will need any of our PLC for industrial automation:
- Industrial Shields controllers: ESP32 Controller Family, Ethernet Controller Family, GPRS / GSM Controller Family or 20IOs Controller Arduino Family
Configuring the switches
Almost all the digital inputs are always connected to the internal Arduino, but in a few cases, the user can choose a special peripheral configuration or a GPIO normally working.
In these cases, the user can choose between two options through the switches
Each switch can select only one configuration. For example, in this case, we are watching the GPIOs configuration of an M-Duino 57R+. If we put the switch to the right in the upper one, the input I2.1 will be activated and we will be able to work with this input as digital. If the switch is in the left position, we will activate the SCL line which will be used for I2C communication. Keep in mind each switch has two different configurations: you must select the right or the left option.
I2.1 input enabled - SCL disabled
I2.1 input disabled - SCL enabled
Input types
There are three different types of inputs in the Industrial Shields PLCs:
- 5V - 24V input
- 5V - 24V optoisolated input
- 5V input
Each one has a particular draw in the case of the PLC. Remember only the Pin 2 and Pin 3 are 5V compatibles:
5V - 24V optoisolated input
Â
5V - 24V input
Â
5V input
Hardware
Not all the inputs must be connected in the same way. While the non-isolated inputs must be referenced to the same ground as the PLC, the isolated inputs can be connected to the input grounds, allowing to isolate systems from the PLC. Anyway, the optoisolated input can be connected to the PLC ground as well.
The following images show how to connect the different inputs to the PLC for industrial automation:
5V - 24V optoisolated input
Â
5V - 24V input
Â
5V input
Software
In order to program the digitals GPIO, we must keep in mind we can read the values with the following command:
digitalRead(GPIO);
This function returns "0" or "1" depending of the actual value of the input. GPIO is the name of the input. Imagine we want to know the state of the "I0.4" input, then, we must write this line:
digitalRead(I0_4);
digitalRead(I0_4);
The inputs "2" and "3" does not have a special name, and for read them we must write:
digitalRead(2);
digitalRead(3);
digitalRead(2);
digitalRead(3);
We must keep in mind we do not need to configure the digital inputs of the PLC as digital ones, except with the 5V compatible inputs. It means we must configure the inputs in the setup before read them:
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(2,INPUT);
pinMode(3,INPUT);
Examples
You can see a read digital GPIO example in the following paragraph:
// Digital read example
// This example reads the I0_10, I0_2 and Pin 2 inputs, and shows via serial if they are active
// Setup function
void setup()
{
   Â
    // Set the speed of the serial port
    Serial.begin(9600UL);
    // Configure Pin 2 as a digital input
    pinMode(2, INPUT);
pinMode(I0_10,INPUT); // Only required in ESP32 family PLCs
pinMode(I0_2, INPUT); // Only required in ESP32 family PLCs
}
// Loop function
void loop()
{
    // Check Pin 2
    if (digitalRead(2)){
        Serial.println("Pin 2 active");   Â
    }
    // Check I0_10
    if(digitalRead(I0_10)){
        Serial.println("I0_10 active");
    }
    // Check I0_2
    if(digitalRead(I0_2)){
        Serial.println("I0_2 active");
    }
}
// Digital read example
   Â
// This example reads the I0_10, I0_2 and Pin 2 inputs, and shows via serial if they are active
// Setup function
void setup()
{Â Â Â Â // Set the speed of the serial port
    Serial.begin(9600UL);
    // Configure Pin 2 as a digital input
    pinMode(2, INPUT);
pinMode(I0_10,INPUT); // Only required in ESP32 family PLCs
pinMode(I0_2, INPUT); // Only required in ESP32 family PLCs}
    // Check Pin 2
// Loop function
void loop()
{Â Â Â Â if (digitalRead(2)){
        Serial.println("Pin 2 active");   Â
    }    // Check I0_10
    if(digitalRead(I0_10)){
        Serial.println("I0_10 active");
    }
    // Check I0_2
    if(digitalRead(I0_2)){
        Serial.println("I0_2 active");
    }
}
Basics about digital inputs of an industrial controller