0% found this document useful (0 votes)
47 views16 pages

Integrating Arduino Into PLC System

The document discusses integrating an Arduino into a PLC system for home automation. It describes connecting an Arduino over ProfiBus-DP to control a 220V lamp from a touch button and display PT100 temperature on an LED matrix. The steps include parts lists, software, ProfiBus networking basics, connections, PLC and Arduino configuration code.

Uploaded by

l1f3b00k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views16 pages

Integrating Arduino Into PLC System

The document discusses integrating an Arduino into a PLC system for home automation. It describes connecting an Arduino over ProfiBus-DP to control a 220V lamp from a touch button and display PT100 temperature on an LED matrix. The steps include parts lists, software, ProfiBus networking basics, connections, PLC and Arduino configuration code.

Uploaded by

l1f3b00k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

instructables

INTEGRATING ARDUINO INTO PLC SYSTEM

by tuenhidiy

I intend to make an automated system for my home with a combination of PLC S IEM ENS and ARDUINO . I think
we can combine their own strengths to make the automation system running in stability, optimization and
acceptable price. So I took times to consult, study and perform some below experiments before applying them to
my home.

Toogle a lamp 220 VAC from touch button of Arduino via Pro bus-DP.

//www.yout ube.com/embed/TC1FKypClzU

Display the PT100 temperature value on the 64x64 led matrix via Pro bus-DP

//www.yout ube.com/embed/G7TGFvfsMPU

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 1


Step 1: PARTS LIST

Main component includes:

A. Testing 1: Toogle a lamp 220 VAC from the touch button of Arduino:

01pcs x DFRduino UNO R3 - Arduino Compatible: https://www.dfrobot.com/product-838.html


01pcs x DFRobot RS485 Shield for Arduino: https://www.dfrobot.com/product-1024.html
01pcs x DFRduino Ethernet Shield (Optional): https://www.dfrobot.com/product-455.html
01pcs x PLC S7-300.
01pcs x Relay 24VDC.
01pcs x Inductive sensor.
01pcs x Lamp 220VAC.
01pcs x Touch button with LEDs indicator.
03 meters x Pro bus cable.
03pcs x Pro bus connectors.

B. Testing 2: Display the PT100 temperature value on RGB led matrix 64x64, we need some more components as
follow:

01pcs x DFRobot Mega 2560: https://www.dfrobot.com/product-655.html


01pcs x P2.5 64x64 RGB LED Matrix.
01pcs x Pt100 RTD.
01pcs x Interface module IM 151-1 Standard for ET 200S - 6ES7151-1AA05-0AB0
01pcs x PM-E power modules for ET 200S - 6ES7138-4CA01-0AA0
01pcs x 2AI RTD HF analog module - 6ES7134-4NB51-0AB0.

Step 2: SOFTWARES AND MANUALS

I. S O FT WARES:

SIMATIC STEP 7 V5.6/ SIMATIC STEP 7 V5.6 PROFESSIONAL.


Arduino IDE.

II. REFERENCE M ANUALS:

Arduino's UART, Timer.


PLC Siemens S7-300.
Pro bus manuals: https://www.felser.ch/pro bus-manual/index.html
Learn about *.GSD le to con gure Arduino into Siemens PLC hardware system.

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 2


Step 3: QUICKVIEW OF PROFIBUS-DP NETWORK

The PROFIBUS DP network is based on an RS485 Each byte in a telegram is transferred as 11 bits
physical communication and it has to strictly follow (S TART = 0 ; DATA = 8 BIT ; PARIT Y = E VEN ;
the telegram format structure and telegram S T O P = 1 ), see FRAME FORMAT picture above.
sequences de ned by PROFIBUS network. And RS485
designs use the same basic UART but it convert the T BIT : DURAT IO N O F O NE BIT
UART signal into a bi-directional di erential signal. RS
485 transmission technology uses two-cores cable, On PROFIBUS-DP, certain time ratios must be
with po s it iv e re d co re B+ and ne g a t iv e g re e n respected to ensure that a telegram sequence can
co re A- . The bene t of using a di erential signal to function correctly.
minimize noises and allowing for longer cable
lengths, up to 1.2 km. It allows for fast data The duration of a bit di ers depending on bit rate: for
communications up to a bit rate of 12 Mbit/s. 12 MBit/s tBit = 83 ns and for 1.5 MBit/s tBit = 0.67 µs.

UART CO DING AND FRAM E FO RM AT We should study more information about Pro bus at
following link:

https://www.felser.ch/pro bus-manual/index.html

PRO FIBUS - DP T ELEGRAM FO RM AT S

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 3


Step 4: CONNECTIONS

I. PLC co nne ct io n:

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 4


II. Arduino co nne ct io n:

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 5


III. Te s t ing de s cript io n:

The 220VAC lamp can be controlled in toogle mode by virtual and physical input as follows:

Touch button is connected to Arduino plus RS485 shield and send the command to PLC S7-300 via
Pro bus-DP network at Virt ua l Input I0 . 0
Inductive sensor is connected to PLC S7-300 directly at Phy s ica l Input I124 . 0
24VDC relay coil is connected to PLC Phy s ica l O ut put Q124 . 0 and lamp 220VAC is connected to
N.O (normal open) contact of this relay. Even though the lamp is controlled by Arduino or PLC,
Arduino receive the feedback of lamp status from PLC at v irt ua l o ut put Q0 . 0 and display lamp
status by red led (lamp 220VAC o ) /green led (lamp 220VAC on) on touch button.

We can see more detail in "PLC PRO GRAM ING " step.

Step 5: PLC HARDWARE CONFIGURATION

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 6


PLC hardware con guration is as picture below and their own GSD les. GSD stands for "G e ne ra l
we need to do the following steps: St a t io n De s cript io n ". It is an ASCII text le that
contains device-speci c data, such as, vendor
identi cation information, supported baud rates,
supported message length, number of input/output
data, meaning of diagnostic messages, timing
information, plus options and features supported,
data formats, and available I/O signals.

With Arduino - F_CPU = 16MHz, Pro bus network


works well at ba udra t e 4 5. 4 5 Kbps .

In Sim a t ic St e p 7 program (HW CONFIG), we have We need to de ne the number of bytes transmitted
to install ARDUINO * . GS D le and update your and received over the Pro bus connection, we can see
Hardware Catalog using the menu command this setup on above picture:
"O pt io ns - - > Upda t e ca t a lo g ". You can check
detail at this link to know how to integrate a GSD le - 1 Byte Input: PLC receive 1 byte input at v irt ua l
into the STEP 7 HW Con g for PROFIBUS. input a ddre s s IB0 .

The GSD le is an electronic device datasheet or - 1 Byte Output: PLC transmit 1 byte output at
device database le that identi es the Pro bus device. v irt ua l o ut put a ddre s s Q B0 .
All Pro bus devices (class 1 masters and slaves) have

Step 6: PLC PROGRAMING

It is simple PLC program with:

OB1 - Main program.


DB1 - Data Block for storage toogle state of LAMP (at DB1.DBX0.0).
FB1 - Function Block for carrying out toggle function. It toggles the output Q state with every rising
edge of clock (CLK).

DB2 - Instant Data Block for FB1.

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 7


Program explanation:

I0.0 - PLC Virtual Input which is received from Touch Button of Arduino via Pro bus-DP.
I124.0 - PLC Physical Input which is directly connected to Inductive Sensor.
Q124.0 - PLC Physical Output which is connected to coil relay 24VDC.
PQB0 - PLC Virtual Output Byte (8bit) which is transmitted to Arduino via Pro bus-DP.

"T O O GLE " Function Block FB1 written in SCL (Structured Control Language) can be copied to S7 pro g ra m /
S o urce s f o lde r and compiled to LAD/STL. This Function Block toggles the output Q state when it detects every
rising edge of clock (CLK). We can see in program, "TOOGLE" function block will toogle Q124.0 when it detects one
rising edge pulse at virtual input I0.0 or physical input I124.0

FUNCTION_BLOCK TOGGLE
TITLE = 'TOGGLE'
VAR_INPUT
CLK : BOOL;
RST : BOOL;
END_VAR
VAR_OUTPUT
Q : BOOL;
END_VAR
VAR
EDGE : BOOL;
END_VAR
BEGIN
IF RST THEN
Q := 0;
ELSIF CLK AND NOT EDGE THEN
Q := NOT Q;
END_IF;
EDGE := CLK;
END_FUNCTION_BLOCK

Step 7: ARDUINO PROGRAMING

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 8


The Arduino code including *.GSD le for PLC Hardware Con guration is available at my GitHub.

My program is referenced from German mikrocontroller website by Jö rg S. , M a rc H. , Jo ha nne s F. and


originally it is written for M S P4 30 F2252 . If you are German I believe you will collect a lot of information here.

https://www.mikrocontroller.net/topic/106174

For RS485 Shield designed by DFROBOT, it is useful when it is equipped with additional button "O pe ra t io n a nd
pro g ra m m ing m o de s w it ch " because Arduino Uno has only 1 UART port for programming and RS485
communication.

Switch to OFF: you can download the program for the Arduino controller.
Switch to ON: the shield will convert the UART to the RS485.

Im po rt a nt no t e :

The Pro bus-DP based on RS485 physical communication has two independent lines known as
negative line - A and positive line - B, which transmit similar voltage levels however with opposite
polarities. For this reason, it is important that the network is connected with the correct polarity. As
my testings with some RS485 modules, in order to correct their polarities, I had to swap 2 cores A and
B of Pro bus cable together for most RS485 modules at Arduino-side.
In order for network working properly, the GND o f PLC and the GND o f Arduino must be
connected together.

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 9


Step 8: DISPLAY PT100 VALUE ON LED MATRIX 64X64

I. T ES T ING DES CRIPT IO N:

PT100 is connected to 2AI RTD analog module at Remote I/O station, Pro bus - DP address: 4.
Led matrix module including: Led matrix 64x64 + Arduino Mega 2560 + DIY Pro bus Shield, is
connected to Pro bus network at address: 6.
PLC read the temperature from Remote I/O station Pro bus Address 6 and then send this value to
led matrix module (Pro bus Address - 6).

II. S O LDERING A PRO FIBUS S HIELD

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 10


This shield not only handles the Pro bus-DP communication, but also controls 64x64 led matrix. You
can refer to this GitHub to know how Arduino Mega 2560 can control the led matrix 64x64. This
shield includes the following components:

- 01pcs x MAX485 IC

- 01pcs x Decoupling capacitor 0.1uF.

- 03pcs x Pull-up resistor 10K.

- 01pcs x Indication led 5mm and its current limiting resistor.

- 01pcs x DB9 female for Pro bus connection.

- 01pcs x 2.45mm 2x8P double row female header, connecting to led matrix PO male header

- 01pcs x Ribbon cable 16P with 2x8P double row female header at 2 sides. It is used for connecting from this shield
to led matrix PI male header.

Pro bus shield - Top View

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 11


Pro bus shield - Bottom View

Plugging this shield to Arduino Mega 2560 and then connecting to led matrix 64x64.

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 12


III. PLC AND ARDUINO PRO GRAM ING

2AI RTD module read temperature from PT100 and store in data block (ex: DB1) in real format (Floating-Point
Numbers) with 32 bit. Then this 4 bytes real number will be transmitted to Arduino, for example at v irt ua l o ut put
PQ B0 ~ PQ B3 .

Take note that PLC SIEMENS S7 ™ use "Big - Endia n " data format and ARDUINO™ use "Lit t le - Endia n " data format.
The terms "Big-Endian" and "Little-Endian" to describe di erences in reading and writing data:

Big – Endia n : MSB (left-most bit) --> LSB (right-most bit), for example, DW O RD 0 x4 C21112F is
stored in PLC Siemens S7 ™ as follows:

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 13


Lit t le Endia n : LSB (left-most bit) --> MSB (right-most bit), with same DWORD above but ARDUINO ™
will store in the opposite way DW O RD 0 x2F11214 C

Arduino receive 4 bytes temperature in REAL, BIG-ENDIAN format, for example it is stored at {
Pro bus_in_register[0] ~ Pro bus_in_register[3] }. It need to be processed and converted to FLO AT, LIT T E-
ENDIAN in Arduino as following tip:

byte Temperature[4];
float Corrected_Value;
Temperature[3] = Profibus_in_register[0]; // swap order, 32-bit Big-Endian float
Temperature[2] = Profibus_in_register[1];
Temperature[1] = Profibus_in_register[2];
Temperature[0] = Profibus_in_register[3];
float *floatTemp= (float *)Temperature; // format the buffer as a float
Corrected_Value= *floatTemp; // value in 32-bit Little-Endian float

Picture for testing result:

Step 9: FINISH

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 14


I have previously posted some projects related to href="https://www.instructables.com/id/WIFI-
communication between PLC and Arduino on this JOYSTICK/">https://www.instructables.com/id/WIFI-
Instructables site, such as: JOYSTICK/

https://www.instructables.com/id/Pro bus-DP- I hope these projects will inspire the students who
Commu... don't have much money, to come up with ideas for
combining electronic and automation elds together,
https://www.instructables.com/id/ARDUINO-HACK- with low price. Hope you enjoyed my post this time.
PLC-... Thank for your watching!

Congregulation,
This is awesome, I will try this in school. I am teacher and I like PLC and arduino. This is
something what I waited for. Greedings from Bosnia and Herzegovina

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 15


Thanks and wishing you success at school! :–)

INTEGRATING ARDUINO INTO PLC SYSTEM: Page 16

You might also like