How to make PLC such as Modbus Master and Communicate with Arduino such as Modbus Slave ?
This article about RS454 communication between PLC Modbus Master and Arduino Modbus Slave using RS485 Module.
This application not use RS-232 PPI Multi-Master Cable of S7-200 PLC for communication between PLC and Arduino.
let us read this article and let's go watch the YouTube video below:
This article about RS454 communication between PLC Modbus Master and Arduino Modbus Slave using RS485 Module.
This application not use RS-232 PPI Multi-Master Cable of S7-200 PLC for communication between PLC and Arduino.
let us read this article and let's go watch the YouTube video below:
Video demonstration about RS485 Communication Between PLC Modbus Master and Arduino Modbus Slave
The hardware you need
- Arduino UNO
- Serial TTL to RS485 Transceiver MAX485 Module
- Siemens S7-200 PLC
- 1 Resistor 220 ohm
- 2 Resistors 330 ohm
- Power supply for Arduino UNO
- DB9 Male Connector
- Optional Hardware for testing:
- 2 Potentiometer 10 K ohm
- 1 LED Blue and 1 LED Red
- 2 Resistors 330 ohm
- 2 Push Button
RS485 Transceiver Module |
Hardware Connections
1. Connections between RS485 Module and PLC
2. Connections between RS485 Module and Arduino
3. Connections between Arduino, Potentiometers and LEDs
4. Connections between PLC and Push Button
The software you need
- Download the Arduino Software : https://www.arduino.cc/en/Main/Software and I use ARDUINO SOFTWARE HOURLY BUILDS version 1.6.6 for Windows
- Download Arduino Modbus Slave library : click here Unzip and Copy Paste to folder C:\arduino-nightly\libraries (Only ModbusSlaveLib folder)
Project file for RS485 Communication Between PLC and Arduino
- Download Arduino Project File : click here Upload to Arduino UNO
- Download PLC Project File : click here Download to Siemens S7-200 PLC
Modbus Data
In Arduino Modbus Slave with slave address 1:
- Analog data from potentiometer1 and potentiometer2 for set Modbus Registers 30001 and 30002
- Modbus Registers 40001 and 40002 for drive LED1 and LED2
In PLC Modbus Master:
Read Modbus Registers 30001 and 30002
- Read Data from Modbus Registers 30001 and 30002
- Save to VW0 for 30001 and VW2 for 30002
- VW0 for drive PLC Output Q1.0 to Q1.7
- VW2 for drive PLC Output Q0.0 to Q0.7
Write Modbus Registers 40001 and 40002
- Write Data to Modbus Registers 40001 and 40002
- Value from VW4 to 40001
- Value from VW6 to 400002
Arduino Code for RS485 Communication Between PLC and Arduino
#include <modbus.h> #include <modbusDevice.h> #include <modbusRegBank.h> #include <modbusSlave.h> modbusDevice regBank; modbusSlave slave; #define RS485TxEnablePin 2 #define RS485Baud 9600 #define RS485Format SERIAL_8E1 #define LED1 11 #define LED2 12 void setup() { //Assign the modbus device ID. regBank.setId(1); //Add Analog Input registers to the register bank regBank.add(30001); regBank.add(30002); //Add Analog Output registers to the register bank regBank.add(40001); regBank.add(40002); slave._device = ®Bank; slave.setBaud(&Serial,RS485Baud,RS485Format,RS485TxEnablePin); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); } void loop() { digitalWrite(LED1, regBank.get(40001)); digitalWrite(LED2, regBank.get(40002)); regBank.set(30001, (word) analogRead(A0)); //from 0 - 1023 regBank.set(30002, (word) analogRead(A1)); //from 0 - 1023 slave.run(); }