Wednesday, November 4, 2015

PLC Modbus Master - Arduino Modbus Slave - 2 Wire RS485 Communication Module




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:

Video demonstration about RS485 Communication Between PLC Modbus Master and Arduino Modbus Slave




The hardware you need

  1. Arduino UNO
  2. Serial TTL to RS485 Transceiver MAX485 Module
  3. Siemens S7-200 PLC
  4. 1 Resistor 220 ohm
  5. 2 Resistors 330 ohm
  6. Power supply for Arduino UNO
  7. DB9 Male Connector
  8. Optional Hardware for testing:
    • 2 Potentiometer 10 K ohm
    • 1 LED Blue and 1 LED Red
    • 2 Resistors 330 ohm
    • 2 Push Button

Hardware of RS485 Communication Between PLC and Arduino


Serial TTL to RS485 Transceiver MAX485 Module
RS485 Transceiver Module


Hardware Connections

1. Connections between RS485 Module and PLC

Connections between RS485 Module and PLC


2. Connections between RS485 Module and Arduino

Connections between RS485 Module and Arduino


3. Connections between Arduino, Potentiometers and LEDs

Connections between Arduino, Potentiometers and LEDs


4. Connections between PLC and Push Button

Connections between PLC and Push Button


The software you need

  1. Download the Arduino Software : https://www.arduino.cc/en/Main/Software
  2. and I use ARDUINO SOFTWARE HOURLY BUILDS version 1.6.6 for Windows

  3. Download Arduino Modbus Slave library : click here
  4. Unzip and Copy Paste to folder C:\arduino-nightly\libraries (Only ModbusSlaveLib folder)


Project file for RS485 Communication Between PLC and Arduino

  1. Download Arduino Project File : click here
  2. Upload to Arduino UNO

  3. Download PLC Project File : click here
  4. Download to Siemens S7-200 PLC


Modbus Data

In Arduino Modbus Slave with slave address 1:

  1. Analog data from potentiometer1 and potentiometer2 for set Modbus Registers 30001 and 30002
  2. Modbus Registers 40001 and 40002 for drive LED1 and LED2
Arduino Modbus Slave


In PLC Modbus Master:

Read Modbus Registers 30001 and 30002

  1. Read Data from Modbus Registers 30001 and 30002
  2. Save to VW0 for 30001 and VW2 for 30002
  3. VW0 for drive PLC Output Q1.0 to Q1.7
  4. VW2 for drive PLC Output Q0.0 to Q0.7
Read Modbus Registers 30001 and 30002


Write Modbus Registers 40001 and 40002

  1. Write Data to Modbus Registers 40001 and 40002
  2. Value from VW4 to 40001
  3. Value from VW6 to 400002
Write Modbus Registers 40001 and 40002



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 = &regBank;  

  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();  
}


Labels:





Newer Post Older Post Home

You may also like these ebook:

Get Free PLC eBook directly sent to your email,
and email subscription to program-plc.blogspot.com




We hate SPAM. Your information is never sold or shared with anyone.

Your Email Will Be 100% Secured !