0% found this document useful (0 votes)
190 views9 pages

PLC and Arduino Interaction Based On Modbus Protocol

This document summarizes a research paper that proposes a system for communication between a PLC (Programmable Logic Controller) and an Arduino board using the MODBUS protocol over an RS485 interface. The system uses an Arduino board as the MODBUS master to communicate with a PLC as the slave device. This allows for reliable and fast communication between the devices to exchange data for automation and control applications in an industrial setting.

Uploaded by

toptop chanel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
190 views9 pages

PLC and Arduino Interaction Based On Modbus Protocol

This document summarizes a research paper that proposes a system for communication between a PLC (Programmable Logic Controller) and an Arduino board using the MODBUS protocol over an RS485 interface. The system uses an Arduino board as the MODBUS master to communicate with a PLC as the slave device. This allows for reliable and fast communication between the devices to exchange data for automation and control applications in an industrial setting.

Uploaded by

toptop chanel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 9

Journal of Korea Multimedia Society Vol. 20, No. 3, March 2017(pp.

511-519)
https://doi.org/10.9717/kmms.2017.20.3.511

PLC and Ar duino Interaction Based


on Modbus Pr otocol
Yunju Jeong†, Md Israfil Ansari††, WooHyeon Shin†††, Bonggu Kang††††,
JinSeop Lim†††††, HyeonSik Moon††††††, Jaechang Shim†††††††

ABSTRACT
This Paper introduces the design and communication method between PLC (Programmable Logic
Controller) and Arduino based on MODBUS Protocol. MODBUS connection can be established in a new
or existing system very easily, therefore we used this protocol in our proposed system. In the field of
automatic devices, multi-function serial port such as RS232, RS422, RS485, and so on creates a great
convenience to the developer. This proposed system used RS485 as a key mediator for data exchanging
on a connected network. We also believe that it will reduce the development cost in various automated
industry because this system can be reused or can be implemented any such PLC installed machines.
RS485 is used as a communication interface between PLC (as a slave) and Arduino (as a master), through
which a reliable network is created for safe and fast communication. Furthermore, RS485 allows multiple
devices(up to 32) to communicate at half duplex on a single pair of wires and provides a long connectivity
area (up to 1200 meters) as compare to other device, which makes it a user-friendly for various devices
in the automated industry. Moreover, Arduino can play as a mediator by connecting third party device
and setup a communication network with PLC.
Key words: PLC, RS485, MODBUS Protocol, Arduino, IoT

1. INTRODUCTION focuses on PLC based machines through which a


communication network is setup with Arduino
Automation in electronic, machinery and many with the help for MODBUS Protocol.
such companies are being adopted in a numerous PLC is a digital controller which is widely used
way[1, 2]. Cost reduction, increase in productivity in automation industry for electromechanical proc-
are the primary benefits cited with the help of esses. PLC is designed for multiple arrangements
automation. When it comes to cost reduction, we of digital and analog inputs and outputs which ex-
believe for a system which can be reusable or tend temperature ranges and immunity to electrical
adaptable in various devices. This proposed system noise. PLC is mostly used to control machinery,

※ Corresponding Author : Shim Jaechang, Address: †††††††Department of Computer Engineering, Andong


(36729) Gyeongdong-ro 1375, Andong, Gyeongsangbuk- National University (E-mail : dngustls@naver.com)
do, Korea, TEL : +82-10-9770-5645, FAX : +82-54-820- †††††††Department of Computer Engineering, Andong
6164, E-mail : jcshim@anu.ac.kr National University (E-mail : jinsseof@naver.com)
Receipt date : Sep. 9, 2016, Revision date : Jan. 3, 2017 †††††††Department of Computer Engineering, Andong
Approval date : Feb. 13, 2017 National University (E-mail : wnl668@naver.com)
†††School of Computer Science & Engineering, †††††††Department of Computer Engineering, Andong
Kyungpook National University National University
(E-mail : vrjung@hanmail.net)
†††Department of Computer Engineering, Andong National
※ This work (Grants No.C0398612) was supported by
Business for Cooperative R&D between Industry, Academy,
University (E-mail : israfila3@hotmail.com) and Research Institute funded Korea Small and Medium
†††Department of Computer Engineering, Andong National Business Administration in 2016.
University (E-mail : withfox6051@naver.com)
512 JOURNAL OF KOREA MULTIMEDIA SOCIETY, VOL. 20, NO. 3, MARCH 2017

PLC comes with build in communication port, usu- sensors. This leads Arduino to the development of
ally 9-pin RS-232, RS-422, RS-485 and Ethernet. a variety of hardware extensions and software li-
Here we will be discussing on RS-485 port. Today braries that enable wired and wireless communica-
modern PLCs can be programmed in a variety of tion with the Internet[7].
ways, from ladder logic to any programming
languages. Under the IEC 61131-3[3 ,4] standard 2. MODBUS PROTOCOL OVERVIEW
PLC can be programmed using standard based
programming languages, in which ladder logic is Modbus protocol is a serial communication pro-
most commonly used. Ladder logic sometimes tocol where digital communication networks can be
called “relay logic” was designed to work like relay implemented over long distance effectively and al-
logic, an old programming language which was al- so in electrically noisy environments. Moreover,
ready in wide use. It is run by reading and writing Modbus can run over virtually in all communica-
from the memory table of inputs, outputs and in- tion media, including twisted pair wires, wireless,
termediate values. fiber optics, Ethernet, telephone modems, cell
Arduino is an open-source platform which is phones and microwave. Here multiple receivers can
used for building electronics projects. The main be connected in a linear network where the only
point of “Arduino Platform” is to allow for easy one will be master device and rest will be a slave.
and fast Platform. It is famous for its simple pro- Slave can’t transmit data without a request from
gramming and rich resources and can also be the master node, and also can’t communicate with
mount each other like bricks to add some more another slave. The master node issues a MODBUS
modules. Arduino hardware platform has the pow- request to the slave nodes in two modes i.e. unicast
er and resets circuitry setup with circuitry to pro- mode and broadcast mode[8].
gram and communicate with the microcontroller At the time of communication on MODBUS
over USB. It consists of microcontrollers and IDE network. The protocol determines how the con-
which helps to upload computer code to the phys- troller knows about its device address, recognize
ical board. It uses a simplified version of C++, message address to it, determine the action to be
making it easier to learn and use[5, 6]. It is a flexi- taken and extract the data or information contain
ble micro-controller and development environment in the message. MODBUS protocol takes place at
that can not only be used to control devices but level 2 of the OSI model. At the physical level,
also can be used to read data from all kind of MODBUS uses different physical interface like
RS485, RS232 etc. RS485 on a Two-Wire interface
Table 1. Comparison of Modbus ASCII and Modbus RTU

MODBUS ASCII MODBUS RTU


Characters ASCII 0….9 and A...F Binary 0….255
Error check LRC(Longitudinal Redundancy Check) CRC(Cyclic Redundancy Check)
Frame start Character ‘:’ 3.5 chars silence
Frame end Characters CR/LF 3.5 chars silence
Gaps in message 1 sec 1.5 times char length
Start bit 1 1
Data bits 7 8
Parity Even/odd none Even/odd none
Stop bits 1 2 1 2
PLC and Arduino Interaction Based on Modbus Protocol 513

which is most commonly used. At Data link layer Table 4. MODBUS Function Codes
MODBUS Serial Line Protocol is defined[10]. CODE Description
MODBUS RTU network consists of one “master” 01 Read coil status
and up to 247 “slaves”[11]. 02 Read input status
In Table 1, we have presented the difference be- 03 Read holding registers
tween Modbus ASCII and Modbus RTU. 04 Read input registers
05 Force single coil
06 Present single registers
2.1 MODBUS Addressing
07 Read exception status
The MODBUS address space includes 256 dif- 15 Force multiple coils
ferent address. 16 Write holding/multiple registers
The Address 0 is for broadcast purpose and all 17 Report slave ID
slave must recognize the broadcast address. The
Master node has no specific address. outputs in a slave. In other words, it is used to Read
Coil Status or digital status from a Modbus Slave
Table 2. MODBUS Address data acquisition device. It read from 1 to 2000 con-
0 1 - 247 248 - 255 tiguous status of coils in a remote device. The
Broadcast Slave Address Reserved Request PDU specifies the starting address i.e. the
Address address of the first coil specified. The Query mes-
sage specifies the starting coil and quantity of coils
2.2 MODBUS Frame Structure to be read. Table 5 Represents a request to read
Modbus frame is composed of ADU(Application slave (20-27) from device 17. The coil in the re-
Data unit) which encloses a PDU(Protocol Data sponse message are generally packed as one coil
Unit). ADU composed of Address, PDU and Error per bit of data field, Table 6 shows the frame
check. PDU is composed Function code and Data. structure.
Table 5. Query Structure of Function 01
3. MODBUS OVERVIEW
Field Name RTU
3.1 MODBUS Function Codes Header None
Slave Address 11
MODBUS has 10 function codes as shown in Function 01
Table 4. In this proposed system we have used two Starting Address Hi 00
codes i.e. 04 and 16. Starting Address Lo 13
No. of Points Hi 00
A. Function 01: Read Coil Status No. of Points Lo 25
Function 01 reads ON/OFF status of discrete CRC --

Table 3. MODBUS Frame Structure

START ADDRESS FUNCTION DATA CRC CHECK END


T1-T2-T3-T4* 8 BITS 8 BITS N*8 BITS 16 BITS T1-T2-T3-T4*
*For T1-T2-T3-T4*, 3.5 character times at no communication.
The address field contains the slave address
The function code indicates server for kind of action to perform
CRC (cyclic redundancy checking) checks the content of the entire message.
514 JOURNAL OF KOREA MULTIMEDIA SOCIETY, VOL. 20, NO. 3, MARCH 2017

Table 6. Response Frame Structure of Function 01 ponse Frame structure is represented in Table 8.
Field Name RTU
Header None C. Function 04: Read Input Registers
Slave Address 11 The Modbus RTU function 04 is used to read
Function 01 Input registers from a Modbus Slave device.
Byte Count 05 Function 04 reads the contents of the 3X registers.
Data (Coils 27-20) CD Here the address starts from 0(zero), for example,
CRC --
1-10 are addressed as 0-9. Function 04 includes
the quantity of registers to read from the Modbus
B. Function 03: Read Holding Registers Slave device. With Function 04 master used to re-
The Modbus RTU Function 03 is used to Read quest one or more holding register value from the
Holding Registers (4x register references), in a device but only one slave device can be addressed
Modbus slave device. This function reads con- in a single query. The frame structure of query and
tinuous blocks of holding registers in the remote response are shown in Table 9 and Table 10
device. Registers are addressed starting at Zero. respectively.
Query message specifies the starting registers. In Table 9, Top 2 byte in Data field is the start
Here we present an example of a request to read address register, the lower two bytes is word units.
register 40108-40110 from slave device 17. Query In Table 10, the first byte in Data field is the num-
frame structure is shown in Table 7. In the Res- ber of data to read (byte unit) and then the top data,
ponse message, the register data are packed as two sub-data and lower data.
bytes per registers with binary contents. For each
register, the first byte contains the high order bits D. Function16: Write Holding Registers
and the second contains the low order bits. Res- With Function16 Master Device write values in-
Table 7. Query Structure of Function 03
to a sequence of holding registers to specified slave.
The query message specifies the register refer-
Field Name RTU ence. It writes values which are specified in the
Header None
Slave Address 11
Function 03 Table 9. Query Structure of Function 04

Starting Address HI 00 Field Name RTU


Starting Address LO 6B Header None
No, of Points HI 00 Slave Address 0A
No. of Points LO 03 Function 04
CRC -- Data 00 00 00 02
Register Request 0001
Table 8. Response Frame Structure of Function 03 CRC B298
Field Name RTU
Header None Table 10. Response Frame Structure of Function 04

Slave Address 11 Field Name RTU


Function 03 Header None
Byte Count 06 Slave Address 0A
Data HI (Register 40108) 02 Function 04
Data LO (Register 40108) 2B Data 04 02 2B 00 64
CRC -- CRC F2
PLC and Arduino Interaction Based on Modbus Protocol 515

Table 11. Query Structure of Function16 code, starting address and quantity of registers
Field Name RTU written.
Header None
Slave Address 11 3.2 Modbus Exception
Function 16 Modbus exception codes are error codes that are
Starting Address Hi 00 returned by slave devices when it detects any
Starting Address Lo 01 problem with a command it received. It can be gen-
Quantity of Register Hi 00
Quantity of Register Lo 02
erated for several reasons, bad data values, invalid
Byte Count 04 Modbus function codes, invalid register and much
Data Hi 00 more. These errors result in an exception response
Data Lo 02 from either the master computer software (Modbus
Data Hi 00 Communications Handler) or the PC Slave, de-
Data Lo 04 pending on the typeof error. The standardized
Error Check Lo C6 Exception codes are listed in Table 13
Error Check Hi B5 Here we also focused on counting the type of
error occur and in which situation. This helped us
Table 12. Response Frame Structure of Function 16 to understand our system much more deeply.
Field Name RTU
Header None 4. IMPLEMENTATION
Slave Address 11
Function 16 This proposed system was successfully im-
Starting Address Hi 00 plemented and tested with Arduino, RS485 and
Starting Address Lo 01 PLC by Modbus RTU protocol. Here we have dis-
Quantity of Register Hi 00 cussed the implementation briefly with the result
Quantity of Register Lo 02 table. The system must confirm that devices on
Error Check Lo 12 the same bus must have same communication
Error Check Hi 98 parameters.

request data field. Here data packets are two bytes 4.1 Wiring of the proposed system
per register. Table 11 shows the frame structure Fig. 1(a) gives an overall idea of the connection
of Query. Table 12 shows the frame structure of between Arduino and PLC with the mediator
Response, it returns the slave address, function RS-485. Here TX and RX port of Arduino is con-
Table13. Response Frame Structure of Function 16

Code Name Description


01 Illegal function The function value is not supported by the slave device
02 Illegal data Address The Register Address value is not a valid register in the slave device.
03 Illegal Data Value The Data value is not supported by the slave device register that is being written to.
04 Slave Device Failure An error occurred in the slave device while attempting to perform a requested
Modbus function query.
05 Acknowledge The Slave device may return an Acknowledge response after receiving a function
query that typically takes a long time to execute.
06 Slave Device Busy The Slave device is busy processing a function or task.
516 JOURNAL OF KOREA MULTIMEDIA SOCIETY, VOL. 20, NO. 3, MARCH 2017

(a)

(b)

(c)
Fig. 1. (a) System Wiring (b) Setup Location (c) PLC Setup Box.

nected to DI and RO of RS485 respectively. picts the location where we setup our system to
Whereas RE and DE port of RS485 are combined test. (c) is the PLC setup Box where *39 and 40
and connected to port13 of Arduino. Port 13 is used port is connected to RS485(A, B port shown in Fig.
as a button. 1(a))
Fig. 1(a) depicts the full system wiring. (b) de-
PLC and Arduino Interaction Based on Modbus Protocol 517

Table 14. From Master to Slave

Address Function Code Data Data Data Data CRC Low CRC HI
0×01 0×04 0×00 0×00 0×00 0×01 0×18 0×F0
0×01 0×04 0×00 0×01 0×00 0×01 0×19 0×60
0×01 0×04 0×00 0×02 0×00 0×01 0×19 0×90
0×01 0×04 0×00 0×03 0×00 0×01 0×19 0×00
0×01 0×04 0×00 0×04 0×00 0×01 0×1A 0×30

Table 15. Slave receives data

Address Function Code Data Data Data CRC Lo CRC HI


0×01 0×04 0×02 0×08 0×00 0×18 0×F0
0×01 0×04 0×02 0×04 0×00 0×19 0×60
0×01 0×04 0×02 0×02 0×00 0×19 0×90
0×01 0×04 0×02 0×01 0×00 0×19 0×00
0×01 0×04 0×02 0×00 0×80 0×1A 0×30

4.2 Results and Arduino with less cost and time. We believe
To test our system we send data from Arduino that this system will reduce the cost of develop-
to PLC using function code 04 where slave address ment for various companies due to reusability and
is 0x01. Here starting data address from 0×00 to easy to install. This proposed system can be able
0x04 represents the different data request from to setup a communication network with a device
PLC. having PLC installed in it or PLC supportable
In Table 14, first two data column states the devices. Moreover, Arduino gives a wide range of
starting address of PLC and next two data column option to connect other third party devices either
states the amount of data is being sent. In the through a wireless module or physically connected
fourth row of this table, Data from 0×00-0×04 are to it. Here we have mainly focused on error count-
the register start address from the data need to be ing and handling. Study on error handling helped
read. us to rectify the situation of error and on what type
In the same way PLC reply to Arduino with data of data error has occurred. Due cost effective and
which was requested. We should note that the CRC complexity reduction this system will be helpful in
should be same during each communication other- the field of automatic devices.
wise there will be an error in communication. Table In future, we are going to use this system as
15 depicts the reply to Arduino request. a mediator between two or more devices which can
In Table 15, first data column lists the amount communicate each other effectively. This system
of data receives and the next two data column are will provide easy connectivity module for various
received data. Third row Data represents the num- devices.
ber of data is received. Fourth and fifth row repre-
sents the data of defined address. REFERENCE

[ 1 ] Y. Jeong, M.I. Ansari, W. Shin, B. Kang, J.


5. CONCLUSION
Shim, “Smart Disel Generator Control Sys-
We proposed and studied RS485 and MODBUS tem,“ Journal of Korea Multimedia Society,
protocol for making communication between PLC Vol. 20, No. 2, pp. 271-278, 2017.
518 JOURNAL OF KOREA MULTIMEDIA SOCIETY, VOL. 20, NO. 3, MARCH 2017

[ 2 ] B.B. Shibarinath and N. Gaur, “MODBUS netics, IEEE International Conference , Vol.
Communication in Microcontroller Based 4, No. 6, pp. 2431-2436, 2000.
Elevator Controller,” International Confer- [ 9 ] PLCopen Technical Committee 6, “XML
ence on Control, Automation, Robotics and Formats for IEC 61131-3, Ver 1.0”, http://
Embedded Systems, pp. 16-18, 2013. www.plcopen.org/pages/tc6_xml/down-
[ 3 ] Comité Europeo de Normalización, EN loads/tc6_xml_v201_technical_doc.pdf
61131-3: Programmable Controllers. Prog- (accessed Nov., 21, 2016).
ramming languages (IEC 611131-3:2013) , [10] MODBUS over Serial Line Specification and
International Electrotechnical Comission, Implementation Guide V1.02, http://www.mod-
Brussels, France, 2013. bus. org/docs/Modbus_over_serial_line_V1_02.
[4] E. Tisserant, L. Bessard, and M. Sousa, “An pdf (accessed Nov., 21, 2016).
Open Source IEC 61131-3 Integrated Devel- [11] X. Jin, H. Yuan, Q. Jiang, and Y. Wang,
opment Environment,” Transactions on In- “Design of Silicon-based Transient Voltage
dustrial Informatics, Vol. 1, pp. 183-187. 2007. Suppressor to Meet IEC System-level ESD
[5] M. Banzi, Getting Started with Arduino, Specification for RS485 Transceiver,” Pro-
O’Relly Media, Sebastopol, Calif., 2011. ceeding of International Conference on Solid-
[6] M. Margolis, Arduino Cookbook, O’Relly State and Integrated Circuit Technology, pp.
Media, Sebastopol, Calif., 2011. 1-3, 2014.
[7] J. Ko, J. Shim, “A Comparison of the Con- [12] Z. Wu, S. Liu, M. Du, Q. Li, C. Han, and J.
struction for IoT System in Smart Clothing,” Wu, “Design of Vibrating Wire Sensor
Journal of Multimedia Information System, Singnal Acquisition Board Based on STM32,”
v.2, no.4, pp. 327-332, 2015. Proceeding of World Congress on Intelligent
[8] G. Frey and L. Litz, “Formal Methods in PLC Control and Automation, pp. 1846-1849, 2016.
Programming,” Systems, Man, and Cyber-
PLC and Arduino Interaction Based on Modbus Protocol 519

Yunju Jeong Bonggu Kang


received BS in Computational received B.S.degree in 2015 and
Statistics from Andong National M.Eng degree on Feb 2017 from
University in 1991 and Master Department of Computer Engi-
of Computer Engineering from neering, Andong National Uni-
Department of Computer Engin- versity, Korea. His research in-
eering, Andong National Uni- terests include Embedded vision
versity in 2000. Currently, she and Android applications.
studies for Ph.D. at Department of Computer Engin-
eering of Kyungpook National University and also an
Education Instructor at Department of Computer JinSeop Lim
Engineering, Department of Electronic Engineering, received B.S.degree in 2015 and
Andong National University, Korea. Her research in- M.Eng degree on Feb 2017 from
terests include computer vision, Deep Learning, and Department of Computer Engi-
VR. neering, Andong National Uni-
versity, Korea. His research in-
terests include programming,
Md Israfil Ansari database, windows program-
received the BCA degree in ming.
Computer Application from Punjab
Technical University, Jalandhar,
India in 2011 and the MCA de- HyeonSik Moon
gree in Computer Application currently is a B.S student at
from Visvesvaraya Technologi- Department of Computer Engi-
cal University, Bangalore, India neering, Andong National Uni-
in 2015. His previous position was a Software Devel- versity. His research interests
oper as an Intern at Xcelvations Consultancy Pvt Ltd, include IoT, Ubiquitous envi-
Hyderabad, India. Currently studies for Ph.D. at De- ronment construction and Elec-
partment of Computer Engineering, Andong National tronic circuit
University, Korea. He has interests in the areas of
computer vision, pattern recognition, Deep Learning.
Jaechang Shim
WooHyeon Shin received the B. S. degree in 1987
currently is a B.S student at and Ph.D. degree from Kyung-
Department of Computer Engi- pook National University, Korea,
neering, Andong National Uni- in 1997. From 1997 to 1999, he
versity. His research interests worked as a researcher in IBM
include computer vision, pro- T. J. Watson Research Center.
gramming language, and IoT. From 2005 to 2006, he was a
visiting Fellow Professor at Princeton University. Since
1994, he has been a Professor of the Andong National
University, Korea. He received the best Industrial-
Related Paper Award form International Association
for pattern Recognition in 1998. His research interests
include computer vision, image processing, and pattern
recognition.

You might also like