Index
Introduction
In this post, we are going to explain how to do the basics in order of working with analog inputs of Industrial Shields programmable logic controllers. By reading this post, you will understand how to connect and configure the analog inputs of your industrial Arduino PLC controller.
Previous reading
We recommend you to read the following blogs in order to understand the program of this blog. We have used the following blog posts to do this example:
- How to program our industrial PLC with Arduino IDE:Â Installing Industrial Shields's boards in the Arduino IDE
Requirements
In order to work with analog inputs, you will need any of our industrial controllers for industrial automation.
Industrial Shields controllers:Â
Configuring the switches
Most of the analog inputs are always connected to the internal Arduino, but in a few cases, the user can choose between a special peripheral configuration or a GPIO by changing the position of the Dip 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 position (ON) in the upper one, the input I2.1 will be activated and we will be able to work with this as input. If the switch is in the left position (OFF) we will activate the SCL line which will be used for I2C communication. Keep in mind that each switch has two different configurations:Â you must select the right (ON) or the left (OFF) option.
.png?access_token=20ba813f-1668-4504-9ef3-97eabd5924ec)
I2.1 input enabled - SCL disabled
Â
.png?access_token=2d73eb81-6cc7-47b4-9776-8f44151f9ab4)
I2.1 input disabled- SCL enabled
Input types
In all of the Industrial Shields Arduino based PLCs, analog inputs can work at:
- 0V - 10V analog input
Analog inputs have a special draw in the case of the PLC:

0V - 10Vdc Analog input
 Â
Hardware
All the analog inputs are not optoisolated (they use the same GNDs as the PLC). The following image shows how to connect an analog input to the PLC:
.png?access_token=09b66b9d-0d82-411a-91b3-20636179a7f8)
0V - 10Vdc Analog input
 Â
Software
In order to program the analog GPIOs, we must keep in mind that we can read the values with the following command:
analogRead(GPIO);
This function returns a value between 0 and 1023 depending on the applied voltage level to the input (0V it is equal to 0, and 10V is equal to 1023).
GPIO is the name of the input. Imagine we want to know the state of the "I0.12" input, then, we must write this line:Â
analogRead(I0_12);
We must know that we do not need to configure the analog inputs as analog. Industrial Shields' libraries do all the work for us.
Example
You can see a read analog GPIO example in the following paragraph:
// Analog read example
    // Set the speed of the serial port
// This example reads the I0_12 and shows via serial the value
// Setup function
void setup()
{Â Â Â Â Serial.begin(9600UL);
pinMode(I0_12,INPUT); // Only required on ESP32 based PLC units}
    int value = analogRead(I0_12);
// Loop function
void loop()
{
    Serial.println(value);}
Learning the basics about analog inputs of an industrial PLC