Integrating Arduino Into PLC System
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
A. Testing 1: Toogle a lamp 220 VAC from the touch button of Arduino:
B. Testing 2: Display the PT100 temperature value on RGB led matrix 64x64, we need some more components as
follow:
I. S O FT WARES:
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
I. PLC co nne ct 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.
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
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
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.
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).
- 01pcs x MAX485 IC
- 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.
Plugging this shield to Arduino Mega 2560 and then connecting to led matrix 64x64.
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:
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
Step 9: FINISH
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