The Arduino PLC IDE offers multiple possibilities to expand the connectivity of your industrial applications. The integration of the PLC IDE with the Arduino IoT Cloud allows you to create advanced HMI for your professional solutions that can be controlled in real-time in multiple ways and devices.
In this comprehensive tutorial, you will learn how to integrate and utilize the Arduino IoT Cloud with the Arduino PLC IDE. The tutorial covers the process of connecting your compatible devices and creating a compact, cloud-connected application using Opta™.
If you have an Opta™, you do not need any license key to activate your product. Go to section License Activation With Pre-Licensed Products (Opta™) to know more.
The Arduino Cloud will be required to perform remote actuation and status monitoring via Wi-Fi® connectivity using the sketch provided in the following section. In case you do not have an account, you can create one for free inside cloud.arduino.cc.
To ensure optimal Wi-Fi® connectivity on Opta™, please use the
WiFiFirmwareUpdater
to update with the latest network firmware version. This can be done by going to Examples -> STM32H747_System -> WiFiFirmwareUpdater
on Arduino IDE 2.X. Additionally, please ensure that you have the latest Arduino Mbed OS Opta Boards version, which can be checked under Boards Manager
.PLC IDE & Arduino IoT Cloud integration example project file compatible with Opta™
This tutorial requires the latest versions of the PLC IDE & PLC IDE Tools ( >= v 1.0.4 ). You can get the latest versions here for the latest PLC IDE and its tools. If it is your first time using the Arduino PLC IDE, we highly recommend you to begin with Arduino® PLC IDE Setup & Device License Activation.
In this present tutorial, we will be utilizing two distinct platforms: the Arduino PLC IDE and the Arduino IoT Cloud. Each of these tools brings unique features and capabilities to the table, making them integral to our workflow.
The Arduino PLC IDE integrates the capability to use IEC IEC61131-3 programming languages, which are Ladder Diagram (LD), Sequential Function Chart (SFC), Function Block Diagram (FBD), Structured Text (ST), and Instruction List (IL). All these languages are applicable to Opta™.
A wide set of standard features are included with these PRO solutions to develop industrial automation or advanced applications. You can find more tutorials related to the PLC IDE at the arduino documentation page and the latest version of the software can be downloaded here.
The IoT Cloud is a platform that allows users to deploy IoT applications with ease and control parameters at any given moment. The platform provides robust security characteristics, of which Opta™ takes advantage to provide secure industrial application deployments. You can find more about Arduino IoT Cloud at here.
The PLC IDE supports seamless integration with Arduino IoT Cloud, enabling IoT capabilities for its compatible devices. The application field can be expanded thanks to this feature with the needed security elements, ensuring stable industrial operations.
The structure comprises two elements:
The device is programmed in two layers: The PLC main execution program and the Arduino sketch. To communicate and interchange data in a safe way between these two different program layers, the PLC IDE use 'Shared variables' between these two layers. The functions of each layer are:
The PLC program layer will manage internal communication and data handling. It can be programmed to read sensor information that is obtained via selected Modbus protocol or available I/O pins. Then use this data to send out to or receive from the Arduino sketch layer.
The Arduino sketch will handle data exchange bound between the PLC program layer and the Arduino IoT Cloud platform. The methods are 'PLCOut.varname' and 'PLCIn.varname', which are used to access the shared variables. For the purpose of the tutorial and to easily classify these methods, we will replace the 'varname' with the 'Shared_variable' tag.
Therefore, the 'PLCOut.Shared_Variable' and 'PLCIn.Shared_Variable' methods manage the shared variables that facilitate the communication between the two systems:
PLCOut.Shared_Variable: This variable refers to the data that is being sent from the PLC program layer to the Arduino sketch layer, which will be sent to Arduino IoT Cloud.
In other words, it represents the outputs from the PLC program. It could be sensor readings, status information, or any other data that the PLC program is designed to generate and share.
PLCIn.Shared_Variable: Conversely, this variable refers to the data that is being sent to the PLC from the Arduino sketch layer, received from the Arduino IoT Cloud platform.
These are inputs for the PLC program. It could be commands, configuration data, or other information that the Arduino IoT Cloud system sends to control or interact with the PLC.
In most industrial IoT applications, the PLC program layer will be responsible for direct control of machinery or processes based on its programming, while the Arduino IoT Cloud platform will often be used as an HMI for operators, analytics, and remote control capabilities. The
Shared_Variables
commands allow in both cases real-time communication between these two layers.A demonstrative example will be used to show how both features are integrated. The example will consist of an Arduino IoT Cloud dashboard and a PLC IDE project file configured for an Opta™ device.
Opta™ will be programmed to execute the following actions:
The following diagram shows the main steps to connect Opta™ to the Arduino IoT Cloud using the PLC IDE. In the following sections you will find how to perform all of these steps in detail.
The example implementation comprises the following sequence:
We will begin by configuring the Arduino IoT Cloud with Opta™ to create a Thing. It will have Opta™ registered with cloud variables and a dashboard configured to perform different actions.
To learn more about how to use the Arduino IoT Cloud, please take a look at Getting Started With the Arduino IoT Cloud tutorial.
The following cloud variables will be created:
Cloud Variables | Type | Variable Permission | Send Values |
---|---|---|---|
analog01 | Float (0 - 65535) | Read Only | On change |
counter | Integer (0 - 2500) | Read Only | On change |
cloudButton | Boolean | Read & Write | On change |
The cloud variables will subsequently be linked to the 'Shared variables' within the PLC IDE environment to set up the communication pathway. Furthermore, the table displays a full 16-bit resolution range for 'analog01', as it can be paired with any chosen analog sensor. The 'counter' is set with a default limit of 2500, beyond which the device will reset to 0. If necessary, this limit can be adjusted in the PLC program, as elaborated further in this tutorial.
Once the Arduino IoT Cloud Thing has been created successfully, we will have something similar to the following image:
We can now extract the code that will serve as the base for the Arduino sketch for Opta™ in the PLC IDE. The code can be accessed by going to the full editor. It will require some of the lines from the
ThingProperties.h
.Please follow:
Things -> "Opta PLC IDE Cloud" Thing -> Sketch -> Open full editor
, of which 'Opta PLC IDE Cloud' is the name of your created Thing, to get to the full editor window.The base sketch of the example will be as follows:
1#include <ArduinoIoTCloud.h>2#include <Arduino_ConnectionHandler.h>3
4const char SSID[] = "SECRET_SSID"; // Network SSID (name)5const char PASS[] = "SECRET_OPTIONAL_PASS"; // Network password (use for WPA, or use as key for WEP)6
7void onCloudButtonChange();8
9float analog01;10int counter;11bool cloudButton;12
13WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PA14void setup() {15 // Initialize serial and wait for port to open:16 Serial.begin(9600);17 // This delay gives the chance to wait for a Serial Monitor without blocking if none is found18 delay(1500); 19
20 // Defined in thingProperties.h21 initProperties();22
23 // Connect to Arduino IoT Cloud24 ArduinoCloud.begin(ArduinoIoTPreferredConnection);25 26 /*27 The following function allows you to obtain more information28 related to the state of network and IoT Cloud connection and errors29 the higher number the more granular information you’ll get.30 The default is 0 (only errors).31 Maximum is 432 */33 setDebugMessageLevel(2);34 ArduinoCloud.printDebugInfo();35}36
37void loop() {38 ArduinoCloud.update();39 // Your code here 40}41
42void initProperties(){43 ArduinoCloud.addProperty(analog01, READ, ON_CHANGE, NULL);44 ArduinoCloud.addProperty(counter, READ, ON_CHANGE, NULL);45 ArduinoCloud.addProperty(cloudButton, READWRITE, ON_CHANGE, onCloudButtonChange);46}47
48/*49 Since CloudButton is READ_WRITE variable, onCloudButtonChange() is50 executed every time a new value is received from IoT Cloud.51*/52void onCloudButtonChange() {53 // Add your code here to act upon CloudButton change54}
Save this example template for later. We will now proceed with a demonstrative example to show you how to set up the PLC IDE to be connected to the Arduino IoT cloud "Thing" we just created.
Before continuing with the PLC IDE configuration with Opta™, please remember to have the latest PLC IDE with its corresponding tools stated within Software Requirements.
The PLC IDE configuration will play an important role in establishing successful communication with the Arduino IoT Cloud. It will require setting onboard features and the communication protocol for Opta™ as usual. However, a proper 'Shared variables' setting will define the communication outcome with the Arduino IoT Cloud.
Thus, you will learn to configure the 'Shared variables' based on the peripherals and tasks you may assign to Opta™.
The successful communication between Opta™ configured with PLC IDE and Arduino IoT Cloud relies on the 'Shared variables'. The 'Shared variables' is defined by heading to
Resources > Opta > Shared variables
. It will then offer two additional tabs: 'Inputs' and 'Outputs'.
The 'Inputs' define variables that will capture the data that comes from the Arduino IoT Cloud through the local Arduino sketch to Opta™ PLC main program runtime. It is the compilation of variables that the Arduino IoT Cloud will send accordingly.
Subsequently, the user programmable LED will be controlled via Arduino IoT Cloud dashboard. We will define a variable so that it can be assigned later to update LED state variable accordingly.
The
in_cloudButton
will represent user programmable LED of Opta™ as a two state variable and indicates that is an input variable with the in
tag.The 'Outputs' define the variables that Opta™ will send to Arduino IoT Cloud. It is the compilation of variables that you would want to monitor within the Arduino IoT Cloud dashboard.
The analog port reading and the counter value of Opta™ are the information that we want to display on the Arduino IoT Cloud dashboard. It can be programmed to use Modbus-compatible devices and use its information for further development.
The following table shows the variables added to the 'Shared outputs' table.
The shared output variables are indicated with an
out
tag and represent the following information:out_analog01
: Analog port number one readingout_counter
: Counter valueThe same variable name is used to maintain variable relationship and simplicity with the Cloud variables that we have defined here previously.
Depending on the project's development requirements, you can add all the variables that will be used to exchange information with the Arduino IoT Cloud.
We will now configure Opta™ device's features to link all these shared variables.
The analog port is configured using the following properties under:
Resources > Opta > Local IO Mapping > Programmable Inputs
.Analog Port | Name | Variable | IO Type | Type |
---|---|---|---|---|
#1 | I1 | analog01 | Analog | UINT |
Opta™ has available 8x I/O ports that can be programmed either as analog or digital. You will select port number one and assign the
analog01
as the variable. The 'IO Type' must be 'Analog' and the 'Type' will update based on the selection of the 'IO Type' property.The 'Programmable inputs mapping' table should look as the following image:
You can also change the analog resolution if needed between 12, 14, or 16 bits.
The user programmable LED of Opta™ is configurable under
Resources > Opta > Local IO Mapping > LED Outputs
. To use the user programmable LED, you will need to assign a variable that will represent the 'LB' row as it can be seen in the following image:
In this case, the
userLed
is assigned as the variable that will represent the user programmable LED of Opta™ that emits blue light. The userLed
is a boolean type variable as well as the in_cloudButton
. It will be matched inside the PLC program to pass the boolean state per the command sent from the Arduino IoT Cloud dashboard.The Library section would be where you could find various pre-written codes or functions specific to PLC operations. It could include libraries for handling several industrial protocols, dealing with specific types of I/O, or even specialized functions for certain control systems. It makes the development process more efficient by providing ready-to-use codes, saving time and effort.
In the context of the PLC IDE, the libraries will need to be added manually under the
Sketch Libraries
found within the 'Resources' tab. These libraries are required to manage Arduino IoT Cloud connection and it is as follows:Library Name | Version |
---|---|
ArduinoIoTCloud | 1.11.2 |
Arduino_ConnectionHandler | 0.7.6 |
ArduinoECCX08 | 1.3.7 |
ArduinoMqttClient | 0.1.7 |
Arduini_DebugUtils | 1.4.0 |
Arduino_Portenta_OTA | 1.1.3 |
Once the libraries are in place within
Sketch Libraries
, we should have a similar table as the following image:
These libraries are indexed, thus they are certified guaranteeing optimized performance and reliability. Leveraging them will not only speed up your development process but also increase the robustness of your applications for industrial environments. It may seem an extra step but it will help you keep cleaner, more reliable, and maintainable code.
For more information about managing libraries inside PLC IDE, please have a look at "Library Management" section from the Programming Introduction with Arduino PLC IDE.
We can now build the Arduino sketch that will be used to establish communication with the Arduino IoT Cloud and manage data traffic. The base sketch will be needed and can be found as discussed in the 'Setting Up the Arduino IoT Cloud' section.
Most of the code will keep the same structure contrary to the
loop()
and onCloudButtonChange()
functions. It will integrate the 'Shared variables' with the PLCOut.Shared_Variable
or PLCIn.Shared_Variable
to establish information exchange between the device and platform.Beginning with the
loop()
function, we have the following code:1void loop() {2 ArduinoCloud.update();3 4 analog01 = PLCOut.out_analog01;5 counter = PLCOut.out_counter;6}
The
loop()
function is used to periodically update the analog01
and counter
variables with the shared output variables. The shared output variables are out_analog01
and out_counter
, and they are attached to PLCOut
.This means that the PLC program, which is capturing the analog port reading and updating the counter value, is defined to bring the data to the Arduino sketch layer and update the cloud variables accordingly. The Arduino IoT Cloud dashboard then displays updated information after the
ArduinoCloud.update()
method based on the cloud variables, which are analog01
and counter
.The
onCloudButtonChange()
function is cloud generated and designed to process similar tasks. Every time a new value is updated from the Arduino IoT Cloud, the function will be triggered and run the assigned tasks. In this instance, it will update the user programmable LED of Opta™ whenever a change is detected with the assigned dashboard button.1/*2 Since CloudButton is READ_WRITE variable, onCloudButtonChange() is3 executed every time a new value is received from IoT Cloud.4*/5void onCloudButtonChange() {6 // Add your code here to act upon CloudButton change7 PLCIn.in_cloudButton = cloudButton;8}
The exact process involves assigning the updated cloud variable value to the
PLCIn.in_cloudButton
variable. It will update the shared variables attached to PLCIn
, which is the in_cloudButton
, and pass its value to the PLC program layer updating the status of Opta™.Consequently, you will have an Opta™ constantly exchanging information with the Arduino IoT Cloud. The complete code for the Arduino sketch is as follows:
1#include <ArduinoIoTCloud.h>2#include <Arduino_ConnectionHandler.h>3
4const char SSID[] = "NETWORK_SSID"; // Network SSID (name)5const char PASS[] = "NETWORK_PASS"; // Network password (use for WPA, or use as key for WEP)6
7void onCloudButtonChange();8
9bool cloudButton;10float analog01;11int counter;12
13WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);14
15void setup() {16 // Initialize serial and wait for port to open:17 Serial.begin(9600);18 // This delay gives the chance to wait for a Serial Monitor without blocking if none is found19 delay(1500); 20
21 // Defined in thingProperties.h22 initProperties();23
24 // Connect to Arduino IoT Cloud25 ArduinoCloud.begin(ArduinoIoTPreferredConnection);26 27 /*28 The following function allows you to obtain more information29 related to the state of network and IoT Cloud connection and errors30 the higher number the more granular information you’ll get.31 The default is 0 (only errors).32 Maximum is 433 */34 setDebugMessageLevel(2);35 ArduinoCloud.printDebugInfo();36}37
38void loop() {39 ArduinoCloud.update();40 41 analog01 = PLCOut.out_analog01;42 counter = PLCOut.out_counter;43}44
45void initProperties(){46 ArduinoCloud.addProperty(cloudButton, READWRITE, ON_CHANGE, onCloudButtonChange);47 ArduinoCloud.addProperty(counter, READ, ON_CHANGE, NULL);48 ArduinoCloud.addProperty(analog01, READ, ON_CHANGE, NULL);49}50
51/*52 Since CloudButton is READ_WRITE variable, onCloudButtonChange() is53 executed every time a new value is received from IoT Cloud.54*/55void onCloudButtonChange() {56 // Add your code here to act upon CloudButton change57 PLCIn.in_cloudButton = cloudButton;58}
The
NETWORK_SSID
and NETWORK_PASS
requires to be manually defined. Please replace these parameters to establish a connection with the desired network. Also, the parameters must be defined in between the quotation marks, replacing NETWORK_SSID
and NETWORK_PASS
fields.The Arduino sketch is ready and now we need a PLC program that will control the onboard features of Opta™ and data readings.
The PLC program will do the following processes:
cnt
, and pass the data to out_counter
(Shared variables)in_cloudButton
(Shared variables)analog01
and passing it to out_analog01
(Shared variables)The following code delivers the previous tasks:
1cnt := cnt + 1;2out_counter := cnt;3
4IF out_counter >= 2500 THEN5 cnt := 0;6END_IF;7
8userLed := in_cloudButton;9
10out_analog01 := analog01;
With this PLC program, we are all set to configure Opta™ device's internal processes and use Arduino sketch to establish a connection with the Arduino IoT Cloud.
For a good practice, we will set the present PLC program as a 'Fast Task'. It can be done by adding the
main
, which is the present PLC program we will use, to Tasks -> Fast
under Project
window tab.
The Arduino IoT Cloud dashboard can be designed to your preference. The following image shows a dashboard example that allows for the control of the user programmable LED and the display of information received from Opta™.
More information about Arduino IoT Cloud & how to create dashboards can be found here.
The complete example project file for PLC IDE can be downloaded here. It is ready to use with Opta™ in the instance at the preferred workspace.
The first compilation process may take some time to finish. It can take around 7 minutes or more depending on the environment and hardware used.
Once we have successfully configured Opta™ with PLC IDE and established communication with the Arduino IoT Cloud dashboard, we have the following tasks in action:
The animation below shows a simple active desktop dashboard:
The mobile dashboard is also available if on-demand monitoring and actuation is needed:
If Opta™ fails to communicate with the Arduino IoT Cloud after configuration, please use the
to update Opta™ with the latest network firmware version.WiFiFirmwareUpdater
You have now set an Opta™ using PLC IDE and successfully connected to the Arduino IoT Cloud platform. You learned how these tools integrate and can be used to create a simple interface allowing you to oversee Opta™ device's status. Now you are now more familiar with the PLC IDE and Arduino IoT Cloud environment, being capable of creating advanced HMI interfaces that can be used to control and monitor your Industrial Arduino Pro devices.
As you progress, feel free to delve into the vast Arduino ecosystem. It will encourage you to utilize an array of libraries and hardware enhancements to construct robust, secure, and interconnected industrial solutions with the Arduino Pro products. For a deeper understanding of the Arduino PLC IDE, consider reviewing the available tutorials.
If you encounter any issues or have questions while working with the PLC IDE or Arduino IoT Cloud, we provide various support resources to help you find answers and solutions.
Explore our Help Center, which offers a comprehensive collection of articles and guides for the PLC IDE or Arduino IoT Cloud. The Arduino Help Center is designed to provide in-depth technical assistance and help you make the most of your device.
Join our community forum to connect with other PLC IDE and Arduino IoT Cloud users, share your experiences, and ask questions. The forum is an excellent place to learn from others, discuss issues, and discover new ideas and projects related to PLC IDE and Arduino IoT Cloud.
Please get in touch with our support team if you need personalized assistance or have questions not covered by the help and support resources described before. We're happy to help you with any issues or inquiries about the PLC IDE and Arduino IoT Cloud.