You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DIN Simul8 is a digital-input-simulator and power distribution board for the PLC of the Opta family. It provides eight toggle switches (0 - 10 V output) and four screw terminal for bringing the 24 V and the GROUND easily to the PLC or other boards.
39
+
The **DIN Simul8** is a digitalinputsimulator and power distribution board designed for the Opta PLC family. It features eight toggle switches (0 - 10 V output) and four screw terminals, making it easy to supply 24 VDC and GND to the PLC or other boards.
40
40
41
-
If you have any problems using the Opta WiFi you can read its [manual](https://docs.arduino.cc/tutorials/opta/user-manual/) before proceeding.
41
+
***If you encounter any issues with the Opta WiFi, refer to its [user manual](https://docs.arduino.cc/tutorials/opta/user-manual/) before continuing.***
42
42
43
43
### Connections
44
44
45
-
To connect the DIN Simul8 to the PLC you'll need 8 wires for the signal and two for the power.
To connect the DIN Simul8 to the PLC, you will need eight wiring cables for the signal connections and two for power.
48
46
49
-
Connections are super important in an industrial project, first of all **disconnect the power plug** and then connect all the pins using cable with lugs, or be careful that no copper part of the cable touch other pins.
***It is recommended to use __AWG 17__ cables for all connections to ensure optimal performance and safety.***
55
53
56
-

54
+
Proper connections are crucial in an industrial project. **Always disconnect the power source before making any connections.** Use cables with lugs, or ensure that no exposed copper parts of the cables come into contact with other pins.
57
55
56
+

58
57
59
58
## Upload Test Code
60
59
61
-
Firstly we have to test if the components and the connections works as excepted. Let's print on the [Serial Monitor](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-serial-monitor/) what arrives to the inputs.
60
+
Before proceeding, it is necessary to test if the components and connections are working as expected. We can do this by printing the input values to the [Serial Monitor](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-serial-monitor/).
62
61
63
-
The Opta WiFi has eight inputs ports, at the top, named from `I1` to `I8`. They are mapped to pin`A0`to`A7`. Let's assign to each of them a variable with the name of the port on the Opta WiFi, easier to remember, we can use the [#define](https://www.arduino.cc/reference/en/language/structure/further-syntax/define/)function, like this:
62
+
The Opta WiFi has eight input ports, labeled `I1` to `I8` at the top. These are mapped to pins`A0`through`A7`. To make it easier to reference each input, we can assign a variable to each port using the [`#define`](https://www.arduino.cc/reference/en/language/structure/further-syntax/define/)directive, as shown below:
64
63
65
64
```arduino
66
65
#define pin_I1 A0
@@ -77,17 +76,15 @@ The Opta WiFi has eight inputs ports, at the top, named from `I1` to `I8`. They
77
76
|`I7`|`A6`/`PIN_A6`|`pin_I7`|
78
77
|`I8`|`A7`/`PIN_A7`|`pin_I8`|
79
78
80
-
From now on we can refer to the port `I1`of the Opta WiFi using the `pin_I1` variable.
79
+
Now, you can refer to the `I1`port on the Opta WiFi using the `pin_I1` variable.
81
80
82
-
83
-
To read what's arriving on each input port, we can use the [digitalRead](https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/) function, inside the `Serial.print` command:
81
+
To read the received values at each input port, you can use the [`digitalRead`](https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/) function within the `Serial.print` command:
84
82
85
83
```arduino
86
84
Serial.print(digitalRead(pin_I1));
87
85
```
88
86
89
-
Now let's do this for each input port, dividing each value with a comma `,`.
90
-
Here the full code:
87
+
Next, lets do this for each input port, separating each value with a comma (`,`). Here is the complete code:
91
88
92
89
```arduino
93
90
#define pin_I1 A0
@@ -130,25 +127,28 @@ void loop() {
130
127
131
128
```
132
129
133
-
>**Don't forget to** initialize the Serial communication with the Serial.begin command in the setup.
130
+
***Remember to initialize the Serial communication with the `Serial.begin` command in the `setup` function.***
131
+
132
+
***Use `Serial.println` for the last `Serial.print` to ensure the output wraps to a new line, making it easier to read.***
134
133
135
-
>**Don't forget to** call the the last `Serial.print`as `Serial.println`, in order to print a new line and wrap the text to make readable.
134
+
***Add a delay, such as __100ms__, to ensure stable communication over Serial.***
136
135
137
-
>**Don't forget to** put some delay, like 100ms in order to have a stable communication over serial.
136
+
Each switch on the DIN Simul8 outputs 0 V when OFF and 10 V when ON. The `digitalRead()` function will read `0` for 0 V and `1` for 10 V.
138
137
139
-
Each switch in the DIN Simul8 outputs 0 V when OFF and 10 V when ON. The `digitalRead()` function will read 0 for 0 V and 1 for 10 V.
140
-
If you switch on the toggle switches 1-3-5-7 and leave off the 2-4-6-8, like in the following image:
138
+
For example, if you turn on toggle switches 1, 3, 5, and 7 while leaving 2, 4, 6, and 8 off, as shown in the image below:
If everything works we can move on and try to trigger a function when switch change state: a function that print `"Switch 1 ON"` when turned on and the inverse for the OFF state.
149
+
If everything works correctly, we can trigger a function when the switch changes state.
150
+
151
+
For example, we can create a function that prints `"Switch 1 ON"` when the switch is turned on and `"Switch 1 OFF"` when it is turned off.
152
152
153
153
```arduino
154
154
void ON_function() {
@@ -160,13 +160,13 @@ void OFF_function() {
160
160
}
161
161
```
162
162
163
-
In order to make every function runs once, only when the state changed, and not continuously, we can save the status of the switch in a variable:
163
+
To ensure that the function only runs oncewhen the state changes (and not continuously), we can store the current state of the switch in a variable:
164
164
165
165
```arduino
166
166
bool stateSwitch = false;
167
167
```
168
168
169
-
and call the function when it reads the opposite state: if the state is OFF (0) and it reads ON (1) it means that is just changed to ON, so call the `ON_function()`and update the `stateSwitch` variable.
169
+
The function is called when the switch state changes. For instance, if the switch is currently OFF (`0`) and the state changes to ON (`1`), the `ON_function()`is triggered, and the `stateSwitch` variable is updated accordingly:
170
170
171
171
```arduino
172
172
if (stateSwitch == 0) {
@@ -177,7 +177,7 @@ and call the function when it reads the opposite state: if the state is OFF (0)
177
177
}
178
178
```
179
179
180
-
The final code should like like this and it will works only for the toggle switch 1.
180
+
Here is the complete code, which works for toggle switch 1:
181
181
182
182
```arduino
183
183
#define pin_I1 A0
@@ -222,27 +222,31 @@ void ON_function() {
222
222
void OFF_function() {
223
223
Serial.println("Switch 1 OFF");
224
224
}
225
-
226
225
```
227
226
227
+
This code will monitor the state of toggle switch 1 and trigger the appropriate function when the switch is turned *on* or *off*.
228
+
228
229
## Upload Final Code
229
230
230
-
In order to make it works for all the eight switches, you can repeat the `stateSwitch` variable and the `if-else` conditions eight times... but that would be boring. What about using [arrays](https://www.arduino.cc/reference/en/language/variables/data-types/array/) and a [for-loop](https://www.arduino.cc/reference/en/language/structure/control-structure/for/)?
231
+
To make this work for all eight switches, you could repeat the `stateSwitch` variable and the `if-else` conditions eight times, but that would be a nonoptimal approach.
232
+
233
+
Instead, let's use [`arrays`](https://www.arduino.cc/reference/en/language/variables/data-types/array/) and a [`for-loop`](https://www.arduino.cc/reference/en/language/structure/control-structure/for/).
231
234
232
-
The idea is to replace all the variables used in the loop with arrays that stores eight values, one for each switch, and put it inside a `forloop`that will cycle through all the eight inputs. Let's see how to do it:
235
+
The idea is to replace the variables in the loop with arrays that store valuesfor each switch and then use a `for-loop`to cycle through all eight inputs.
233
236
234
-
First of all we need an array for all the pins definition of the inputs:
237
+
First, define an array for all the input pin definitions:
Then, you can substitute these arrays into your code:
246
250
247
251
```arduino
248
252
if (stateSwitch[ ] == 0) {
@@ -258,8 +262,9 @@ if (stateSwitch[ ] == 0) {
258
262
}
259
263
```
260
264
261
-
Now we need to tell to each array-variable which values to use, you can do it by putting a number from 0 to 7 inside the `[]`, i.e. `pins[0] = pin_I1 // pins[1] = pin_I2 // etc..`.
262
-
One way of doing it is with the [`for-loop`](https://www.arduino.cc/reference/en/language/structure/control-structure/for/). We can assign a variable, like `int i`, to change from 0 to 7, and then assign it to each array-variable:
265
+
To specify which array values to use, you can use a number from 0 to 7 inside the brackets `[]`. For example, `pins[0] = pin_I1`, `pins[1] = pin_I2`, and so on.
266
+
267
+
One way to implement this is with a [`for-loop`](https://www.arduino.cc/reference/en/language/structure/control-structure/for/). Assign a variable, like `int i`, to iterate from 0 to 7, and then use it to access each array value:
263
268
264
269
```arduino
265
270
for (int i = 0; i <= 7; i++) {
@@ -277,9 +282,9 @@ for (int i = 0; i <= 7; i++) {
277
282
}
278
283
```
279
284
280
-
Ok, that would work, but the `ON_function()` and the `OFF_function()` will print only the state of the Switch 1, unless we make the `i` variable as an [argument](https://docs.arduino.cc/learn/programming/functions/), and so we can print the number related to the switch we are switching.
285
+
This approach will work, but the `ON_function()` and `OFF_function()` will only print the state of Switch 1 unless we pass the `i` variable as an [argument](https://docs.arduino.cc/learn/programming/functions/). This way, we can print the switch number that is being toggled.
281
286
282
-
Here the full code:
287
+
Here is the full code:
283
288
284
289
```arduino
285
290
#define pin_I1 A0
@@ -332,14 +337,16 @@ void OFF_function(int n) {
332
337
}
333
338
```
334
339
335
-
And here you can see what's goes on the serial monitor when you turn on all the switch from 1 to 8 and then off from 8 to 1:
340
+
And here is what you should see on the Serial Monitor when you turn on all the switches from 1 to 8 and then off from 8 to 1:
336
341
337
342

338
343
344
+
This code will monitor the state of all eight switches and print the corresponding message whenever a switch is toggled *on* or *off*.
345
+
339
346
## Considerations
340
347
341
-
If something strange happens when you turn a switch on or off, like if the switch was triggered on and off super rapidly, don't panic! That's normal, and it is related to something called "debounce". You can have a look [here](https://docs.arduino.cc/built-in-examples/digital/Debounce/) to understand what's going on.
348
+
If you notice any unexpected behavior when turning a switch on or off, such as the switch appearing to toggle on and off rapidly, don't worry! This is normal and is related to a phenomenon called "debounce." To understand further, you can learn more about it [here](https://docs.arduino.cc/built-in-examples/digital/Debounce/).
342
349
343
350
## Conclusions
344
351
345
-
The Arduino DIN Simul8 is the perfect playground to start experiment your coding skill in the PLC world. Try creating more functions that could be triggered by some combination of switch position, or whatever you like, have fun!
352
+
The Arduino DIN Simul8 provides an excellent platform to start experimenting with your coding skills in the PLC world. Try creating more functions that different combinations of switch positions can trigger, or explore any other ideas you have. Have fun!
0 commit comments