---
title: "ScadaBR with Arduino via Modbus TCP/IP"
url: "https://maker.wiznet.io/praveen_k/projects/ScadaBR-with-Arduino-via-Modbus-TCPIP/"
markdown_url: "https://maker.wiznet.io/praveen_k/projects/ScadaBR-with-Arduino-via-Modbus-TCPIP/md"
type: "UCC: User Created Content"
author: "praveen_k"
author_url: "https://maker.wiznet.io/praveen_k/"
original_author: "praveen_k"
original_url: "https://portal.vidadesilicio.com.br/scadabr-modbus-tcp-ip/"
published: "2021-06-10"
language: "en"
hardware: ["Arduino UNO", "WIZnet W5100 ethernet shield"]
likes: 0
views: 890
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# ScadaBR with Arduino via Modbus TCP/IP

> ScadaBR with Arduino via Modbus TCP/IP

Original author: praveen_k (source: https://portal.vidadesilicio.com.br/scadabr-modbus-tcp-ip/)

## Components

- **Arduino UNO** x 1 ([docs](https://www.farnell.com/datasheets/1682209.pdf))
- **WIZnet W5100 ethernet shield** x 1 ([docs](https://www.wiznet.hk/en/open-source-hardware/102-w5100s-ethernetshield.html?search_query=W5100+ethernet+shield&results=84))
- Software: **Scadabr**

## Article

we will demonstrate the procedures necessary for?**Arduino**?to communicate???with??**ScadaBR**?using another category of the modbus protocol: the?**modbus TCP/IP.**

Original post:?<https://portal.vidadesilicio.com.br/scadabr-modbus-tcp-ip/>

---

## Get to work - Establishing communication between an Arduino board and the ScadaBR

### Required components

- 1 x?[Arduino UNO](http://www.vidadesilicio.com.br/arduino-uno-r3)

- 1 x?[Shield Ethernet Wiznet W5100](http://www.vidadesilicio.com.br/shield-ethernet-wiznet-w5100.html)

- 1 x?[Protoboard](http://www.vidadesilicio.com.br/protoboard-830.html)

- 1 x?[Resistor 330 Ω](https://www.vidadesilicio.com.br/resistor-330-ohm-10un)

- 1 x?[Diffuse green LED](http://www.vidadesilicio.com.br/led-verde-difuso.html)

### assembling the project

![Hardware used.](https://i2.wp.com/portal.vidadesilicio.com.br/wp-content/uploads/2018/03/scadatcp.png?resize=612%2C524&ssl=1)

*Figure 1 ? Hardware used.*

### programming

#include &lt;SPI.h>

#include &lt;Ethernet.h>

#include &lt;Modbus.h>

#include &lt;ModbusIP.h>

const int LED_COIL = 0;

ModbusIP mb;

void setup ()

{

mac byte [] = { 0xDE , 0xAD , 0xBE , 0xEF , 0xFE , 0xED }

byte ip [] = { 192, 168, 25, 16 } ;

mb. config ( mac,ip ) ;

pinMode ( 9, OUTPUT ) ;

mb. addCoil ( LED_COIL ) ;

}

void loop ()

{

mb. task () ;

digitalWrite ( 9, mb. Coil ( LED_COIL )) ;

}

### Configuring Scadabr

At this moment, we are going to present the initial procedures that must be done in?**ScadaBR**?so that it is possible to carry out the interaction between it and our?**Arduino**?board?.?First, to fulfill the presented objective, we must make?**?ScadaBR**?identify the element with which it will communicate.?This must be done by creating an element called Data source, which in turn will be the bridge between the Arduino board we are using and ScadaBR.

> Data source is the structure that allows communication between Arduino and ScadaBR

![Accessing the Data sources creation panel in SCADABR](https://i2.wp.com/portal.vidadesilicio.com.br/wp-content/uploads/2018/03/Data-sources.png?resize=440%2C209&ssl=1)

*Figure 2 ? Accessing the Data sources creation panel.*

Then, when creating the Data point, we must say what type of communication will exist between the 2 elements.?As mentioned before, we will use the Modbus protocol through serial communication, so just find the?**Modbus IP**?option in the selection list??and click on the icon to the right of the list in question.

![Creating Data Source of Modbus IP type.](https://i2.wp.com/portal.vidadesilicio.com.br/wp-content/uploads/2018/03/scadatcp2.png?resize=379%2C392&ssl=1)

*Figure 3 ? Creating the Modbus IP Data Source.*

Then,?**ScadaBR**?will direct us to a page, in which we must define the parameters of the?**Data source**?in question (remember that it is the bridge between?**Arduino UNO**?and?**ScadaBR**?).?At first, we should just name our?**Data source**?and also define the time when the data will be updated (this information is very important, that is, it is essential that the reader is aware of the application that is being developed so that the choosing this parameter results in an efficient functioning of the project).

![Figure 4 - Defining Initial Data Source Settings.](https://i1.wp.com/portal.vidadesilicio.com.br/wp-content/uploads/2018/02/scada4.png?resize=415%2C92&ssl=1)

*Figure 4 ? Configuring Initial Data Source Settings.*

In addition to?these settings, we must also specify a few parameters for the communication to be established established, such as: the?**endececo?**?**IP**?previously configured on the code?**UNO Arduino**?and the type of transport (we suggest the "TCP to stay alive" in a There is no need to change the?**Port**?field?**.**

![Figure 5 - Configuring the communication port and Arduino IP.](https://i1.wp.com/portal.vidadesilicio.com.br/wp-content/uploads/2018/03/configtcp.png?resize=356%2C91&ssl=1)

*Figure 5 ? Configuring the Arduino communication port and IP.*

After creating and configuring the?**Data source**?, we must create a small structure called?**Data point**?.?Data points are the elements that will contain the values ??related to the inputs and outputs of our?**Arduino**?board?.?To perform this procedure, go to the bottom of the screen and then click on the icon located to the right of the table referring to?**Data points**?.

![](https://i0.wp.com/portal.vidadesilicio.com.br/wp-content/uploads/2018/02/scada5.png?resize=636%2C61&ssl=1)

*Figure 6 ? Data points table.*

After clicking on the aforementioned icon,?**ScadaBR**?will give us a window with some options to be defined.?First, we must name the?**Data point**?(in this tutorial, we call it LED).?Next, we must ensure that?**the Record Range**?field has??**the Coil Status**??option?selected.?To save the settings made, just click on the icon at the top right of the window.

> As this is an introductory tutorial, we won't cover how the other fields work.

![](https://i1.wp.com/portal.vidadesilicio.com.br/wp-content/uploads/2018/03/datapointtcp.png?resize=517%2C386&ssl=1)

*Figure 7 ? Creating a new Data point.*

The following figure shows how the table where the Data points are organized will look like after the previous creation.?To enable the desired data point, just click on the red circle present in the Status field of the created data point.

![](https://i2.wp.com/portal.vidadesilicio.com.br/wp-content/uploads/2018/03/tabelatcp.png?resize=678%2C87&ssl=1)

*Figure 8 ? Data point created.*

Finally, we must go to the top of the page, save the settings made (the same procedure as performed in the previous step) and enable the Data source, clicking again on the red circle beside the icon used to save.

![](https://i1.wp.com/portal.vidadesilicio.com.br/wp-content/uploads/2018/02/scada8.png?resize=604%2C226&ssl=1)

*Figure 9 ? Saving Data source settings.*

At this moment, the reader must return to the watch list (first icon from the left in the toolbar) and on the left side of the presented interface, click on the arrow to visualize the status of the created data point.

![](https://i2.wp.com/portal.vidadesilicio.com.br/wp-content/uploads/2018/02/scada9.png?resize=150%2C47&ssl=1)

*Figure 10 ? List of Data points created.*

After performing the procedure mentioned above, our Data point will appear created on the right side of the interface presented in our watchlist.

![](https://i1.wp.com/portal.vidadesilicio.com.br/wp-content/uploads/2018/02/scada1023.png?resize=718%2C63&ssl=1)

*Figure 11 ? Data point initial value.*

. To activate the led, just position the mouse over the icon located to the left of the Data point's name and change its value (note that when its value is 0 (zero), the led will be off, while when we change it for 1 (one) the led will be turned on).

![](https://i0.wp.com/portal.vidadesilicio.com.br/wp-content/uploads/2018/02/scada1123.png?resize=796%2C99&ssl=1)

*Figure 12 ? Manipulating the Data point.*

See the result of the activation of the led in ScadaBR.

![](https://i0.wp.com/portal.vidadesilicio.com.br/wp-content/uploads/2018/02/scada12.png?resize=730%2C60&ssl=1)

*Figure 13 ? Data point final value .*

---

## understanding in depth

### software

At this point, all the steps for the development of the code that must be inserted in??**Arduino UNO**??so that it is possible to carry out the communication between it and??**ScadaBR will be demonstrated**?.

#### ? Including the libraries that will be used

The first step in establishing communication between the two elements consists in the inclusion of appropriate libraries for the use of the??**Modbus TCP/IP protocol*?***?(developed by??***?Andre Sarmento***??and available??[here](https://github.com/andresarmento/modbus-arduino/tree/master/libraries)?).?In addition, we must also declare the libraries responsible for the functioning of the?**SPI**?communication protocol??and for the connectivity of our?**Arduino**?board?with the local network.

#include &lt;SPI.h>

#include &lt;Ethernet.h>

#include &lt;Modbus.h>

#include &lt;ModbusIP.h>

#### ? Defining Modbus protocol structures

Later, we must determine the structure that will be responsible for activating the LED.?In this tutorial, we will address only one among the other structures that exist in the MODBUS protocol: the?**Coils**?.?These elements act in the storage of values ??that can be used to trigger??***on/off**?*?devices. To define the Coil that will be used to activate the LED, just declare a variable of type const int and then assign a number to it according to the amount of Coils in use in the project (as in this application we are using only one Coil, we assign the number 0 (zero) to the declared variable).

const int LED_COIL = 0;

#### ? Creating the mb object

Before proceeding to the?**setup()**?function??, an object called?**mb**?must be created so??that we can control the existing structures in the Modbus protocol.

ModbusIP mb;

#### ? Defining initial settings

In the?**Setup()**?function??there are some lines of code referring to the initial settings of the program.?First, we must define some parameters related to the communication protocol used, so that this procedure is performed by defining the?**MAC**?and?**IP addresses**?of our?**Arduino UNO**?board?(in practice, the MAC address can be anything, as long as it is unique on the network, while the IP address must be a valid address on your local network).?Then, to configure our Modbus protocol, we use the?**config()**?function??together with the values ??determined above. Then, we use the?**pinMode()**?function?to define the operating mode of digital pin 9 as a digital output and finally, we add the Coil that will be responsible for containing the values ??used in the activation of the LED.

void setup () {

mac byte [] = { 0xDE , 0xAD , 0xBE , 0xEF , 0xFE , 0xED }

byte ip [] = { 192, 168, 25, 16 } ;

mb. config ( mac,ip ) ;

pinMode ( 9, OUTPUT ) ;

mb. addCoil ( LED_COIL ) ;

}

#### ? Carrying out the LED activation

Within the?**loop()**?function??, we?*?*use the?**task()?**?function??to manage communication and data exchange between devices that are connected via?***Modbus***?protocol??.?In addition to the aforementioned function, we also have the necessary function to write the data referring to the activation of the LED in the?***Coil***?instance??***.***

void loop () {

mb. task () ;

digitalWrite ( 9, mb. Coil ( LED_COIL )) ;

}

---

## Final considerations

In this tutorial, we demonstrate how you can establish communication between your Arduino board and ScadaBR through a local network, we hope you will keep following us and feel free to give us suggestions, criticisms or compliments.

---

Source: https://maker.wiznet.io/praveen_k/projects/ScadaBR-with-Arduino-via-Modbus-TCPIP/
