Getting Started with Opta™

Get started with the Opta™ and get to know some of its features.


The Opta™ is a robust micro PLC solution with many engaging features. In this tutorial, we will go through setting up Opta™ with the Arduino IDE and explain how to use its basic features. It includes examples to show how to program the LEDs on the device, how to use the programmable button, as well as to control its inputs and outputs.

The Opta™


  • Learn how to put Opta™ to work with the Arduino IDE
  • Learn how to blink the LEDs on the Opta™
  • Learn how to program the button on the Opta™
  • Learn how to test the inputs and outputs on the Opta™
  • Learn how to connect the Opta™ to the Arduino Cloud

Required Hardware and Software

  • Opta™ PLC (x1)
  • USB-C® cable (x1)
  • Arduino IDE 1.8.10+, Arduino IDE 2, or Arduino Web Editor
  • Power supply of 12-24V DC, 1A (optional if not running the section related to the relays) (x1)
  • Analog inputs (optional, alternatively the section related to analog inputs will work but reading random values)


Setup with the Arduino IDE

Make sure the latest version of the Arduino IDE is installed. The IDE can be downloaded here.

Within the Arduino IDE install the core for the Opta™. Go to Tools > Board > Boards Manager, in the board's manager section search for Opta mbed and install it.

Finding the Opta™ Core in the Arduino IDE 2
Finding the Opta™ Core in the Arduino IDE 2

Now you are ready to upload sketches to the Opta™ via the Arduino IDE.

Once the IDE and the core are installed, let's warm up by uploading a first sketch to your Opta™. We will be using a modified version of the classical Arduino blink sketch to put your device to work and test if everything is set properly.

Let's create a simple blink sketch that will blink the four STATUS LEDs on the Opta™, highlighted in the image below.

The blinking STATUS LEDs on the Opta™

All the STATUS LEDs on the device are defined in the core of the PLC.

Hereafter you can see the correspondence between each of them as identified in the core and their labeling on the front panel of the product:

  • LED_D0
    : STATUS 1
  • LED_D1
    : STATUS 2
  • LED_D2
    : STATUS 3
  • LED_D3
    : STATUS 4
    : LED above the reset button
    : LED above the user button (only available on the Opta™ with Wi-Fi®/Bluetooth® Low Energy connectivity features)

Select the correct board and port in the Tools section. Copy the sketch below into the Arduino IDE sketch editor, then upload it to Opta™. When the sketch is uploaded you will see the Opta™ device's STATUS LEDs blinking in sequence.

2 Getting Started with Opta™
3 Name: LED_Blink_Opta
4 Purpose: Blink STATUS LEDs on Opta™.
6 @author Arduino
9void setup() {
10 pinMode(LED_D0, OUTPUT);
11 pinMode(LED_D1, OUTPUT);
12 pinMode(LED_D2, OUTPUT);
13 pinMode(LED_D3, OUTPUT);
16void loop() {
17 digitalWrite(LED_D0, HIGH);
18 delay(100);
19 digitalWrite(LED_D0, LOW);
20 delay(100);
22 digitalWrite(LED_D1, HIGH);
23 delay(100);
24 digitalWrite(LED_D1, LOW);
25 delay(100);
27 digitalWrite(LED_D2, HIGH);
28 delay(100);
29 digitalWrite(LED_D2, LOW);
30 delay(100);
32 digitalWrite(LED_D3, HIGH);
33 delay(100);
34 digitalWrite(LED_D3, LOW);
35 delay(500);

Configuring the Programmable Button on the Opta™

The Opta™ has a programmable button, shown in the image below, identified as USER. It can be programmed using the Arduino IDE to fit your needs. To show how simple it is, let's create a sketch and program the button as a trigger to modify the status of the STATUS LEDs.

The button and STATUS LEDs that will light up on the Opta™

The button is defined in the core as

: 'HIGH' as default (not pressed), and 'LOW' when pressed. The new sketch will turn the STATUS LEDs on one by one when the button is pressed and then start over when all the lights have been turned on. Below you can find the entire sketch, where a simple Switch (case) Statement is used, and an image highlighting where the USER button is located on the device.

2 Getting Started with Opta™
3 Name: Programmable_Button_Opta
4 Purpose: Configures the programmable button to control STATUS LED sequence.
6 @author Arduino
9int buttonState = 0;
10int counter = 0;
12void setup() {
13 // Initialize OPTA LEDs
14 pinMode(LED_D0, OUTPUT);
15 pinMode(LED_D1, OUTPUT);
16 pinMode(LED_D2, OUTPUT);
17 pinMode(LED_D3, OUTPUT);
18 pinMode(BTN_USER, INPUT);
21// The loop function runs over and over again while the device is on
22void loop() {
23 buttonState = digitalRead(BTN_USER);
24 if(buttonState == LOW){
25 if(counter < 4){
26 counter++;
27 }
28 else{
29 counter = 0;
30 }
31 delay(100);
32 }
33 changeLights();
37 Function to control STATUS LED based on the counter.
39void changeLights() {
40 switch(counter){
41 case 0:
42 digitalWrite(LED_D0, LOW);
43 digitalWrite(LED_D1, LOW);
44 digitalWrite(LED_D2, LOW);
45 digitalWrite(LED_D3, LOW);
46 break;
47 case 1:
48 digitalWrite(LED_D0, HIGH);
49 break;
50 case 2:
51 digitalWrite(LED_D1, HIGH);
52 break;
53 case 3:
54 digitalWrite(LED_D2, HIGH);
55 break;
56 case 4:
57 digitalWrite(LED_D3, HIGH);
58 break;
59 }
60 delay(100);

Once the sketch is uploaded, you can see that an additional LED is turned on each time you press the button, following the sequence:

First pressSTATUS LED 1 ON
Second pressSTATUS LEDs 1 and 2 ON
Third pressSTATUS LEDs 1, 2 and 3 ON
Fourth pressSTATUS LEDs 1, 2, 3 and 4 ON
Fifth pressAll STATUS LEDs off and counter reset

Using Output Relays of Opta™

The Opta™ has 4 relay outputs, consisting of 4 normally-open electromechanical relays (SPST) with a capacity of 10A at 250V AC (considering a resistive load). They are identified as OUTPUTS and located on the bottom of Opta™, as shown in the image below.

Output relays on the Opta™

The coils of each relay correspond to pins D0 to D3 as follows:


The Opta™ output contacts are "clean" contacts, which means these are not live in a "non-connection" scenario. This type of contact can be used in any system and with a wide voltage range. To properly function, the outputs must therefore be connected by bringing, for example, a power cable to one of the terminals and connecting the load to the exit of the other terminal.

This way, when the contact is closed by the logic set in the programming, the power supply signal will cross the contact carrying the signal up to the reference load.

The “clean” contact also allows carrying a different power system or type of load for each output contact, being possible to control multiple devices or signals that use different voltage levels.

Clean contact on the Opta™

Let's run a simple sketch to test the output relays on Opta™: in this sketch, all the 4 relays are closing and reopening their contacts and after each relay's cycle, a LED will turn on to provide visual feedback. To activate the relays and run this sketch, you need to provide energy to Opta™ with a voltage from 12 to 24 V DC by connecting it to a proper power supply.

The Opta™ has dedicated terminals for power supply located in the upper part of Opta™ and next to the inputs. These duplicates are to help the user connect the power supply and any common part to the input terminals.

Connect these pins to drive the relays on the Opta™

These terminals are polarized, it is therefore mandatory to strictly respect the power supply polarity by connecting the positive connector of the power supply to "+" and the negative to "-".

The entire sketch can be found below, copy it into your IDE and upload it to your device.

2 Getting Started with Opta™
3 Name: Output_Relay_Opta
4 Purpose: Test output relays of the Opta™.
6 @author Arduino
9void setup() {
10 // Initialize Relays outputs
11 pinMode(D0, OUTPUT);
12 pinMode(D1, OUTPUT);
13 pinMode(D2, OUTPUT);
14 pinMode(D3, OUTPUT);
16 // Initialize Opta LEDs
17 pinMode(LED_D0, OUTPUT);
18 pinMode(LED_D1, OUTPUT);
19 pinMode(LED_D2, OUTPUT);
20 pinMode(LED_D3, OUTPUT);
23void loop() {
24 // Closes and opens the contact of relay 1 and turns on/off led 1
25 digitalWrite(D0, HIGH); // Sets the relay 1 on
26 digitalWrite(LED_D0, HIGH);
27 delay(1000);
28 digitalWrite(D0, LOW); // Sets the relay 1 off
29 digitalWrite(LED_D0, LOW);
30 delay(1000);
32 // Closes and opens the contact of relay 2 and turns on/off led 2
33 digitalWrite(D1, HIGH); // Sets the relay 2 on
34 digitalWrite(LED_D1, HIGH);
35 delay(1000);
36 digitalWrite(D1, LOW); // Sets the relay 2 off
37 digitalWrite(LED_D1, LOW);
38 delay(1000);
40 // Closes and opens the contact of relay 3 and turns on/off led 3
41 digitalWrite(D2, HIGH); // Sets the relay 3 on
42 digitalWrite(LED_D2, HIGH);
43 delay(1000);
44 digitalWrite(D2, LOW); // Sets the relay 3 off
45 digitalWrite(LED_D2, LOW);
46 delay(1000);
47 // Closes and opens the contact of relay 4 and turns on/off led 4
48 digitalWrite(D3, HIGH); // Sets the relay 4 on
49 digitalWrite(LED_D3, HIGH);
50 delay(1000);
51 digitalWrite(D3, LOW); // Sets the relay 4 off
52 digitalWrite(LED_D3, LOW);
53 delay(1000);

Using Opta™ PLC's Inputs

Opta™ has 8 input pins that can be programmed to be used as analog or digital. The mapping between the marking on the Opta™ physical terminals (I1 to I8) and their definition in the core can be found below:

Physical terminalDefinition in coreAlias

The 8 input pins can be used as digital (having the logical values of LOW or HIGH) or as analog inputs (within a range from 0 to 10V).

  • To use them as digital inputs, add the Arduino command
    pinMode(pinName, INPUT);
    inside the
  • To use them as analog inputs, add the command
    with the bit resolution that you want to use.

Analog inputs on the Opta™

Now let's try a sketch that will read the analog inputs on the Opta™. The inputs can operate in a range between 0 and 10V.

The maximum voltage managed by the microcontroller is 3V. This maximum voltage is important to calculate the input voltage using it in conjunction with the resolution factor of the ADCs. That resolution is configured inside the program within the range between 12 bits (4095) and 16 bits (65535).

To get and display the proper voltage value read by the input, we need to convert the value read by the

function and apply a rescaling factor of 0.3 which is determined by the internal voltage divider. The sketch will read the inputs on the analog pins A0, A1, and A2 and then print the result in the serial monitor.

2 Getting Started with Opta™
3 Name: Analog_Inputs_Opta
4 Purpose: Test analog pins A0, A1 and A2 as inputs on Opta™.
6 @author Arduino
9void setup() {
10 Serial.begin(9600);
11 // 65535 is the max value with 16 bits resolution set by analogReadResolution(16)
12 // 4095 is the max value with 12 bits resolution set by analogReadResolution(12)
13 analogReadResolution(12);
16void loop() {
17 // Read the input on analog input I1 corresponding to A0:
18 int sensorValueA0 = analogRead(A0);
19 float voltageA0 = sensorValueA0 * (3.0 / 4095.0)/ 0.3;
21 // Print out the value you read from I1 to the max value for the analog inputs resolution:
22 Serial.print("I1 value: ");
23 Serial.print(sensorValueA0);
24 Serial.print(" corresponding to ");
25 Serial.print(voltageA0, 5); // Print the voltage as a float with 5 decimal digits
26 Serial.println("Volts");
28 // Read the input on analog input I2 corresponding to A1:
29 int sensorValueA1 = analogRead(A1);
30 float voltageA1 = sensorValueA1 * (3.0 / 4095.0)/0.3;
32 Serial.print("I2 value: ");
33 Serial.print(sensorValueA1);
34 Serial.print(" corresponding to ");
35 Serial.print(voltageA1, 5); // Print the voltage as a float with 5 decimal digits
36 Serial.println("Volts");
38 // Read the input on analog input I3 corresponding to A2:
39 int sensorValueA2 = analogRead(A2);
40 float voltageA2 = sensorValueA2 * (3.0 / 4095.0)/0.3;
42 Serial.print("I3 value: ");
43 Serial.print(sensorValueA2);
44 Serial.print(" corresponding to ");
45 Serial.print(voltageA2, 5); // Print the voltage as a float with 5 decimal digits
46 Serial.println("Volts");
48 delay(1000);

Once you have uploaded the code, open the serial monitor to see the values read in each analog input. If you have connected a device with an analog voltage value in I1, I2, and/or I3 you will see the voltage or analog value of each signal. In case you did not connect anything to the analog inputs, you will be able to observe the values oscillate around 0V because the pins are floating.

You may notice from the output values that when the maximum value reaches 10V, the corresponding numerical value is not 4095 as the maximum value with 12 bits resolution should be. This is due to the precautional margin taken on the maximum voltage level applied to the inputs to preserve the integrity of the microcontroller.

Connecting Opta™ to the Cloud

It is possible to use the Opta™ with the Arduino Cloud. To set up the Opta™ to the cloud, go to the Arduino Cloud. For help with how to get started with the cloud, check Getting started with the cloud tutorial. More helpful tutorials regarding the Arduino Cloud can be found here to help you expand its capabilities.


This tutorial went through the basics of the Opta™ device. Now you know how to program the LEDs of the PLC, use the user-programmable button to create additional modes and features, program the relays, and read the digital and analog inputs. With the additional connection of the Opta™ to the Arduino Cloud, Opta™ can be programmed online, create HMI interfaces accessible on any device, and even be updated through an OTA using professional encryption security.

Next Steps

Now that you know the basics of the Opta™, it could be a good idea to combine these features with other features of the device. For example, if you want to add connectivity to your solution, take a look at the Getting started with connectivity on the Opta™ tutorial.

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.

Suggest Changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. You can read more on how to contribute in the contribution policy.