Wednesday, November 11, 2015

PLC - Arduino - Multiple DS18B20 Digital Temperature Sensor - One Wire and Modbus Communication




This application about how to read data from Multiple DS18B20 Digital Temperature Sensor to PLC (Programmable Logic Controller), and to bridge between Multiple DS18B20 and PLC,  I use Arduino.

Communication between Arduino and Multiple DS18B20 use One Wire Communication, and Communication between Arduino and PLC use Modbus Communication.

Operating temperature range of DS18B20 between -55°C to +125°C -67°F to +257°F) and suitable for applications : HVAC (Heating, Ventilation, and Air Conditioning) environmental controls, sensing temperatures equipment or machinery , process monitoring and control, sensing temperatures inside buildings , and etc.

How to Read Data from Multiple DS18B20 to PLC ?
Let's read this article and let's go watch the video demonstration:

Multiple DS18B20 Digital Temperature Sensor to PLC using Arduino, One Wire and Modbus Communication




Hardware

  1. Arduino UNO
  2. 2 Pieces DS18B20 Digital Temperature Sensor, I use Waterproof with 3 cable:
    • 1 piece with cable : Red (VCC), Yellow(DATA), Black(GND)
    • 1 piece with cable : Red (VCC), Yellow(DATA), Grey(GND)

  3. 1 Piece Resistor 4.7K ohm / 4700 ohm
  4. RS485 Transceiver Module
  5. Siemens S7-200 PLC
  6. 1 Piece Resistor 220 ohm
  7. 2 Pieces Resistors 330 ohm
  8. Power supply for Arduino UNO
  9. DB9 Male Connector

DS18B20, Arduino, RS485 and PLC


DS18B20 Digital Temperature Sensor
DS18B20 Digital Temperature Sensor

Hardware Connections

1. Connections between Arduino, RS485 Module and PLC

Hardware connection can be read in the article : http://program-plc.blogspot.com/2015/11/plc-modbus-master-arduino-modbus-slave.html

2. Connections between Arduino and Multiple DS18B20 Digital Temperature Sensor

Connections between Arduino and Multiple DS18B20 Digital Temperature Sensor


Software

  1. Arduino Software : https://www.arduino.cc/en/Main/Software
  2. and I use HOURLY BUILDS version 1.6.6

  3. Arduino library : click here
  4. Unzip and Copy Paste to folder C:\arduino-nightly\libraries
    Only Folder : DallasTemperature, OneWire and ModbusMasterRS485


Project File

  1. for Upload to Arduino : click here
  2. for Download to Siemens S7-200 PLC : click here


Modbus Communication between Arduino Modbus Master and PLC Modbus Slave

  1. Arduino UNO such as Modbus Master
  2. PLC such as Modbus Slave with Slave Address 1
  3. DS18B20 to Arduino use One Wire Communication


Response/Actual Time from DS18B20 Digital Temperature Sensor to PLC

1. DS18B20 Max Conversion Time per Sensor

Thermometer Resolution
Max Conversion Time
9 bit
94 ms
10 bit
188 ms
11 bit
375 ms
12 bit
750 ms

2. Actual Time for two Sensors

I use two sensor and with Thermometer Resolution = 9 and Actual Time from Read two DS28B20 to Write PLC Memory between 2 - 2.5 Seconds
for communication use RS485 Modbus communication


Arduino Code for Application of DS18B20 , RS485 and PLC


#include <OneWire.h>
#include <DallasTemperature.h>
#include <SimpleModbusMaster.h>

#define slaveAddr 1
#define baud 9600
#define timeout 1000
#define polling 1
#define retry_count 0
#define TxEnablePin 2 
enum
{
  PACKET1,
  TOTAL_NO_OF_PACKETS
};

Packet packets[TOTAL_NO_OF_PACKETS];
packetPointer packet1 = &packets[PACKET1];
unsigned int writeRegs[3];

//Red cable to +5V and Black/Grey cable to GND
//Yellow/Blue Cable is plugged into D3/Pin 3 on Arduino Proto Screw
#define One_Wire_Pin 3

//Thermometer resolution is programmable from 9 to 12 bits
#define Thermometer1_Resolution 9
#define Thermometer2_Resolution 9

//Setup a one wire communication
OneWire One_Wire(One_Wire_Pin);

//Pass our oneWire reference to Dallas Temperature. 
DallasTemperature Temperature_Sensor(&One_Wire);

//Setup Temperature Sensor Address
DeviceAddress Temperature_Sensor1_Address = {0x28, 0xFF, 0x12, 0x77, 0x52, 0x15, 0x01, 0xE0};
DeviceAddress Temperature_Sensor2_Address = {0x28, 0xFF, 0xCB, 0x29, 0x15, 0x15, 0x01, 0xCB};


void setup(void)
{
//Modbus Slave Setup  
 modbus_construct(packet1, slaveAddr, PRESET_MULTIPLE_REGISTERS, 0, 3, writeRegs);
 modbus_configure(&Serial, baud, SERIAL_8E1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);  


//Temperature Sensor Setup
  Temperature_Sensor.begin();
 Temperature_Sensor.setResolution(Temperature_Sensor1_Address, Thermometer1_Resolution);
 Temperature_Sensor.setResolution(Temperature_Sensor2_Address, Thermometer2_Resolution);
  
  if(!Temperature_Sensor.getResolution(Temperature_Sensor1_Address) ||
     !Temperature_Sensor.getResolution(Temperature_Sensor2_Address))
  {
    //Get Temperature Sensor Address
    int numberOfDevices = Temperature_Sensor.getDeviceCount();
    Serial.print("Locating devices...");  
    Serial.print("Found ");
    Serial.print(numberOfDevices, DEC);
    Serial.println(" devices.");       
    if(numberOfDevices>0)Serial.println("Please Setup Address with : ");
    DeviceAddress tempDeviceAddress;
    for(int i=0;i<numberOfDevices; i++)
    {
      if(Temperature_Sensor.getAddress(tempDeviceAddress, i))
    {      
      Serial.print("DeviceAddress Temperature_Sensor");
      Serial.print(i+1, DEC);
      Serial.print("_Address = ");
      printAddress(tempDeviceAddress);
      Serial.println();
      
    }else{
      Serial.print("Found ghost device at ");
      Serial.print(i, DEC);
      Serial.println(" but could not detect address. Check power and cabling");
    }
    }
    while(1){};
  }

}


void loop(void)
{ 
 Temperature_Sensor.requestTemperatures(); 
 //Resolution=9 delay time 94ms per sensor
 //Resolution=10 delay time 188ms per sensor
 //Resolution=11 delay time 375ms per sensor
 //Resolution=12 delay time 750ms per sensor
 //Error -127.00
 float Temperature1_Celsius = 100 * Temperature_Sensor.getTempC(Temperature_Sensor1_Address);
 float Temperature2_Celsius = 100 * Temperature_Sensor.getTempC(Temperature_Sensor2_Address);  
 writeRegs[0]=(word)random(1000);
 writeRegs[1]=(word)Temperature1_Celsius;  
 writeRegs[2]=(word)Temperature2_Celsius; 
 modbus_update();
}


void printAddress(DeviceAddress deviceAddress)
{
  Serial.print("{");
  for (uint8_t i = 0; i < 8; i++)
  {
    Serial.print("0x");
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
    if(i<7)Serial.print(", ");
  }
  Serial.print("};");
}


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 !

Your email is stored safely on Google FeedBurner